26

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.

Zoe
  • 27,060
  • 21
  • 118
  • 148
chrizonline
  • 4,779
  • 17
  • 62
  • 102

1 Answers1

36

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

Vinayak Bevinakatti
  • 40,205
  • 25
  • 108
  • 139
  • What if I am adding a module or library project instead of a jar. I am trying to use like below but not working. implementation project(':Library') was working. Now I replaced it with freeDebugImplementation project(path:':Library') and paidDebugImplementation project(path:':Library') Is there any other rule for the library module? – Parmeshwar C Nov 07 '19 at 05:26
  • 1
    The Android documentation mentioned that -https://developer.android.com/studio/build/dependencies#variant_aware `Android plugin 3.0.0 and higher include a new dependency mechanism that automatically matches variants when consuming a library. This means an app's debug variant automatically consumes a library's debug variant, and so on. It also works when using flavors—an app's freeDebug variant will consume a library's freeDebug variant.` And also `In order for the plugin to accurately match variants, you need to provide matching fallbacks for instances where a direct match is not possible` – Vinayak Bevinakatti Nov 07 '19 at 21:09
  • @ParmeshwarC I haven't came across this situation, so quoting it from developer documentation. Please let us know if that works. Also this SO post may help in your case, if you haven't seen it yet - https://stackoverflow.com/q/24860659/28557 – Vinayak Bevinakatti Nov 07 '19 at 21:14