强制配置gradle android应用程序中的依赖项

时间:2018-03-09 06:19:20

标签: android gradle android-gradle-3.0 gradle-3.0

我需要在我的Android应用程序中强制配置gradle,我的gradle verision是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

1 个答案:

答案 0 :(得分: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'
}

来源:Migrate dependency configurations for local modules