首页 > 解决方案 > Android Gradle - Implementation、releaseImplementation 和 debugImplementation 的区别

问题描述

我在 Android Studio 中有一个 Android 应用程序。我正在使用Gradle Version = 4.6, Android Plugin Version=3.2.1.. 它有一个应用程序模块(主)和一个库模块。

library我重命名了模块中的一个类函数。在清理并构建library模块后跟app模块后,我在 app 模块中收到此错误:error: cannot find symbol to the renamed class function

下面是我的 build.gradle(app):

android {
...
}
dependencies {
...
  releaseImplementation 'com.example.library:1.0.0'
  debugImplementation project(':library')
}

如果我将 build.gradle 更改为下面的,那么一切正常。

android {
}
dependencies {
...
  implementation project(':library')
}

我想知道 和 之间的区别implementationreleaseImplementation以及debugImplementation如何在我的情况下使用它。

标签: androidandroid-gradle-plugin

解决方案


implementation将依赖项应用于所有构建变体。如果您只想为特定的构建变体源集或测试源集声明依赖关系,则必须将配置名称大写并在其前面加上构建变体或测试源集的名称。

例如:如果您必须使用单独的依赖项进行调试、发布和免费构建变体(my-library-debugmy-library分别my-library-free),那么您必须使用debugImplementation, releaseImplementationfreeImplementation如下

debugImplementation 'com.test.package:my-library-debug:1.0' 

releaseImplementation 'com.test.package:my-library:1.0' 

freeImplementation 'com.test.package:my-library-free:1.0' 

注意:在上述情况下,如果您只使用

implementation 'com.test.package:my-library:1.0'

那么你所有的构建,比如调试和自由类型,只会拉my-library你可能不想要的。

在此处阅读更多内容(您也可以结合产品风格和构建类型,以针对更具体的构建变体):https ://developer.android.com/studio/build/dependencies#dependency_configurations


推荐阅读