Android Studio 3.0 错误。迁移本地模块的依赖配置

新手上路,请多包涵

我最近安装了最新的 Android Studio Canary 版本,它目前正在使用 Android Gradle 插件 3.0.0-alpha4 。

我现在得到一个错误:

 Error:Failed to resolve: Could not resolve project :MyLib.
Required by:
project :app

我已阅读: Migrate dependency configurations for local modules

>  dependencies
>
> {
>
> // This is the old method and no longer works for local
> // library modules:
> // debugCompile project(path: ':foo', configuration: 'debug')
> // releaseCompile project(path: ':foo', configuration: 'release')
>
> // Instead, simply use the following to take advantage of
> // variant-aware dependency resolution. You can learn more about
> // the 'implementation' configuration in the section about
> // new dependency configurations.
> implementation project(':foo')
>
> // You can, however, keep using variant-specific configurations when
> // targeting external dependencies. The following line adds 'app-magic'
> // as a dependency to only the 'debug' version of your module.
>
> debugImplementation 'com.example.android:app-magic:12.3'
> }
>
> ```

我变了:

releaseCompile project(path: ‘:MyLib’, configuration: ‘appReleaseApp’) debugCompile project(path: ‘:MyLib’, configuration: ‘appDebug’)


到:

implementation project(‘:MyLib’)


但我仍然有这个错误: `Error:Failed to resolve: Could not resolve project :MyLib.`

库等级:

apply plugin: ‘com.android.library’

android { publishNonDefault true compileSdkVersion 25 buildToolsVersion “25.0.3” defaultConfig { minSdkVersion 14 targetSdkVersion 25 } buildTypes { debug { … } releaseApp { … } releaseSdk { …’ } } flavorDimensions “default”

productFlavors {
    flavor1{
        ...
    flavor2{
        ...
    }
    flavor3{
        ...
    }
}

}

dependencies { compile fileTree(include: [‘*.jar’], dir: ‘libs’) compile ‘com.android.support:appcompat-v7:25.3.1’ compile ‘com.android.support:support-v4:25.3.1’ compile ‘com.google.code.gson:gson:2.8.0’ compile ‘com.google.android.gms:play-services-maps:10.2.6’ compile ‘com.google.android.gms:play-services-gcm:10.2.6’ compile ‘com.google.android.gms:play-services-location:10.2.6’ }

apply plugin: ‘maven’

uploadArchives { repositories { mavenDeployer { repository(url: mavenLocal().url) } } }


应用程序等级:

apply plugin: ‘com.android.application’

android {

compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
    vectorDrawables.useSupportLibrary = true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    minSdkVersion 19
    targetSdkVersion 25
    versionCode 12
    versionName "5.0.2"
}

buildTypes {
    release {
        ...
    }
    debug {
        ...
    }
}
flavorDimensions "default"

productFlavors {
    flavor1 {
        ...
    }

    flavor2 {
        ...
    }
}

testOptions {
    unitTests {
        all {
            jvmArgs '-noverify'
            systemProperty 'robolectric.logging.enable', true
        }
    }
}

}

repositories { flatDir { dirs ‘libs’ } } dependencies { // releaseCompile project(path: ‘:MyLib’, configuration: ‘appRelease’) // debugCompile project(path: ‘:MyLib’, configuration: ‘appDebug’) implementation project(‘:MyLib’)

compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.google.android.gms:play-services-maps:10.2.6'
compile 'com.google.android.gms:play-services-location:10.2.6'
compile 'com.google.android.gms:play-services-analytics:10.2.6'
compile 'com.google.android.gms:play-services-gcm:10.2.6'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:gridlayout-v7:25.3.1'
compile 'com.android.volley:volley:1.0.0'
compile 'com.facebook.stetho:stetho:1.4.1'
compile 'com.facebook.stetho:stetho-okhttp3:1.4.1'
compile 'com.android.support:percent:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.squareup.picasso:picasso:2.5.2'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.1.0'
testCompile 'org.robolectric:robolectric:3.1.4'
testCompile 'org.assertj:assertj-core:1.7.1'

compile 'com.flipboard:bottomsheet-core:1.5.0'
compile 'com.flipboard:bottomsheet-commons:1.5.0'
compile 'com.android.support.constraint:constraint-layout:1.0.1'

}

apply plugin: ‘com.google.gms.google-services’

”`

请帮忙

原文由 phnmnn 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 343
2 个回答

Google 添加了更多说明如何解决它: Resolve build errors related to dependency matching

构建错误的原因:

您的应用包含库依赖项不包含的构建类型。

例如,您的应用包含“暂存”构建类型,但依赖项仅包含“调试”和“发布”构建类型。

请注意,当库依赖项包含您的应用程序不包含的构建类型时,没有问题。那是因为插件根本不会从依赖项中请求构建类型。

解析度

使用 matchingFallbacks 为给定的构建类型指定替代匹配项,如下所示:

 // In the app's build.gradle file.
android {
    buildTypes {
        debug {}
        release {}
        staging {
            // Specifies a sorted list of fallback build types that the
            // plugin should try to use when a dependency does not include a
            // "staging" build type. You may specify as many fallbacks as you
            // like, and the plugin selects the first build type that's
            // available in the dependency.
            matchingFallbacks = ['debug', 'qa', 'release']
        }
    }
}

原文由 phnmnn 发布,翻译遵循 CC BY-SA 4.0 许可协议

遇到同样的问题后,我终于在 App 和 Modules 的 build.gradle 文件中声明了完全相同的 buildTypes。

在你的情况下,添加

buildTypes {
    debug {}
    releaseApp {}
    releaseSdk {}
}

您模块的 build.gradle 应该可以解决问题。

确保也将任何“编译项目”更改为“实施项目”。

希望能帮助到你

原文由 Zoubiock 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题