Android Question Compile error with Firebase Admob Library [SOLVED]

Computersmith64

Well-Known Member
Licensed User
Longtime User
To cut a long story short, I'm trying to get one of the Google Play Games Services wrappers to work with the latest version of Google Play Services (v9.2.0) so that I can use it in the same app as the Firebase AdMob wrapper. I have successfully updated the Google Play wrapper to work with v9.2.0 & can compile & run the app & confirm that the leaderboard, achievement, etc... functionality works fine. I can also compile the app with the FirebaseAdMob wrapper & confirm that it serves ads - however if I try to compile the app with both the FirebaseAdMob wrapper & the Google Play Games Services wrapper, I get the following error:

B4A version: 6.00
Parsing code. (0.16s)
Running custom action. (0.11s)
Compiling code. (0.60s)
Compiling layouts code. (0.03s)
Organizing libraries. (1.86s)
Generating R file. (0.30s)
Compiling debugger engine code. (2.88s)
Compiling generated Java code. (2.94s)
Convert byte code - optimized dex. Error
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/google/firebase/FirebaseApiNotAvailableException;
at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
at com.android.dx.command.dexer.Main.processClass(Main.java:615)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:570)
at com.android.dx.command.dexer.Main.access$2(Main.java:546)
at com.android.dx.command.dexer.Main$2.processFileBytes(Main.java:514)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:537)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:449)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:236)
at com.android.dx.command.dexer.Main.run(Main.java:206)
at com.android.dx.command.dexer.Main.main(Main.java:179)
at com.android.dx.command.Main.main(Main.java:103)
1 error; aborting

There's not really much else I can add that's of any use, except that v9.2.0 of Google Play Services has been broken down into multiple .aar files (which the .jar files can be extracted from) - each one containing a different part of the functionality that used to be in that one big google-play-services.jar. To get the wrapper to work with the Google Play Games Services wrapper, I had to use 7 of those "sub-jars" & put an @DependsOn clause in the java code for all of them. It appears that the error is coming from the play-services-basement-9.2.0 jar file.

Any ideas on how I can get around this?

Thanks - Colin.
 

DonManfred

Expert
Licensed User
Longtime User
how does the dependson directive in your wrapper looks like?
Do you use any #AdditionalJar in your project?
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
how does the dependson directive in your wrapper looks like?
Do you use any #AdditionalJar in your project?
Hi DonManfred - it looks like this:

B4X:
@DependsOn(values = { "android-support-v4", "google-play-services-auth-base", "google-play-services-base", "google-play-services-games", "play-services-auth", "play-services-basement", "play-services-drive", "play-services-nearby" })

I thought that maybe putting "com.google.firebase" in the -b4aignore field in SLC might help, but it doesn't seem to make a difference.

- Colin.
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
You should change the @DependsOn annotation in your library to the new maven repository.

B4X:
@DependsOn(values = { "com.android.support:support-v4", "com.google.android.gms:play-services-games"})

This may be enough.

The Android Studio example projects include these libraries:

B4X:
    compile "com.android.support:appcompat-v7:${appcompat_library_version}"
    compile "com.android.support:support-v4:${support_library_version}"
    compile "com.google.android.gms:play-services-games:${gms_library_version}"
    compile "com.google.android.gms:play-services-plus:${gms_library_version}"

I don't know, if you need appcompat-v7 and play-services-plus. You should start to try without them.

Just extract the .jar files to compile your library wrapper. Do NOT include the jar files in your additional libs folder for B4A. Use the maven repositories with B4A with the DependsOn line provided above.

For test purposes you can even delete the complete DependsOn line from your library and add the maven repository with #AdditionalJar in B4A like:

B4X:
#AdditionalJar: com.android.support:support-v4
#AdditionalJar: com.google.android.gms:play-services-games

If you get "NoClassDefFound" errors you can try to add additional entries: For a full list of all possible modules see here
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
You should change the @DependsOn annotation in your library to the new maven repository.

B4X:
@DependsOn(values = { "com.android.support:support-v4", "com.google.android.gms:play-services-games"})

Hah! I guess we must have been thinking along the same lines, because before you posted I tried exactly what you said. The problem I then had was that the dexer process would time out, even when I extended the time to 120 seconds. So to fix it, I changed the @DependsOn clause to this:

B4X:
@DependsOn(values = { "
com.android.support:appcompat-v7", "com.google.android.gms:play-services-auth-base", "com.google.android.gms:play-services-base", "com.google.android.gms:play-services-games", "com.google.android.gms:play-services-auth", "com.google.android.gms:play-services-basement", "com.google.android.gms:play-services-drive", "com.google.android.gms:play-services-nearby" })

& now it compiles & runs. I have run the app & confirmed that the Play Services Games & AdMob functionality is working as expected, however I'll do some more testing before I break out the champagne. The beauty of this approach is that it directly references the libraries downloaded using the Android SDK Manager (I think), so you don't need to copy libraries into the B4A libraries or additional libraries folder(s).

Thanks for the suggestions Corwin - you would have pointed me in the right direction if I hadn't figured it out!

- Colin.
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
The beauty of this approach is that it directly references the libraries downloaded using the Android SDK Manager (I think), so you don't need to copy libraries into the B4A libraries or additional libraries folder(s).

This is one of the big advantages of the maven repositories. The other big one is that you don't have to include additional resources with #AdditionalRes: lines.

Congratulations on getting it done. I think adding support for the maven repositories was a big step for B4A which will make using complex libraries much more simple in the future.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
@Computersmith64 Would you share the new Google play game services wrapper that works together with firebase admob?

I need to do some more testing on it & also check with Informatix (it's his wrapper that I recompiled with v9.2.0 of Google Play Services) first.
 
Upvote 0
Top