0

我需要在我的 android 应用程序的 gradle 中强制配置,我的 gradle 版本是 3.0.1。下面是这样做的旧方法,我需要相当于 Gradle 3.0。

releaseCompile project(path: ':androidLibrary', configuration: 'debug')

我的错误版本:

releaseImplementation project(path: ':androidLibrary', configuration: 'debug')

以上给了我一个错误信息

错误:无法解析':main@release/compileClasspath'的依赖关系:无法解析项目:androidLibrary。”

错误:无法解析“:main@releaseUnitTest/compileClasspath”的依赖关系:无法解析项目:androidLibrary。

4

1 回答 1

0

您是否尝试过以下方法?

implementation project(':androidLibrary')

根据 Google 的Migrate to Android Plugin for Gradle 3.0.0,“针对本地模块依赖项的特定变体(例如,使用配置:'debug')会导致以下构建错误:”

Error:Unable to resolve dependency for ':app@debug/compileClasspath':
  Could not resolve project :library.
Error:Unable to resolve dependency for ':app@release/compileClasspath':
  Could not resolve project :library.

我认为当您使用release前缀releaseImplementation和包含configuration: 'debug'在此语句中时,您的目标是本地模块依赖项的特定变体:

releaseImplementation project(path: ':androidLibrary', configuration: 'debug')

它继续推荐以下解决方案:

“您应该按如下方式配置您的依赖项”:

dependencies {
    // This is the old method and no longer works for local
    // library modules:
    // debugImplementation project(path: ':library', configuration: 'debug')
    // releaseImplementation project(path: ':library', 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(':library')

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

来源:迁移本地模块的依赖配置

于 2018-03-16T21:41:55.697 回答