无法解析依赖项 Android Studio 3.0

Unable to resolve dependency Android Studio 3.0

有一个更新的 Android Studio 3.0 真好。但是我遇到了 Android Studio 3.0 的问题,我刚刚在 Android Studio 3.0 中创建了一个新项目。然后我得到了一些错误

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

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

我收到以下错误-:

Error:Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.facebook.android:account-kit-sdk:4.+. Open File
Show Details

build.gradle(应用程序)

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'
}

注意-:

截图

我前天遇到了类似的错误。刚刚解决了

此外,正如最新的 gradle 版本 notes 中提到的,您应该避免使用版本号为:

的动态依赖项
com.facebook.android:account-kit-sdk:4.+

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

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

步骤 1-:

我在设置中禁用Gradle离线工作

File > Settings > Build, Execution, Deployment > Gradle > Uncheck Offline Work

步骤 2-:

然后,我就把compile 'com.facebook.android:account-kit-sdk:4.+'改成了api 'com.facebook.android:account-kit-sdk:4.+'

我不知道它为什么起作用。我在文档 Reference

中看到 api

现在可以了:)

编辑-

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

谢谢,

短篇小说:

降级到 Gradle 4.2.1

长话短说:

我使用的是 Gradle 版本 4.3 基于答案 因为那个问题是我的错误。做了那个改变之后我开始遇到你的问题。

降级到版本 4.2.1,您的问题就消失了。现在我得回到之前的问题了。

我在用 Android Studio 3.0gradle plugin 3.0.0

编译我的项目时也有这个

如果我还有其他问题,我会post在这里更新

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

例如我遇到 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
    }
}

有同样的问题。尝试了一切之后,终于意识到是网络不允许同步依赖项。尝试使用热点,效果很好。

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

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

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

解决了这个问题

关于我的问题,它与你的有点不同。我有第二个模块 android 库和来自 android 开发者页面 "Convert an app module to a library module" 部分。我的猜测是它与管理架构内部的 Manifest 文件有关,因此 Android 将知道主 Manifest 文件在哪里。

关于apiimplementation,可以找到答案here

The api configuration should be used to declare dependencies which are exported by the library API, whereas the implementation configuration should be used to declare dependencies which are internal to the component.

所有 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 模式。

我遇到了同样的问题,我确实是这样解决的:

implementation project(path: 'com.facebook.android:account-kit-sdk:4.+', configuration: 'default')

降级这两个文件解决问题

项目的 build.graddle 到 3.1.4 gradle-wrapper 属性到 4.4

看到一个旧项目。它显示“构建”成功。所以我检查了 build.gradle 文件。比较这两个项目,我发现依赖项版本号发生了变化。然后我只是从旧项目中复制了版本号并且它起作用了。 android{} 中还有一个 BuildUsing 左右,我将其从我的新项目中删除(它不在我的旧项目中)。我认为这是因为 gradle 更新不完整或损坏。