I'm trying to implement instant apps into a project that uses Firebase database. I'm targeting SDK version 27, so the support libraries are on version 27.0.2.
Firebase database version is 11.8.0 and gms version is 3.1.0. When I try to sync, I get the following error:
Android dependency 'com.android.support:support-v4' has different
version for the compile (25.2.0) and runtime (27.0.2) classpath. You
should manually set the same version via DependencyResolution
I was able to get around the issue by adding the following dependencies explicitly before the instant apps
implementation 'com.android.support:support-v4:27.0.2'
implementation 'com.android.support:support-media-compat:27.0.2'
But with the instant apps, even if I have them in the feature module (app-base), when I try to build the actual app (com.android.application), I again get the same error.
I can again move around the issue by moving those conflicting dependencies into application module gradle file, in which case the sync succeeds, but then I'm facing another problem, this time with manifest merging, which prevents the app from finding the launcher activity:
Attribute provider#com.google.firebase.provider.FirebaseInitProvider@authorities value=(com.iamkaan.packagename.firebaseinitprovider) from AndroidManifest.xml:10:13-72 is also present at AndroidManifest.xml:33:350-423 value=(com.iamkaan.packagename.base.firebaseinitprovider). Suggestion: add 'tools:replace="android:authorities"' to element at AndroidManifest.xml:8:9-12:39 to override. app main manifest (this file), line 9
This last issue is somehow related to firebase-core
dependency because when I changed my app gradle dependencies from
implementation project(':app-base')
to
implementation (project(':app-base')) {
exclude group: 'com.google.firebase', module:'firebase-core'
}
I was able to run the app. But this time, I started getting the following error on runtime (the first time I call FirebaseDatabase.getInstance()
)
Default FirebaseApp is not initialized in this process com.iamkaan.packagename. Make sure to call FirebaseApp.initializeApp(Context) first
It was indeed not called but was working without anyway until instant app implementation. Anyway, I added the call to various places before the first FirebaseDatabase call, nothing helped.
Package names
com.iamkaan.packagename
com.iamkaan.packagename
com.iamkaan.packagename.base
I ran into something similar and it is caused by support libraries being included by dependencies. It's important to note that almost all of Google/Android support libraries (CardView, RecyclerView etc) includes the latest v4 and v7 support libraries. So that usually causes conflicts.
What you need to do is:
implementation project(':app-base')
onlyapi
instead of implementation
for support libs included inside Base Module's build.gradle
i.e. api 'com.android.support:support-v4:27.0.2'
build.gradle
filebuild.gradle
file, exclude support libs FOR EACH item (see example below)
api('com.android.support:support-media-compat:27.0.2') {
exclude group: 'com.android.support'
}
api('com.android.support:support-v7:27.0.2') {
exclude group: 'com.android.support'
}
I will also recommend not using com.android.support:support-v7:27.0.2
instead use only the specific items from support libs that you need. See Support Library Packages on how can you add only specific items from support libs.
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