Firebase AdMob, Android NDK and Bazel: @integer/google_play_services_version

388 views
Skip to first unread message

sbilkoloft

unread,
Oct 26, 2016, 10:45:20 AM10/26/16
to Firebase Google Group
Hi,

I'm trying to initialize AdMob in my native android app. I'm not using Android Studio but instead using Bazel (Google folks know it as Blaze). When I call Initilize on AdMob I get this error:

W/System.err(24443): java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
W/System.err(24443): at com.google.android.gms.common.zze.zzbt(Unknown Source)
W/System.err(24443): at com.google.android.gms.common.zze.isGooglePlayServicesAvailable(Unknown Source)
W/System.err(24443): at com.google.android.gms.common.zzc.isGooglePlayServicesAvailable(Unknown Source)
W/System.err(24443): at com.google.android.gms.ads.internal.util.client.zza.zzas(Unknown Source)
W/System.err(24443): at com.google.android.gms.ads.internal.client.zzl.zza(Unknown Source)
W/System.err(24443): at com.google.android.gms.ads.internal.client.zzl.zzl(Unknown Source)
W/System.err(24443): at com.google.android.gms.ads.internal.client.zzag.zza(Unknown Source)
W/System.err(24443): at com.google.android.gms.ads.MobileAds.initialize(Unknown Source)
W/System.err(24443): at com.google.android.gms.ads.MobileAds.initialize(Unknown Source)
W/System.err(24443): at com.google.firebase.app.internal.cpp.CppThreadDispatcher.nativeFunction(Native Method)
W/System.err(24443): at com.google.firebase.app.internal.cpp.CppThreadDispatcher.access$000(CppThreadDispatcher.java:8)
W/System.err(24443): at com.google.firebase.app.internal.cpp.CppThreadDispatcher$1.run(CppThreadDispatcher.java:16)
W/System.err(24443): at android.os.Handler.handleCallback(Handler.java:739)
W/System.err(24443): at android.os.Handler.dispatchMessage(Handler.java:95)
W/System.err(24443): at android.os.Looper.loop(Looper.java:145)
W/System.err(24443): at android.app.ActivityThread.main(ActivityThread.java:5942)
W/System.err(24443): at java.lang.reflect.Method.invoke(Native Method)
W/System.err(24443): at java.lang.reflect.Method.invoke(Method.java:372)
W/System.err(24443): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
W/System.err(24443): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
E/firebase(24443):  !jni_exception

In my manifest I have: 

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

Since I'm not using gradle or Android studio, I have a file res/values/integers.xml which contains:

<resources>
    <integer name="google_play_services_version">4030500</integer>
</resources>

Still the same error occurs. So if someone could kindly help me first figure how to fix this problem, and then show me from where I can extract this magic version number I blindly found off the Internet.

It seems so strange to me that Android development is being pushed so hard into using a specific IDE and build system.

Thanks.

Stewart Miles

unread,
Oct 26, 2016, 12:05:43 PM10/26/16
to fireba...@googlegroups.com
Hi, 

There are numerous build systems out there, it's exceptionally hard to support all of them well so the Android tools team focus on Gradle for Android Java components, ndk-build / cmake for native components.  If you try out another build system (e.g bazel - even though it's built by Google) you're setting yourself up for a hard time.  TBH if you look at other ecosystems (e.g VisualStudio for Windows, Xcode for iOS / OSX) you'll find a fairly similar story.

That said, if you wish to persist, the error points to missing the correct metadata in the final manifest that is used when packaging your application.  google_play_services_version may just be the tip of the iceberg here since you need to make sure you include not only the admob aar but all transitive dependencies in your application's build *and* make sure each aar's AndroidManifest.xml is being merged into the final manifest used by your application.  The easiest way to figure this out is to use one of our sample projects e.g https://github.com/firebase/quickstart-cpp/tree/master/admob/testapp and use Gradle to print out the set of dependencies (below I do this grabbing the dependencies of the "compile" target, removing the tree in the output and sorting the final list)...

$ ANDROID_HOME=$(readlink -f ~/dev/sdk/adt-current/sdk) ANDROID_NDK_HOME=$(readlink -f ~/dev/sdk/android-ndk-current) FIREBASE_CPP_SDK_DIR=. ./gradlew dependencies | awk '{ if (p) { print $0; if ($0 ~ /^$/) { exit } } } /^compile -/ { p = 1 }' | sed 's/.*\(com\.\)/\1/' | grep -v '(\*)$' | sort -u

com.android.support:support-annotations:24.0.0
com.android.support:support-v4:24.0.0
com.google.android.gms:play-services-ads:9.6.0
com.google.android.gms:play-services-ads-lite:9.6.0
com.google.android.gms:play-services-base:9.6.0
com.google.android.gms:play-services-basement:9.6.0
com.google.android.gms:play-services-clearcut:9.6.0
com.google.android.gms:play-services-gass:9.6.0
com.google.android.gms:play-services-tasks:9.6.0
com.google.firebase:firebase-ads:9.6.0
com.google.firebase:firebase-analytics:9.6.0
com.google.firebase:firebase-analytics-impl:9.6.0
com.google.firebase:firebase-common:9.6.0
com.google.firebase:firebase-core:9.6.0
com.google.firebase:firebase-iid:9.6.0

Is there anything tying your build to bazel?  How about building the C++ components in bazel then invoking gradle from a genrule to include the aar dependencies etc. and package the final application?

Cheers,
Stewart 







--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/d80a4f23-e0ab-4c94-8704-70d13275bb99%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sbilkoloft

unread,
Oct 27, 2016, 11:20:41 AM10/27/16
to Firebase Google Group
Hi Stewart,

Thanks for the insight. You are right about exiting echo systems and it has been a tough time getting things to work. I've come a long way.

The Android part of the project is a small piece of a bigger cake. So when it comes to build systems there are a lot more pros for Bazel than Gradle. Bazel almost does everything especially with the latest ability to import aar targets.

That being said a fallback onto Android studio is the backup plan. Would I get the gradlew script by importing the app once and run it as a gen rule from then on?

I was hoping that more widespread adaptation of Bazel could help us in the long run, starting with Google open-source projects including their BUILD files as well ;).

Cheers

Stewart Miles

unread,
Oct 27, 2016, 12:09:24 PM10/27/16
to fireba...@googlegroups.com
Regarding building with Gradle, I think - even though this does combine build systems - it would be easier to run your final Android packaging build step from a bazel genrule (which basically runs a shell command) using Gradle.  So you'll end up with BUILD for all of your C/C++ components, maybe some .jars etc. then the final build rules to generate the app would consist of a build.gradle file that is executed using the gradle command line via a BUILD genrule.  Make sense?

Cheers,
Stewart

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.

sbilkoloft

unread,
Nov 12, 2016, 11:44:48 AM11/12/16
to Firebase Google Group
To close this off, seems like that error was caused by a bug in Bazel:


For the record, Bazel can build android apps with firebase support. For a working sample see:

https://github.com/sbilkoloft/Bazel-Debug on master branch checkout tag "AdMob_ads"

Reply all
Reply to author
Forward
0 new messages