6

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
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
iamkaan
  • 1,495
  • 2
  • 23
  • 43
  • This may or may not be related, but you may be in for more problems even if you get things to build. https://groups.google.com/forum/#!topic/firebase-talk/EAF4KZsB7I0 – Doug Stevenson Jan 17 '18 at 03:12
  • What is the package name for your installed app and instant app (denoted in the androidmanifest.xml) – dazza5000 Jan 17 '18 at 03:31
  • added all package names at the end of the question – iamkaan Jan 17 '18 at 03:56
  • See this other answer: https://stackoverflow.com/a/46776897 – dchai Jan 17 '18 at 04:20
  • can you check https://github.com/googlesamples/android-instant-apps/tree/master/analytics might it help you. – Prags Jan 17 '18 at 07:20
  • When I targeted 27, added support lib 27.0.2, Firebase 11.8.0 and gms 3.1.0, I didn't get any error. Can you provide your gradle file dependencies and the version values? – TWL Jan 19 '18 at 23:08

2 Answers2

2

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:

  1. Don't exclude anything while adding Base Module in main application, i.e. keep using implementation project(':app-base') only
  2. Use api instead of implementation for support libs included inside Base Module's build.gradle i.e. api 'com.android.support:support-v4:27.0.2'
  3. Make sure whichever library you've added in Base Module must NOT be added again in main app's build.gradle file
  4. 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.

adnanyousafch
  • 1,172
  • 9
  • 26
  • Exclusions may lead to having different versions of the support library within your application. This can have unwanted side effects and is therefore not recommended. – Ben Weiss Jan 18 '18 at 10:10
  • @keyboardsurfer Exclusions lead to different versions if done on few dependencies only. If it's done on all then it might lead to missing dependency compile error which can be solved by including them but not the different version as anything and everything from support libs is being included explicitly. Besides if no exclusion is done then just the v4 and v7 takes up 2+ MB of space which is 50+% size of allowed Instant App limit (4MB) – adnanyousafch Jan 18 '18 at 10:20
0

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'