My Android project has submodule which are in git & artifactory. The submodule's gradle dependencies has these included.
kapt 'com.google.dagger:dagger-compiler:2.15'
implementation 'com.google.maps.android:android-maps-utils:0.5'
implementation 'com.airbnb.android:lottie:2.5.3'
The local release build flavor (when the submodule is pulled from git) builds fine. But the remote release build (where the submodule is pulled from artifactory) fails.
remote release flavor is:
release {
debuggable false
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
multiDexKeepProguard file('multidex.pro')
}
The error is that some library files cant be referenced.
can't find superclass or interface dagger.internal.Factory Warning: _ProvideFakeTrackerFactory: can't find superclass or interface dagger.internal.Factory Warning: _ProvidePropMapPresenterFactory: can't find superclass or interface dagger.internal.Factory Warning: : can't find referenced class dagger.Provides Warning: : can't find referenced class dagger.Module Warning: .FirebaseTracker: can't find referenced class com.google.firebase.analytics.FirebaseAnalytics Warning: .FirebaseTracker$subscribeToScreenEvents$1: can't find referenced class com.google.firebase.analytics.FirebaseAnalytics Warning: .: can't find referenced class com.airbnb.lottie.LottieAnimationView Warning: .DetailFragment_MembersInjector: can't find referenced class dagger.MembersInjector Warning: .map.DaggerPropMapComponent$Builder: can't find referenced class dagger.internal.Preconditions Warning: .MapFragment: can't find referenced class com.google.android.gms.location.LocationServices Warning: .MapFragment: can't find referenced class com.google.android.gms.location.FusedLocationProviderApi
Since these library files are already in the submodule's gradle dependencies, How can I build successfully without redeclaring these libraries in the app's gradle?
Thanks.
You are talking about Transitive Dependencies. This is a common error in compilng for many engineers.
Keep in mind any repository pointers declared in children sub modules must ALSO be declared in the parent application. The repository URLs are not included in parent modules. So if you have a custom maven repository that you are accessing from a child module, you will need to duplicate that URL in the parent application.
Also, if a child module has dependencies, these are known as transitive dependencies, or "the dependencies of my dependents". These do not get included in compiled final APK or AAR file. They are excluded by default. This is the normal default behavior.
You can of course create a FAT-JAR or FAT-AAR file to include the transitive dependencies, but this is bad practice typically and I wouldn't recommend it.
If you are generating proper Maven files you can simply add in the line for:
myDependencyNamespaceinGradle{ transitive = true }
this flag tells it to include the dependencies of this dependent. IMPORTANT* This only works if you have proper maven structured files in the child and the host maven repo to know which children dependencies to include.
Now if you need it to compile when you are working locally, but you know it will be provided by the parent, you can specify it as
provided mydependency instead of compile mydependency.
This tells it to compile when debugging, but don't package it with it, as the dependency will be in the final output as part of the parent provided dependencies.
Another important factor is to ensure your proguard file is setup correctly to not remove annotations and reflection based code. Dagger will need to have insurance in place in these files to not be removed at minification time. Please confirm this by disabling minification and proguard on release. If it works fine, then your issue is proguard file related, if it still has an issue, then it is likely your transitive dependency management.
Hope that helps, please let me know if you need additional clarity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With