1

I'm creating an instant version of my Android game. I have followed the instructions on this example:

https://codelabs.developers.google.com/codelabs/android-instant-apps/index.html?index=..%2F..%2Findex#0

The problem is that in the feature module I need to access services implemented by the com.google.gms.google-services plugin, so I put it at the bottom of my dependencies in the gradle file for such module, but as the package name of my game is (say) com.me.mygame while the one for the feature module would be com.me.mygame.base, the aforementioned plugin fails because there's no com.me.mygame.base package defined in my app google-services.json file.

So I tried by setting the name of the feature module to com.me.mygame too and that made the trick for that and gradle would successfully build the project, but it will fail when trying to build the APKs due

com.android.dex.DexException: Multiple dex files define Lcom/me/mygame/BuildConfig

I tried to workaround this by adding this option to my gradle modules, as suggested in an answer to a related question here:

android {
    dexOptions {
        preDexLibraries = false
    }
}

But to no avail. The problem persist.

It seems the logical thing would be that the feature module has a different package name, but as told before this will fail due the com.google.gms.google-services plugin not founding a configuration for such package.

So... I'm stuck at this and have run out of ideas, so any help will be welcomed.

Thanks a million in advance!

UPDATE: I have published a minimal example in github at the following URL:

https://github.com/fmmarzoa/IssuesWithFirebaseCrashlytics

I've took that example directly from Google Guides. The master branch is empty, those with the workarounds I've tried so far are all named 'firebase/...'. The last one is this 'firebase/updating-plugins':

https://github.com/fmmarzoa/IssuesWithFirebaseCrashlytics/tree/firebase/updating-plugins

What I have done in that one is to update several things as suggested by dchai, and it seems to do the trick for the Google Services plugin (at least it does build now) but the Firebase Crashlytics plugin which depends on the aforementioned one continues failing with the error message:

Crashlytics could not find the manifest. Not found at /Users/fran/Desktop/Idea/android-topeka/base/build/intermediates/merged_manifests/debug/AndroidManifest.xml

