Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Gradle - Differences between Implementation, releaseImplementation and debugImplementation

Tags:

I've an Android app in Android Studio. I'm using Gradle Version = 4.6, Android Plugin Version=3.2.1.. It has a app module (main) and a library module.

I renamed one of the class function in library module. After cleaning and building the library module followed by the app module, I'm getting this error in the app module: error: cannot find symbol to the renamed class function

Below is my build.gradle(app):

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

If I changed the build.gradle to the one below, then everything is ok.

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

I would like to know the differences between implementation, releaseImplementation and debugImplementation, and how can I use it in my situation.

like image 553
chrizonline Avatar asked Feb 03 '19 06:02

chrizonline


1 Answers

implementation will apply dependencies to all build variants. If you instead want to declare a dependency for only a specific build variant source set or for a testing source set, you must capitalize the configuration name and prefix it with the name of the build variant or testing source set.

For example : If you have to consume separate dependencies for debug, release and free build variants (my-library-debug, my-library and my-library-free respectively) then you have to use debugImplementation, releaseImplementation and freeImplementation as below

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' 

Note : In the above case, if you only use

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

then all your builds like debug and free types will only pull my-library which you may not want.

Read more here (you can combine product flavor and a build type too, to target more specific build variant): https://developer.android.com/studio/build/dependencies#dependency_configurations

like image 72
Vinayak Bevinakatti Avatar answered Sep 20 '22 11:09

Vinayak Bevinakatti