无法解析依赖Android Studio 3.0

问题描述 投票:36回答:9

拥有更新的Android Studio 3.0非常棒。但是我遇到了Android Studio 3.0的问题,我刚刚在Android Studio 3.0中创建了一个新项目。然后我收到了一些错误

我通过将dependencies更改为最新版本并解决了问题来解决这些问题。

但是,当我添加了facebook account-kit sdk dependencycom.facebook.android:account-kit-sdk:4.+

我得到以下错误 - :

错误:无法解析':app @ debug / compileClasspath'的依赖项:无法解析com.facebook.android:account-kit-sdk:4.+。打开文件 显示详细资料

的build.gradle(APP)

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "ultimate.devil.logintest"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.facebook.android:account-kit-sdk:4.+'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

注意 -:

  • 我关注Facebook Developers Docs
  • 我尝试过将compile改为implementation
  • 我也尝试通过谷歌搜索最新版本的Facebook Account-Kit SDK将com.facebook.android:account-kit-sdk:4.+改为com.facebook.android:account-kit-sdk:4.11.0com.facebook.android:account-kit-sdk:4.27
  • 我也尝试使用StackOverFlow Answers同样的问题。但没有人帮助我

截图

enter image description here

android facebook-android-sdk android-studio-3.0
9个回答
71
投票

经过一番研究,我已经解决了这个问题。

步骤1-:

我在设置中禁用了Gradle脱机工作。

文件>设置>构建,执行,部署> Gradle>取消选中脱机工作

enter image description here

第2步-:

然后,我刚刚将compile 'com.facebook.android:account-kit-sdk:4.+'改为api 'com.facebook.android:account-kit-sdk:4.+'

我不知道它为什么会起作用。我在文档Reference中看到了api

现在它工作:)

编辑 -

现在,我可以使用apiimplementation,一切正常。

谢谢,


5
投票

在未能编译的matchingFallbacks = ['release', 'debug']中添加buildType

例如。我在releaseStaging时遇到错误:

buildTypes {
    debug {
        buildConfigField "String", "CODEPUSH_KEY", '""'
    }
    releaseStaging {
        buildConfigField "String", "CODEPUSH_KEY", 'myKey'
        signingConfig signingConfigs.release
        matchingFallbacks = ['release', 'debug']
    }
    release {
        buildConfigField "String", "CODEPUSH_KEY", 'myKey'
        minifyEnabled enableProguardInReleaseBuilds
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        signingConfig signingConfigs.release
    }
}

3
投票

我前天面临类似的错误。刚解决它here

此外,正如最新的gradle版本notes中所提到的,您应该避免使用版本号的动态依赖关系:

com.facebook.android:account-kit-sdk:4.+

尝试将其替换为适当的版本号4.0.0或更新版本。希望它能解决问题。


2
投票

短篇故事:

降级为Gradle 4.2.1

很长的故事:

我根据答案here使用Gradle版本4.3,因为这个问题是我的错误。做完这个改变后,我开始遇到你的问题。

降级到版本4.2.1,您的问题就消失了。现在我必须回到上一个问题。

我用problemAndroid Studio 3.0编译我的项目时也有这个gradle plugin 3.0.0

如果我有其他问题,我会在这里发布更新


2
投票

所有Facebook Account Kit SDK构建工件都可以在Maven Central上找到:

// https://mvnrepository.com/artifact/com.facebook.android/account-kit-sdk
api 'com.facebook.android:account-kit-sdk:4.35.0'

并且要添加的相应存储库是:

repositories {
    mavenCentral()
}

正在假设Gradle没有处于offline模式。


0
投票

有同样的问题。在尝试了一切之后,终于意识到它是不允许同步依赖的网络。尝试使用热点,它工作。


0
投票

我通过清除此目录解决了这个问题:

c:\Users\User name\\.gradle\caches\

0
投票

我有同样的问题,我通过将apply plugin: 'com.android.application'更改为apply plugin: 'com.android.library'解决了这个问题

关于我的问题,它与你的有点不同。我有第二个模块与android库和Android开发人员页面“将应用程序模块转换为库模块”部分。我的猜测是它与管理架构内部的Manifest文件有关,因此Android会知道Manifest的主要文件在哪里。

关于apiimplementation,答案可以找到here

api配置应该用于声明由库API导出的依赖项,而实现配置应该用于声明组件内部的依赖项。


0
投票

我有同样的问题,我确实解决了这个问题:

implementation project(path: 'com.facebook.android:account-kit-sdk:4.+', configuration: 'default')
© www.soinside.com 2019 - 2024. All rights reserved.