Fran Marzoa
  • 4,293
  • 1
  • 37
  • 53
  • You have the same dependency defined in multiple places. It looks like BuildConfig in this instance. Unless you have removed part of the log. – dazza5000 Aug 30 '18 at 21:40
  • `apply plugin: 'com.google.gms.google-services'` should only go in the app and base modules. – TWL Aug 31 '18 at 19:19
  • @dazza5000 BuildConfig is generated automatically by gradle. – Fran Marzoa Sep 06 '18 at 13:49
  • @TWL is where it is. The problem raises because it is in the base module, and the base module app id is different from the application module's one. (say com.me.mygame vs com.me.mygame.base) – Fran Marzoa Sep 06 '18 at 14:12
  • Yes, base package name is supposed to be different, but in your app module's gradle, you have `applicationId` and that's supposed to set the primary package name to be used. – TWL Sep 06 '18 at 16:05
  • otherwise, are you able to add both package names to your json? – TWL Sep 06 '18 at 16:07
  • You cannot use applicationId in a feature module, see my comment below answering to dchai. I didn't try to add both package names to my json file, that looks like quite a dirty hack, but it may work. I'll give it a try. Anyway with the updates suggested by dchai the project already build, but firebase crashlytics continue failing. I think this is a Firebase Crashlytics issue instead of Google Services, but I'm still waiting an answer from Firebase team about this. I'll publish whatever they say ASAP. – Fran Marzoa Sep 07 '18 at 17:42
  • I think your latest issue is similar to this [one](https://stackoverflow.com/questions/35371480/crashlytics-could-not-find-the-manifest-with-fabric-properties/35372226). – dev.for.fun Sep 13 '18 at 14:28
  • @dev.for.fun sure it's similar, but it's not the same unfortunately. That developer is using Fabric Crashlytics, I'm trying to use Firebase Crashlytics that doesn't even need/use fabric.properties file, all that fabric stuff it's supposed to be done under the hood. In fact, I'm considering to get rid of Firebase Crashlytics and go back to the pure Fabric experience. However, this very morning another developer told me he managed to make it to work without problems and he's about to publish an article with the code, so I'm going to wait to see his solution. – Fran Marzoa Sep 13 '18 at 14:41
  • I see, my bad. Have you heard back from the developer? It'll be better if you also post the answer you got. I'm having the same issue as well. – dev.for.fun Sep 14 '18 at 12:56
  • Not yet. He usually publish his stuff in Medium, but haven't updated yet. Also the guy of Firebase support told me yesterday he's going to try to reproduce the problem with their sample app and will come back with something. Don't worry, I'll update this question as soon as I have some solution. – Fran Marzoa Sep 15 '18 at 13:18
  • solved the issue. I added a manifest file to the path stated in the error message. – dev.for.fun Sep 21 '18 at 12:18
  • @dev.for.fun I understand you put a file by hand into the build directory. It maybe do the trick as a dirty workaround, but that manifest there is intended to be generated automatically. It even may be deleted when cleaning/rebuilding. Anyway, if you could elaborate a bit more that comment as an answer, I'll upvote you. I'm going back to fabric crashlytics until they provide a real solution. No news from the guy on medium, and the Firebase support dodge the question by blaming google services plugin or "your implementation". I asked for a proper implementation example to no avail. – Fran Marzoa Sep 21 '18 at 23:32
  • I was just starting a git flow feature to replace Firebase CL with Fabric CL when I realized that I *think* can actual solve this problem. The feature module needs Crashlytics only because there are several places where I call Crashlytics.log static method there, so I just have to decouple that using an interface. In fact, I already had a GameLogger interface created for things like these, but so far I had only used them for create different loggers for the Android and Desktop app (and soon for the iOS release). I can and should have take advantage of this decoupling also among android modules – Fran Marzoa Sep 22 '18 at 15:42
  • I will publish a more elaborate answer when I'm done with it and check that everything works fine. Actually I don't think beforehand any reason why it could fail with such an approach, since the firebase library won't know about the "base" module, neither the other way around. – Fran Marzoa Sep 22 '18 at 15:43
  • what do you mean by "your implementation"? mine or yours? I'm a bit confused on that part. However, I tried checking your github and it seems you have some implementation that looks like forced. Maybe the guy from Firebase support is pertaining to that part. I have had an issue about Firebase and Python before. Apparently, the issue is with Python and they couldn't help me telling that the issue isn't with Firebase but with Python. – dev.for.fun Sep 22 '18 at 19:23
  • I'm quoting their words, so they are implying that's something I have done wrong. I don't know if he has even looked at that code, and in any case if there was something wrong, he could have corrected it. All the code involved in my case is Java. – Fran Marzoa Sep 22 '18 at 23:19
  • PS. BTW, the code I uploaded to GitHub is an official google Android example on how to implement an instant app. I don't find anything forced there, anyway. In any case is not my code, is theirs. – Fran Marzoa Sep 22 '18 at 23:44
  • well, one example is that you've declared this line of code twice in your base/build.gradle file: implementation 'com.google.firebase:firebase-core:16.0.3' another example is in your other gradle files, you only declared this one while you didn't included the crashlytics dependencies. – dev.for.fun Sep 24 '18 at 07:51
  • I'll take a look on that, though it looks quite irrelevant for this matter and utterly unrelated with the error I'm describing here. Anyway, I have already solved it in my production code by other means. Thanks for reviewing my code anyway. I wish the firebase support guy would have had the same diligence. Can you believe that nobody from firebase had shown up here? And BTW, the guy from Medium told me yesterday that he actually had problems with Firebase Crashlytics too, but it seems he got someone competent at the other side of the help desk that actually helped him. – Fran Marzoa Sep 25 '18 at 00:31
  • @dev.for.fun just pulling your leg a bit there, mate. I just made some changes to my code and gave in using Firebase Crashlytics in the instant version of the app. Actually the instant version is a subset of the installed one, so most of the code is shared and if there's a crash, it's likely it'll show up on the installed version first. I'll get back to this issue eventually anyway, maybe after some of those plugins new releases things are straight forward. Thanks for your support here and by email. – Fran Marzoa Oct 03 '18 at 14:18
  • @FranMarzoa, thanks for the update too. Hope you get the best results to your app! :) – dev.for.fun Oct 04 '18 at 10:37

1 Answers1

2

Older versions of plugins don't correctly pick up applicationId for the purposes of checking against google-services.json.

If you upgrade to com.android.tools.build:gradle:3.3.0-alpha08 and com.google.gms:google-services:4.1.0, your original project structure should build fine.

dchai
  • 231
  • 2
  • 4
  • Same problem. I had to update the gradle wrapper version to 4.9+, so I updated it to 4.10. Got into some errors as expected, solved them, but now I'm in the same place I was before: Crashlytics complain about not finding its key because it's trying to find it for the common module ID instead of the application one. – Fran Marzoa Aug 31 '18 at 16:35
  • I tried to add the applicationId to the defaultConfig section of the feature module too, to see if that makes the trick, but then I got an error "Library projects cannot set applicationId." – Fran Marzoa Aug 31 '18 at 16:41
  • BTW, I'm using Firebase Crashlytics, not the standalone one, so the google-services plugin should take care of it. – Fran Marzoa Aug 31 '18 at 17:21
  • I tried by removing the crashlytics plugin from the feature module gradle script, and now it builds the APKs, but crashes on the device "java.lang.IllegalStateException: Must Initialize Fabric before using singleton()" so I guess by removing it, the google-services plugin is not initializing something it should. I'm gonna jump thru the window... – Fran Marzoa Aug 31 '18 at 18:36