问题
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
- app manifest:
com.iamkaan.packagename
- app gradle applicationId:
com.iamkaan.packagename
- app-base manifest:
com.iamkaan.packagename.base
- app-base gradle file doesn't have an applicationId
回答1:
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:
- Don't exclude anything while adding Base Module in main application, i.e. keep using
implementation project(':app-base')
only - Use
api
instead ofimplementation
for support libs included inside Base Module'sbuild.gradle
i.e.api 'com.android.support:support-v4:27.0.2'
- Make sure whichever library you've added in Base Module must NOT be added again in main app's
build.gradle
file - MOST IMPORTANT: For both main app and base module's
build.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.
回答2:
try this. SDK is 28
implementation ('com.google.firebase:firebase-core:16.0.6'){
exclude module: 'support-media-compat'
exclude module: 'support-v4'
}
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'
来源:https://stackoverflow.com/questions/48292901/firebase-support-library-dependency-conflict-for-instant-apps