With official support moving away from Eclipse towards Android Studio and Gradle, new things like Firebase Analytics have become unavailable to developers wanting to continue using Eclipse for their app development. In this post, I will go through the libraries and the configuration required so you can integrate it in your Eclipse project.
You will observe compile errors like Tag ... attribute name has invalid character '$' after importing libraries like android-google-firebase-iid or android-google-firebase-common. To resolve the issue you will have to manually replace
Firebase Analytics libraries
dandar3/android-google-firebase-README project (GitHub) gives you an overview of the available Firebase libraires ready to use with your Eclipse project. Have a look at the two YouTube videos at the end covering the installation of the Subversive plugin and the steps to easily import an entire project set like Firebase Analytics into your workspace.
You will observe compile errors like Tag ... attribute name has invalid character '$' after importing libraries like android-google-firebase-iid or android-google-firebase-common. To resolve the issue you will have to manually replace
${applicationId}
with your application id (Java package) in all AndroidManifest.xml files (use CTRL+H > File Search > Replace...) Importing google-services.json
There is no Eclipse plugin to do the work that the Google Services Gradle plugin does for Android Studio (I have started working on one, but I can't say when this will be available), so you would have to read the Firebase documentation and follow the Processing the JSON File information to manually create your own values.xml.
If you're having trouble with getting this right you could use Android Studio to import firebase/quickstart-android GitHub project, deploy your google-services.json into it and then copy the generated values.xml out.
If you're having trouble with getting this right you could use Android Studio to import firebase/quickstart-android GitHub project, deploy your google-services.json into it and then copy the generated values.xml out.
You can also try the web conversion tool I wrote, the conversion is done in your browser through JavaScript like you would do it manually. You need to download your google-services.json from Firebase Console, then use the tool to open it and will generate your values.xml just like you would manually do it.
This is the undocumented part that can only be observed by looking at the AndroidManifest.xml generated by Google Services Gradle plugin (app\intermediates\manifests\full\debug\AndroidManifest.xml).
Without these changes you would get all sorts of errors in logcat when running your app, some of them listed below:
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="default_web_client_id" translatable="false">{YOUR_CLIENT}/oauth_client/[first client_type 3]</string> <string name="gcm_defaultSenderId" translatable="false">project_info/project_number</string> <string name="firebase_database_url" translatable="false">project_info/firebase_url</string> <string name="google_app_id" translatable="false">{YOUR_CLIENT}/client_info/mobilesdk_app_id</string> <string name="google_api_key" translatable="false">{YOUR_CLIENT}/services/api_key/current_key</string> <string name="google_storage_bucket" translatable="false">project_info/storage_bucket</string> </resources>
AndroidManifest.xml changes
This is the undocumented part that can only be observed by looking at the AndroidManifest.xml generated by Google Services Gradle plugin (app\intermediates\manifests\full\debug\AndroidManifest.xml).
<?xml version="1.0" encoding="utf-8"?> <manifest> [...] <!-- Required permission for App measurement to run. --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" /> <application> [...] <receiver android:name="com.google.android.gms.measurement.AppMeasurementReceiver" android:enabled="true" android:exported="false" > </receiver> <receiver android:name="com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver" android:enabled="true" android:permission="android.permission.INSTALL_PACKAGES" > <intent-filter> <action android:name="com.android.vending.INSTALL_REFERRER" /> </intent-filter> </receiver> <service android:name="com.google.android.gms.measurement.AppMeasurementService" android:enabled="true" android:exported="false" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <provider android:name="com.google.firebase.provider.FirebaseInitProvider" android:authorities="${applicationId}.firebaseinitprovider" android:exported="false" android:initOrder="100" /> <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="${applicationId}" /> </intent-filter> </receiver> <!-- Internal (not exported) receiver used by the app to start its own exported services without risk of being spoofed. --> <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" /> <!-- FirebaseInstanceIdService performs security checks at runtime, no need for explicit permissions despite exported="true" --> <service android:name="com.google.firebase.iid.FirebaseInstanceIdService" android:exported="true" > <intent-filter android:priority="-500" > <action android:name="com.google.firebase.INSTANCE_ID_EVENT" /> </intent-filter> </service> </application> </manifest>
Without these changes you would get all sorts of errors in logcat when running your app, some of them listed below:
11-04 15:56:22.970 E/FA ( 1539): AppMeasurementReceiver not registered/enabled 11-04 15:56:22.971 E/FA ( 1539): AppMeasurementService not registered/enabled ... 11-04 16:01:23.188 W/FA ( 1694): Failed to retrieve Firebase Instance Id ... 11-04 16:01:36.391 E AndroidRuntime: Process: com.google.firebase.quickstart.analytics, PID: 1718 11-04 16:01:36.391 E AndroidRuntime: java.lang.RuntimeException: Unable to start receiver com.google.android.gms.measurement.AppMeasurementReceiver: java.lang.SecurityException: Neither user 10067 nor current process has android.permission.WAKE_LOCK.
Testing
Enable verbose / debug logging for Firebase Analytics (docs):
adb logcat -c adb shell setprop log.tag.FA VERBOSE adb shell setprop log.tag.FA-SVC VERBOSE adb logcat -v time -s FA FA-SVC
If everything looks fine you may notice the upload scheduling is nothing close to Google Analytics (1h to 12h) - Steve Ganem, Product Manager at Firebase Analytics, confirms on StackOverflow he is aware of the need for quicker reporting.
11-05 21:01:21.560 V/FA ( 1418): Upload scheduled in approximately ms: 3599998
One way to trigger the initial upload found by Yapaxi user on the same thread, is to Clear data for your app. That will not make the information immediately on the Firebase Console web app, it could take up to an hour or more before the reports are made available.
--------- beginning of system --------- beginning of main 11-05 21:25:17.413 I/FA ( 1761): App measurement is starting up, version: 9877 11-05 21:25:17.413 I/FA ( 1761): To enable debug logging run: adb shell setprop log.tag.FA VERBOSE 11-05 21:25:17.413 D/FA ( 1761): Debug-level message logging enabled 11-05 21:25:17.413 D/FA ( 1761): AppMeasurement singleton hash: 96720111 11-05 21:25:17.418 V/FA ( 1761): Collection enabled 11-05 21:25:17.418 V/FA ( 1761): App package, google app id: com.google.firebase.quickstart.analytics, 1:348775509088:android:a9b2141120408d37 [...] 11-05 21:25:27.931 V/FA ( 1761): Uploading data. app, uncompressed size, data: com.google.firebase.quickstart.analytics, 445, 11-05 21:25:27.931 V/FA ( 1761): batch { 11-05 21:25:27.931 V/FA ( 1761): bundle { 11-05 21:25:27.931 V/FA ( 1761): protocol_version: 1 11-05 21:25:27.931 V/FA ( 1761): platform: android 11-05 21:25:27.931 V/FA ( 1761): gmp_version: 9877 11-05 21:25:27.931 V/FA ( 1761): uploading_gmp_version: 9877 11-05 21:25:27.931 V/FA ( 1761): config_version: 1477992761690000 11-05 21:25:27.931 V/FA ( 1761): gmp_app_id: 1:348775509088:android:a9b2141120408d37 11-05 21:25:27.931 V/FA ( 1761): app_id: com.google.firebase.quickstart.analytics [...] 11-05 21:25:27.931 V/FA ( 1761): } 11-05 21:25:27.931 V/FA ( 1761): } 11-05 21:25:27.931 V/FA ( 1761): Uploading data. size: 431 11-05 21:25:28.039 V/FA ( 1761): Upload scheduled in approximately ms: 3599999 11-05 21:25:28.042 V/FA ( 1761): Successful upload. Got network response. code, size: 204, 0
That's it - check your data up on Firebase Console an hour or so later.
How to generate google-services.json to value.xml ?
ReplyDeleteAnd where to put that value.xml files in Eclipse?
Thanks
You missed the "Processing the JSON File" link in the "Importing google-services.json" section - it should take you to Google's website where they explain what values goes into what. The same is hinted in the XML section up in the post here, but you need to open the .json file to see the resemblence.
DeleteBeing a string resouce file the convention is to save it in \res\values\ folder, it is also hinted in the title of the XML section up in the post.
Hope it helps you.
Thank you very much.
DeleteMore clear now.
Thanks for your information, but may I use for Cloud Messaging? Is it have same way to use in Eclipse?
ReplyDeletemany thanks.
Pretty much the entire article should still apply, you just need the dandar3/android-google-firebase-messaging library (+ dependencies off course). Let us know how it works for you!
DeleteThanks man, it works! Your article give me pretty much information that I need.
Delete:)
You're welcome! :-) I just made Cloud Messaging available following your question, glad to hear it works. I might write a new post soon specifically just for Cloud Messaging just so there is one, but I expect it not to be too different.
DeleteHi! Is there are any instructions to send notification to android app using GCM? How to use it in eclipse?
DeleteI´m getting some errors.
ReplyDeleteFor example -> E/AndroidRuntime(29194): java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file.....
Any ideas? I copied everything into my manifest
Hi Denis,
DeleteYou're getting the error because it found the entry in the manifest, but it didn't find the class - that class is in the firebase-common library.
As I've pointed out in the above post in the "Firebase Analytics libraries" section, best to read the dandar3/android-google-firebase-README project on GitHub for details, especially the videos at the end that show you how to easily import the libraries you need into your project.
Or maybe read this StackOverflow thread in case you've added the libraries to your project the Java way and not the Android way. http://stackoverflow.com/a/10965393
Please contact me by email if your problem still doesn't resolve.
This comment has been removed by the author.
DeleteHi Dan ,
DeleteI have the same errors like Denis (class not found problem) , i did every thing was told in dandar3/android-google-firebase-README , i imported the project android-google-firebase-iid with team project set , the import passed good with no errors all is ok , i changed the ${applicationId} in the all project , but unfortunately while building the project the class com.google.firebase.provider.FirebaseInitProvider unable to found , help plzzzzzzzzzzz !!!
thanks in advance
Delete@Red Eye
DeleteIf you already added the android-google-firebase-analytics project as a dependat library to your project (Properties > Android > Library section), I would try next to add android-google-firebase-iid as well in there, clean your project, build and try again.
Thank you for your information! Is there are any instructions to send notification to android app using firebase cloud messaging? How to use it in eclipse?
ReplyDeleteCurrently working on that, hoping to have it published by the end of the weekend.
DeleteSounds perfect, looking forward to it. Thanks a lot for your work
DeleteThe libraries for Firebase Cloud Messaging have ${applicationId} given in their manifest file. However, eclipse is giving an error because of the "$" sign. Any suggestions on how to solve this issue? Thank you !
ReplyDeleteTake a note on the library project with the errors and see the README.md for that project. It will tell you to replace ${applicationId} with the package of your application - that is a step that Android Studio does for you but Eclipse doesn't know anything about, you will have to manually change it. See https://github.com/dandar3/android-google-firebase-iid/ as a reference.
DeleteThank you for your help !
DeleteWill the information about sending notifications to android app using firebase cloud messaging be published soon? Thank you so much for the help
ReplyDeleteJust posted today, should not be much different than this one, but it's out there now.
DeleteWhen I add the permissions to android manifest I get an installation error : INSTALL_FAILED_CONFLICTING_PROVIDER. Any idea why that is happening?
ReplyDeleteProbably because of conflicting provider authorities. See the updated AndroidManifest.xml template, you need to replace ${applicationId} with your application id (Java package). https://developer.android.com/studio/build/application-id.html
DeleteAm i supposed to replace the ${applicationId} with my package name? where do i get the package name from? I have read the https://github.com/dandar3/android-google-firebase-iid/ reference but i am still not sure where to get the package name from. Thank you for the help.
ReplyDeleteYou've defined a package name when you created your application, it's in the <manifest> element in AndroidManifest.xml, see https://developer.android.com/guide/topics/manifest/manifest-element.html Can you please contact me by email dan.dar33 at gmail.com for questions unrelated directly to this post please, it would be easier for everyone, thanks.
DeleteHi, I follow the steps given, and my app immediately crash when starting.
ReplyDeleteThis is the log:
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gms.R$string
at com.google.android.gms.common.internal.zzam.(Unknown Source)
at com.google.firebase.FirebaseOptions.fromResource(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1214)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1189)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:5119)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4725)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4665)
at android.app.ActivityThread.access$1400(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1376)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method)
I think it missing parameters for initialisation, i think from google-services.json.
But I already converted my google-services.json into values.xml and put the file into my res folder (res/values/values.xml)
Any idea why the string cannot be found? Thank you very much for your attention.
I believe you posted the same problem on the other thread, see my answer below.
Deletecom.google.android.gms.R$string is in google-play-services-basement.
If you go to dandar3/android-google-firebase-README project on GitHub (linked in article above) you can see all the libraries you need grouped by Firebase library.
I would suggest using Eclipse to download an entire set easily (see the video explaining how to download an entire project set), then import in IntelliJ all projects from the Eclipse workspace.
Hi Dan, I saw similar question on FCM thread.
DeleteI am a different person, just happen asking similar question on the same day. hehe.
"com.google.android.gms.R$string is in google-play-services-basement." this really saved me from my problem.
I has been wondering for quite some time.
In my case, I directly include all *.jar for firebase & google sdk without their individual project.
With this method I can initialise firebase manually using code,
but not automatically using FirebaseInitProvider from manifest.
After reading your reply, i tried importing google-play-services-basement as a project, complete with it res folder.
Then everything works fine!
Thank you very mush for your reply :D
You're welcome. glad you sorted it out! Yes, you need the entire projects, resources and all, not just the classes in the JARs. The libraries from GitHub are just the AAR packages exploded and reorganized so that they can be consumed by Eclipse ADT, which doesn't have AAR support. https://developer.android.com/studio/projects/android-library.html#aar-contents
DeleteHow can i integrate with android studio (no gradle) ?
ReplyDeleteThis comment has been removed by the author.
DeleteHi dan my app is crash this is my log
DeleteCaused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.R$string" on path: DexPathList[[zip file "/data/app/com.bisnews.bisnewscompanionmobile.dev-2/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.google.android.gms.common.internal.zzam.(Unknown Source)
at com.google.firebase.FirebaseOptions.fromResource(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1686)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1655)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:4964)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4559)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4499)
at android.app.ActivityThread.access$1500(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.R$string
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 20 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
what should i do ? thanks :)
I've already answered this in a preview comment: com.google.android.gms.R$string is in google-play-services-basement.
DeleteIf you go to dandar3/android-google-firebase-README project on GitHub (linked in article above) you can see all the libraries you need grouped by Firebase library.
As for Android Studio with no gradle, I see there is a File > New... > New Module > Import .JAR / .AAR Package. Run android-sdk\SDK Manager, install Extras > Google Repository, then import from androi-sdk\extras\google\m2repository\.
Otherwise I guess you could try importing libraries I prepare for Eclipse with File > New... > New Module > Import Eclipse ADT Project.
I'm try File > New... > New Module > Import .JAR / .AAR Package. but android studio create file build.gradle when import success and show error "Gradle Project sync failed. Please fix your project and try again".
DeleteMy project can't use gradle what should i do next as well? thanks!
I would also try the second suggested solution, importing my libraries with File > New... > New Module > Import Eclipse ADT Project.
DeleteIf everything else fails I would manually create an Android Library using File > File... > New Module > Android Module, explode the AAR yourself into a temporary location and manualy copy the resources into this new library.
But why not using gradle with Android Studio?
thanks for your help! I will try this again.
DeleteMy old project is from eclipse now I'm use in Android studio. I'm try migrate to gradle but it's fails. because duplicate resource from multi module in my project this can't delete.
Please advice me to migrate project to use gradle.
Sorry I can't help you with migrating the project to Android Studio without seeing the project and the errors. Probably not the best place to discuss it here, send me an email to dan.dar33 at gmail.com if you want to discuss it there at length.
DeleteUpdate.. I can import module but onRefreshedToken not working.
ReplyDeletethis is my error https://www.uppic.org/share-D106_58DDE401.html
Thanks! :D
I'm try coding FirebaseApp.initializeApp(this); in RootActivity.java
DeleteThis is log.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.bisnews.tnstradecode, PID: 26240
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/R$string;
at com.google.android.gms.common.internal.zzam.(Unknown Source)
Note: I'm use Firebase notification
You jumped a few things, better read the this blogpost about Cloud Messaging:
Deletehttp://dandar3.blogspot.com/2017/01/eclipse-integrating-firebase-messaging.html
and you shouldn't call onTokenRefresh() youself, see the Google reference app mentioned in the post and the FirebaseInstanceIdService class here (the one you are trying to implement):
https://github.com/firebase/quickstart-android/tree/master/messaging
com/google/android/gms/R$string is part of google-play-services-basement package which you may not be referencing in your project as a module dependenct, check the APK (see Android Studio APK analyzer feature - https://developer.android.com/studio/build/apk-analyzer.html)
DeleteAlthough I can see the basement module in your screenshot there might be a chance you haven't added it as dependecy module to your app (Project > select your app project > right click > Open Module Settings > app > Dependencies).
I followed your steps and i am able to get the result now i am waiting for the analytics report in console which is not populated yet. Meanwhile can you tell me do we have same procedure for Firebase crash reporting ?
ReplyDeleteAll that is different really between Eclipse and Android Studio is that you need take down into the project all required libraries yourself and to manually add the entries to AndroidManifest.xml as there is no plugin to do it for you. Once those are down you're back to following the standard instructions. https://firebase.google.com/docs/crash/android
Deletei tried following steps for firebase crash
Delete1) Extracting AAR from
C:\Program Files (x86)\Android\android-sdk\extras\google\m2repository\com\google\firebase\firebase-crash\10.2.4
here is the AAR extract looks like
https://screenshot.net/915q3c5
2) Now i have create a folder structure that i can import in eclipse
here it looks like
https://screenshot.net/93oxjie
3) then i tried to import it into eclipse and done add to project
https://screenshot.net/93oxjie
but still i am not able to get the crash report on the console
05-15 15:17:50.410: I/FirebaseCrashApiImpl(23661): FirebaseCrashApiImpl created by ClassLoader p[DexPathList[[zip file "/data/data/com.google.android.gms/app_chimera/m/00000007/DynamiteModulesC_GmsCore_prodlmp_alldpi_release.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]]
05-15 15:17:50.531: I/FirebaseCrash(23661): FirebaseCrash reporting initialized com.google.android.gms.internal.zzbnq@1f61fc96
05-15 15:17:50.532: I/FirebaseInitProvider(23661): FirebaseApp initialization successful
can you please help in resolving
Firebase Crash Reporting library is not part of the 10.2.6 release, try it on and let me know how it goes. https://github.com/dandar3/android-google-firebase-README
DeleteI am not able to view my analytics on firebase on console , following is the log that i can see in logcat
ReplyDeletecom.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
FirebaseCrashApiImpl created by ClassLoader p[DexPathList[[zip file "/data/data/com.google.android.gms/app_chimera/m/00000003/DynamiteModulesC_GmsCore_prodlmp_alldpi_release.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]]
05-11 21:20:51.717: I/FA(5054): App measurement is starting up, version: 10298
05-11 21:20:51.717: I/FA(5054): To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
05-11 21:20:51.729: I/FA(5054): Faster debug mode event logging enabled. To disable, run:
05-11 21:20:51.729: I/FA(5054): adb shell setprop debug.firebase.analytics.app .none.
05-11 21:20:51.735: I/FirebaseCrash(5054): FirebaseCrash reporting initialized com.google.android.gms.internal.zzbnq@28b9350d
05-11 21:20:51.736: I/FirebaseInitProvider(5054): FirebaseApp initialization successful
05-11 21:20:54.015: I/FA(5054): Tag Manager is not found and thus will not be used
i get Tag Manger is not found after my statement get executed i.e.
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "110");
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name);
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "image");
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);
Tell me more about your context: device / emulator, Android API version, Firebase library version, did you take all libraries required by Firebase Analytics (see https://github.com/dandar3/android-google-firebase-README + the videos at the end).
DeleteHi,
ReplyDeleteCan you help me with the Eclipse Firebase integration.
How can I solve the problem below.
08-08 08:25:54.443: E/AndroidRuntime(1510): FATAL EXCEPTION: main
08-08 08:25:54.443: E/AndroidRuntime(1510): Process: info.androidhive.firebasenotifications1, PID: 1510
08-08 08:25:54.443: E/AndroidRuntime(1510): java.lang.NoClassDefFoundError: com.google.firebase.FirebaseApp
08-08 08:25:54.443: E/AndroidRuntime(1510): at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source)
08-08 08:25:54.443: E/AndroidRuntime(1510): at info.androidhive.firebasenotifications1.activity.Yeni_MainActivity.onCreate(Yeni_MainActivity.java:21)
08-08 08:25:54.443: E/AndroidRuntime(1510): at android.app.Activity.performCreate(Activity.java:5231)
08-08 08:25:54.443: E/AndroidRuntime(1510): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-08 08:25:54.443: E/AndroidRuntime(1510): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
08-08 08:25:54.443: E/AndroidRuntime(1510): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
08-08 08:25:54.443: E/AndroidRuntime(1510): at android.app.ActivityThread.access$800(ActivityThread.java:135)
08-08 08:25:54.443: E/AndroidRuntime(1510): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
08-08 08:25:54.443: E/AndroidRuntime(1510): at android.os.Handler.dispatchMessage(Handler.java:102)
08-08 08:25:54.443: E/AndroidRuntime(1510): at android.os.Looper.loop(Looper.java:136)
08-08 08:25:54.443: E/AndroidRuntime(1510): at android.app.ActivityThread.main(ActivityThread.java:5017)
08-08 08:25:54.443: E/AndroidRuntime(1510): at java.lang.reflect.Method.invokeNative(Native Method)
08-08 08:25:54.443: E/AndroidRuntime(1510): at java.lang.reflect.Method.invoke(Method.java:515)
08-08 08:25:54.443: E/AndroidRuntime(1510): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
08-08 08:25:54.443: E/AndroidRuntime(1510): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
08-08 08:25:54.443: E/AndroidRuntime(1510): at dalvik.system.NativeStart.main(Native Method)
Regards.
java.lang.NoClassDefFoundError: com.google.firebase.FirebaseApp
DeleteSounds like the firebase-iid class did exist at compile time but it's missing from the APK package. Have you dissabled it and look at the DEX files?
Also, how did you import the library projects, did you lump them all toghether like in one of the comments above with somewhat similar problems, or did you use the Team Set import as shown in the videos at the end of dandar3/android-google-firebase-README page?
Hi,
ReplyDeleteI put firebase-iid_9.6.1.jar in the project
I put firebase-messaging-9.6.1.jar in the project
I can share source codes if you want.
Where am I making mistakes?
08-10 17:00:20.602: E/AndroidRuntime(3729): FATAL EXCEPTION: main
08-10 17:00:20.602: E/AndroidRuntime(3729): Process: info.androidhive.firebasenotifications1, PID: 3729
08-10 17:00:20.602: E/AndroidRuntime(3729): java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/FirebaseApp;
08-10 17:00:20.602: E/AndroidRuntime(3729): at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source)
08-10 17:00:20.602: E/AndroidRuntime(3729): at info.androidhive.firebasenotifications1.MainActivity.onCreate(MainActivity.java:23)
08-10 17:00:20.602: E/AndroidRuntime(3729): at android.app.Activity.performCreate(Activity.java:6289)
08-10 17:00:20.602: E/AndroidRuntime(3729): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
08-10 17:00:20.602: E/AndroidRuntime(3729): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2655)
08-10 17:00:20.602: E/AndroidRuntime(3729): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)
08-10 17:00:20.602: E/AndroidRuntime(3729): at android.app.ActivityThread.access$900(ActivityThread.java:177)
08-10 17:00:20.602: E/AndroidRuntime(3729): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
08-10 17:00:20.602: E/AndroidRuntime(3729): at android.os.Handler.dispatchMessage(Handler.java:102)
08-10 17:00:20.602: E/AndroidRuntime(3729): at android.os.Looper.loop(Looper.java:145)
08-10 17:00:20.602: E/AndroidRuntime(3729): at android.app.ActivityThread.main(ActivityThread.java:5951)
08-10 17:00:20.602: E/AndroidRuntime(3729): at java.lang.reflect.Method.invoke(Native Method)
08-10 17:00:20.602: E/AndroidRuntime(3729): at java.lang.reflect.Method.invoke(Method.java:372)
08-10 17:00:20.602: E/AndroidRuntime(3729): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
08-10 17:00:20.602: E/AndroidRuntime(3729): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
08-10 17:00:20.602: E/AndroidRuntime(3729): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.FirebaseApp" on path: DexPathList[[zip file "/data/app/info.androidhive.firebasenotifications1-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
08-10 17:00:20.602: E/AndroidRuntime(3729): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
08-10 17:00:20.602: E/AndroidRuntime(3729): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-10 17:00:20.602: E/AndroidRuntime(3729): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
08-10 17:00:20.602: E/AndroidRuntime(3729): ... 15 more
08-10 17:00:20.602: E/AndroidRuntime(3729): Suppressed: java.lang.ClassNotFoundException: com.google.firebase.FirebaseApp
08-10 17:00:20.602: E/AndroidRuntime(3729): at java.lang.Class.classForName(Native Method)
08-10 17:00:20.602: E/AndroidRuntime(3729): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
08-10 17:00:20.602: E/AndroidRuntime(3729): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
08-10 17:00:20.602: E/AndroidRuntime(3729): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
08-10 17:00:20.602: E/AndroidRuntime(3729): ... 16 more
08-10 17:00:20.602: E/AndroidRuntime(3729): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
Hi again,
DeleteMaybe the jar files I added to the project are wrong
I tried all versions.
But I could not find a solution
Regards,
There's to it than just adding the JAR files to your project.
DeleteFollow the resources below (end of dandar3/android-google-firebase-README):
1. http://www.youtube.com/watch?v=04L4rkykWZw
2. http://www.youtube.com/watch?v=ytRSnjp56tA
3. File > Import... > SVN > Project from SVN > Create a new repository location > URL:
https://github.com/dandar3/android-google-firebase-messaging/tags/11.0.2
4. Add google-firebase-messaging library (or analytics) and add as a dependent library to your application.
Hi again.
DeleteI bothered you again.I am so sorry
1.OK
2.OK
3.In the 3rd stage, I got an error like below.
Checkout operation for 'https://github.com/dandar3/android-google-firebase-messaging/tags/11.0.2' failed.
svn: E200030: Invalid expression
How can I solve it.
Regards.
That shouldn't have errored out, but sorry that's not the easiest way I meant, please try the one below:
Delete(Eclipse) File > Import... > Team > Team Project Set > URL:
https://raw.githubusercontent.com/dandar3/android-google-firebase-messaging/11.0.2/.projectset
Hi again,
DeleteI bothered you again.I am so sorry
I've tried,I have the error below
Selected resource is not checked out.
svn: E175002: PROPFIND of '/dandar3/android-google-firebase-messaging/11.0.2/.projectset': 400 Bad Request (https://raw.githubusercontent.com)
How can I solve it.
Regards,
You're not bothering me at all, but I think we can sort it out quicker by email (click on my name here to see the email address) and send me a screenshot with Eclipse and the error.
Deletethx man i really needed this as google shifted to studio but me i still work on eclipse i have to configure many things but this article just answered my answer.
ReplyDeletethx again
You're quite welcome, let me know if anything else.
DeleteHello! My project had join google services before,and now I should reJoin the google services jars now??? maybe the version of the google services is not matching with the version of firebase?
ReplyDeleteNot quite sure I understand your question or the problem you're having. Should you update the Google Play Services integration or start using Google Firebase? The simple answer is no, you don't if your application works fine with the older version you already integrated.
DeleteHello Friend
ReplyDeleteFirst of all thank you for the time you have made available to help the community with this article.
I followed your guidelines.
I already imported all the libs.
I've already changed the name $ {applicationId} for my package name:
Now when I add Lib-> google-firebase-analytics in my project several errors are presented, as below:
[2017-10-16 10:59:14 - 4firebase] (skipping file '.readme' due to ANDROID_AAPT_IGNORE pattern '.*')
[2017-10-16 10:59:14 - 4firebase] (skipping file '.readme' due to ANDROID_AAPT_IGNORE pattern '.*')
[2017-10-16 10:59:14 - 4firebase] (skipping file '.readme' due to ANDROID_AAPT_IGNORE pattern '.*')
[2017-10-16 10:59:14 - 4firebase] (skipping file '.readme' due to ANDROID_AAPT_IGNORE pattern '.*')
[2017-10-16 10:59:14 - 4firebase] (skipping file '.readme' due to ANDROID_AAPT_IGNORE pattern '.*')
[2017-10-16 10:59:14 - 4firebase] (skipping file '.readme' due to ANDROID_AAPT_IGNORE pattern '.*')
[2017-10-16 10:59:14 - 4firebase] (skipping file '.readme' due to ANDROID_AAPT_IGNORE pattern '.*')
[2017-10-16 10:59:14 - 4firebase] (skipping file '.readme' due to ANDROID_AAPT_IGNORE pattern '.*')
[2017-10-16 10:59:14 - 4firebase] (skipping file '.readme' due to ANDROID_AAPT_IGNORE pattern '.*')
[2017-10-16 10:59:14 - 4firebase] D:\Google DRIVE\workspace_atualizado\workspace\google-play-services_lib\res\values\base_attrs.xml:11: error: Attribute "buttonSize" already defined with incompatible format.
[2017-10-16 10:59:14 - 4firebase] D:\Google DRIVE\workspace_atualizado\workspace\google-play-services-basement\res\values\values.xml:290: Original attribute defined here.
[2017-10-16 10:59:14 - 4firebase] D:\Google DRIVE\workspace_atualizado\workspace\google-play-services_lib\res\values\base_attrs.xml:16: error: Attribute "colorScheme" already defined with incompatible format.
[2017-10-16 10:59:14 - 4firebase] D:\Google DRIVE\workspace_atualizado\workspace\google-play-services-basement\res\values\values.xml:298: Original attribute defined here.
[2017-10-16 10:59:14 - 4firebase] D:\Google DRIVE\workspace_atualizado\workspace\google-play-services_lib\res\values\common_attrs.xml:13: error: Attribute "imageAspectRatioAdjust" already defined with incompatible format.
[2017-10-16 10:59:14 - 4firebase] D:\Google DRIVE\workspace_atualizado\workspace\google-play-services-basement\res\values\values.xml:276: Original attribute defined here.
[2017-10-16 10:59:14 - 4firebase] D:\Google DRIVE\workspace_atualizado\workspace\google-play-services_lib\res\values\maps_attrs.xml:5: error: Attribute "mapType" already defined with incompatible format.
[2017-10-16 10:59:14 - 4firebase] D:\Google DRIVE\workspace_atualizado\workspace\google-play-services-basement\res\values\values.xml:20: Original attribute defined here.
Would you help me?
William, the easiest way of pulling all the necessary libraries with the correct versions is this way:
Delete1. Remove / move outside all existing Android Support / Google Play Services / Firebase libraries from your workspace (what is google-play-services-lib?)
2. Pick a Firebase version you want to use, e.g. 11.2.0
https://github.com/dandar3/android-google-firebase-analytics/tree/11.2.0
* Download into your workspace using the method shown in the two videos at the end of this page using its ProjectSet file: https://github.com/dandar3/android-google-firebase-README
* Add "android-google-firebase-analytics" as an Android library to your app properties;
* Clean / Rebuild workspace.
All libraries are linked to each other using project sets (for download) and referenced by their .project files (for compile).
Thanks for this tutorial Dan,
ReplyDeleteI did clean->build my project successfully but at the time when i export unsigned APK i am receiving this error
"Multiple dex files define Landroid/support/annotation/AnimRes",
I think its referring to android.support.v4 and annotations conflict but no idea which one?
1 - Created a new android project to test.
2 - Added "google-firebase-analytics" as library reference.
3 - Clean -> Build (Successful).
4 - Export Unsigned APK.
I tried removing the v4 Jar from libs folder and did clean->build but still same.
Thank you for your feedback. My thinking is that you have a mix of libraries that contain the class probably from various versions. If you want to confirm where is it coming from you could use this ClassFinder (https://github.com/gvenzl/ClassFinder/releases, run with java -jar ClassFinder.java), fill in the class name (android/support/annotation/AnimRes) and point it to your workspace location and search recursively - that will look in all jars in your workpace and it will show you if found in multiple places.
DeleteOtherwise, I would suggest this:
1. Create a new temporary workspace to test (clean slate)
2. Create a simple test app or if you intend to copy your app project make sure there's no Android Support Librarie in the \libs folder (no need to, the steps below will bring it)
2. Pick a Firebase Analytics version you want to use, e.g. 11.2.0
https://github.com/dandar3/android-google-firebase-analytics/tree/11.2.0
* Download into your workspace using the method shown in the two videos at the end of this page using its ProjectSet file: https://github.com/dandar3/android-google-firebase-README
* Add "google-firebase-analytics" as a library reference to your app properties;
* Clean / Build / Export APK
Thanks very much, For some reason i am not able to get SVN connectors into my eclipse SVN connector list and when i try to get/download SVN Kit 1.8 & JavaHL 1.9.x then i get this error "Problem occurred while performing installations". I tried to use SVN tool like smart SVN but dont know if its working with .projectset url or not as i am getting 400 bad request.
Deletebut somehow managed to build and export APK by manually downloading and adding library projects as dependencies, on the other hand even in new workspace i was still getting above Multiple dex error, i resolved it by directly adding projects in build path but getting this exception now when testing on device.
01-01 15:08:48.952: E/AndroidRuntime(3816): FATAL EXCEPTION: main
Delete01-01 15:08:48.952: E/AndroidRuntime(3816): Process: com.ma.firebaseanalyticstest, PID: 3816
01-01 15:08:48.952: E/AndroidRuntime(3816): java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.ma.firebaseanalyticstest-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
01-01 15:08:48.952: E/AndroidRuntime(3816): at android.app.ActivityThread.installProvider(ActivityThread.java:5558)
01-01 15:08:48.952: E/AndroidRuntime(3816): at android.app.ActivityThread.installContentProviders(ActivityThread.java:5150)
01-01 15:08:48.952: E/AndroidRuntime(3816): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5090)
01-01 15:08:48.952: E/AndroidRuntime(3816): at android.app.ActivityThread.access$1600(ActivityThread.java:177)
01-01 15:08:48.952: E/AndroidRuntime(3816): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1509)
01-01 15:08:48.952: E/AndroidRuntime(3816): at android.os.Handler.dispatchMessage(Handler.java:102)
01-01 15:08:48.952: E/AndroidRuntime(3816): at android.os.Looper.loop(Looper.java:145)
01-01 15:08:48.952: E/AndroidRuntime(3816): at android.app.ActivityThread.main(ActivityThread.java:5938)
01-01 15:08:48.952: E/AndroidRuntime(3816): at java.lang.reflect.Method.invoke(Native Method)
01-01 15:08:48.952: E/AndroidRuntime(3816): at java.lang.reflect.Method.invoke(Method.java:372)
01-01 15:08:48.952: E/AndroidRuntime(3816): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
01-01 15:08:48.952: E/AndroidRuntime(3816): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
01-01 15:08:48.952: E/AndroidRuntime(3816): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.ma.firebaseanalyticstest-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
01-01 15:08:48.952: E/AndroidRuntime(3816): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
01-01 15:08:48.952: E/AndroidRuntime(3816): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
01-01 15:08:48.952: E/AndroidRuntime(3816): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
01-01 15:08:48.952: E/AndroidRuntime(3816): at android.app.ActivityThread.installProvider(ActivityThread.java:5543)
01-01 15:08:48.952: E/AndroidRuntime(3816): ... 11 more
01-01 15:08:48.952: E/AndroidRuntime(3816): Suppressed: java.lang.ClassNotFoundException: com.google.firebase.provider.FirebaseInitProvider
01-01 15:08:48.952: E/AndroidRuntime(3816): at java.lang.Class.classForName(Native Method)
01-01 15:08:48.952: E/AndroidRuntime(3816): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
01-01 15:08:48.952: E/AndroidRuntime(3816): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
01-01 15:08:48.952: E/AndroidRuntime(3816): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
01-01 15:08:48.952: E/AndroidRuntime(3816): ... 13 more
01-01 15:08:48.952: E/AndroidRuntime(3816): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
01-01 15:08:48.952: V/ApplicationPolicy(796): isApplicationStateBlocked userId 0 pkgname com.ma.firebaseanalyticstest
I would encourage you to go back and install the Subversive plugin and connectors (SVNKit) from Polarion website (see Latest Stable Build) and start clean again. https://polarion.plm.automation.siemens.com/products/svn/subversive/download
DeleteNot quite sure what is going on there, the class seems to be missing from the exported application (ClassNotFoundException) whether because it was never exported or it was removed (Proguard?) or a multidex?
Analyze your APK with tools like dex2jar (GitHub), use the aforementioned ClassFinder to look for com.google.firebase.provider.FirebaseInitProvider into your manually prepared workspace if it exists (again, underlining the need for installing Suvbversive conectors and starting fresh again).
Send me an email to dan.dar33 at Gmail with your findings, we can arrange then a TeamViewer session towards the end of week sometime, I'm pretty sure we can sort it out.