Google Play Service FATAL ERROR - android

In my project I use GCM for push notification from server.
I foollow instruction https://developers.google.com/android/guides/setup to add Google Play Service in my project.
And everything work fine on my device (Galaxy NOTE S3), but when I start testing on another emulators (include genymotion) I got FATAL ERROR:
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gms.R$string
at com.google.android.gms.measurement.zza.<init>(Unknown Source)
at com.google.android.gms.measurement.zza.zzaR(Unknown Source)
at com.google.android.gms.measurement.internal.zzn.zziJ(Unknown Source)
at com.google.android.gms.measurement.internal.zzz.zza(Unknown Source)
at com.google.android.gms.measurement.internal.zzw.<init>(Unknown Source)
at com.google.android.gms.measurement.internal.zzaa.zzDj(Unknown Source)
at com.google.android.gms.measurement.internal.zzw.zzaT(Unknown Source)
at com.google.android.gms.measurement.AppMeasurementContentProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1058)
at android.app.ActivityThread.installProvider(ActivityThread.java:4560)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4190)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4132)
at android.app.ActivityThread.access$1300(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
I check availability by method:
public static boolean checkPlayServices(Activity activity) {
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(activity);
if (resultCode != ConnectionResult.SUCCESS) {
if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(activity, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
.show();
}
return false;
}
return true;
}
And call this method in onResume of MainActitvity.class:
#Override
protected void onResume() {
super.onResume();
if(SMSSenderHelper.checkPlayServices(this)){
startService(new Intent(this, RegistrationIntentService.class));
}else{
finish();
}
}
SOLUTION (in my case):
review your build.gradle
change Application class:
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}

This is some line of code you have to define in Manifest file if you want to use GCMListenerService:
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="training.com.chatgcmapplication" />
</intent-filter>
</receiver>
<service
android:name="training.com.services.MessageListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</service>

Did you see any Google related apps (Ex: Google Play Store, Gmail...) in your emulator? If not, your emulator does not include Google service, so the Exception will be occured. Try to install Gapps for your genymotion and try again.
Edit:
Have you added Google Play Services library like Google guidline?
Note from Google guidline (emulator 4.2.2 and above):
To test your app when using the Google Play services SDK, you must use
either:
A compatible Android device that runs Android 2.3 or higher and
includes Google Play Store.
The Android emulator with an AVD that runs
the Google APIs platform based on Android 4.2.2 or higher.

Related

AltBeacon issue after adding Parse server push notification

My application was working ok, but after i added the push notifications from parse server, i started getting an error when the app is launched (see message below), while the app open and work ok, when i close the app the same is not doing the background search and notification.
09-30 17:22:12.006 10338-10349/br.com.inconnet.inbeacon E/Parcel: Class not found when unmarshalling: org.altbeacon.beacon.service.StartRMData
java.lang.ClassNotFoundException: org.altbeacon.beacon.service.StartRMData
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:324)
at android.os.Parcel.readParcelableCreator(Parcel.java:2404)
at android.os.Parcel.readParcelable(Parcel.java:2358)
at android.os.Message.readFromParcel(Message.java:571)
at android.os.Message.-wrap0(Message.java)
at android.os.Message$1.createFromParcel(Message.java:527)
at android.os.Message$1.createFromParcel(Message.java:525)
at android.os.IMessenger$Stub.onTransact(IMessenger.java:51)
at android.os.Binder.execTransact(Binder.java:453)
Caused by: java.lang.ClassNotFoundException: org.altbeacon.beacon.service.StartRMData
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:469)
at java.lang.Class.classForName(Native Method) 
at java.lang.Class.forName(Class.java:324) 
at android.os.Parcel.readParcelableCreator(Parcel.java:2404) 
at android.os.Parcel.readParcelable(Parcel.java:2358) 
at android.os.Message.readFromParcel(Message.java:571) 
at android.os.Message.-wrap0(Message.java) 
at android.os.Message$1.createFromParcel(Message.java:527) 
at android.os.Message$1.createFromParcel(Message.java:525) 
at android.os.IMessenger$Stub.onTransact(IMessenger.java:51) 
at android.os.Binder.execTransact(Binder.java:453) 
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
if i remove the following information from my AndroidManifest.xml, the app works ok again.
<meta-data android:name="com.parse.push.gcm_sender_id"
android:value="id:xxxxxx" />
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.GcmBroadcastReceiver" 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="br.com.inconnet.inbeacon" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.ParsePushBroadcastReceiver" android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.OPEN" />
<action android:name="com.parse.push.intent.DELETE" />
</intent-filter>
</receiver>
How can i make both work thogeter?
A similar problem has been reported by folks who are bundling their apps with certain other services and the Android Beacon Library. There is no known fix or even a fully understood cause. You can read more about the issue here:
https://github.com/AltBeacon/android-beacon-library/issues/306
One theory is that bundling some services with your app somehow forces other services in the app to run in a separate process, something the Android Beacon Library does not support.
If you have proguard settings enabled, you may want to try disabling them to see if this makes the problem go away.

Google Play Services 7.5.0 AnalyticsService NPE onStartCommand

Has anyone run into this crash when loading Google Play 7.5.0 in their app? I'm seeing about 30 crashes a day now, without any way to reproduce. No particular Android flavour (4.4, 5, 5.1) or device (Samsung, HTC, etc..) is sticking out at me.
java.lang.RuntimeException: Unable to start service com.google.android.gms.analytics.AnalyticsService#1153b3b0 with null: java.lang.NullPointerException
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2721)
at android.app.ActivityThread.access$1900(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5116)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: java.lang.NullPointerException
at com.google.android.gms.analytics.AnalyticsService.onStartCommand()
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2704)
at android.app.ActivityThread.access$1900(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5116)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(NativeStart.java)
This issue has also been posted on the Analytics bug tracker, but I don't expect to see any movement there for a while: https://code.google.com/p/analytics-issues/issues/detail?id=667
Here is what is in my Gradle file:
compile 'com.google.android.gms:play-services:7.5.0'
And in my AndroidManifest (which I think is verbatim from the Google docs):
<receiver
android:name="com.google.android.gms.analytics.AnalyticsReceiver"
android:enabled="true" >
<intent-filter>
<action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
</intent-filter>
</receiver>
<service
android:name="com.google.android.gms.analytics.AnalyticsService"
android:enabled="true"
android:exported="false" />
Try with the latest Google play services SDK version. It has been fixed in Google Play services 9.2.1.

NotificationListenerService with RemoteController.OnClientUpdateListener crashes on API18 (4.3)

The Problem
I want to implement the new RemoteController API, which has been introduced with API19 (Kitkat,4.4). The API requires me to implement a class which extends from NotificationListenerService (introduced with API18) and implements the RemoteController.OnClientUpdateListener interface. (Further information on how to implement all this can be found here and a very helpful example project can be found here)
Everything's working as it should on my API19 (Kitkat,4.4) device and every other API<18 device. However the problem is, that the app crashes right away on API18 (Jelly bean, 4.3), because the "android.service.notification.NotificationListenerService" is being sent and starts my RemoteService, which then crashes the app instantly with the following Stacktrace:
05-24 09:32:48.945 893-893/com.example E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate service com.example.RemoteService: java.lang.ClassNotFoundException: Didn't find class "com.example.RemoteService" on path: DexPathList[[zip file "/data/app/com.example-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example-1, /system/lib]]
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2561)
at android.app.ActivityThread.access$1600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1338)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.RemoteService" on path: DexPathList[[zip file "/data/app/com.example-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example-1, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2558)
at android.app.ActivityThread.access$1600(ActivityThread.java:141
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1338)
...
This is caused by the simple fact, that RemoteController and therefore the implemented interface RemoteController.OnClientUpdateListener is not available on API18, but NotificationListenerService is. The intent is not being sent on every device
What I've tried so far
Put another layer of abstraction on it and build a simple "if (API>=19)" check.
I tried to do this by using a second empty NotificationListenerService which would just work as a kind of callthrough Service. I would put that second Service in my AndroidManifest, so that it receives the intent instead, and then I'd just put the "if (API>=19)" check in its onCreate and start my actual RemoteService from there. The result is, that my App doesn't crash any more (yay). Unfortunately it also doesn't work in API19 Kitkat any more :(. I think that's because I have to register my RemoteService as a listener in my AndroidManifest directly, or otherwise it won't receive anything.
Code snippets
RemoteService.java:
public class RemoteService extends NotificationListenerService
implements RemoteController.OnClientUpdateListener {
...
}
AndroidManifest.xml:
<manifest ...>
<application ...>
<service android:name="com.example.RemoteService"
android:label="#string/app_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
</application>
</manifest>
The solution
Put a bool in an xml file in values and values-v19. Set it to false in values and to true in values-v19. Now set the NotificationListenerService's "android:enabled" tag to this bool.
./values/bool_switches.xml:
<resources>
<bool name="remotecontrollerservice_enabled">false</bool>
</resources>
./values-v19/bool_switches.xml:
<resources>
<bool name="remotecontrollerservice_enabled">true</bool>
</resources>
./AndroidManifest.xml:
...
<service android:name=".services.RemoteControllerService"
android:label="#string/scrobblingservice_string"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
android:enabled="#bool/remotecontrollerservice_enabled">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService"/>
</intent-filter>
</service>
...
Just disable the service with android:enabled="false", then in Application.onCreate enable it if the device is running KitKat or newer.

Wrong API key for Xtify?

I get this error message:
Caused by: com.xtify.android.sdk.InvalidFormatException: Could not read the api key. No meta data found in the manifest file.
at com.xtify.android.sdk.PersistentLocationManager.a( Unknown Source)
at com.xtify.android.sdk.PersistentLocationManager.c( Unknown Source)
at com.xtify.android.sdk.PersistentLocationManager.a( Unknown Source)
at com.xtify.android.sdk.PersistentLocationManager.<i nit>(Unknown Source)
at com.nejo.android.xtify.nejoXTIFY.initialize(nejoXT IFY.java:27)
at Xtracard.Customer.xti._service_create(xti.java:102 )
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
... 13 more
This is in my manifest file:
<receiver android:name="com.nejo.android.xtify.NejoXtyreceiv er">
<intent-filter androidriority="9999">
<action android:name="com.xtify.android.sdk.SHOW_NOTIFICAT ION" />
<!-- KEEP THE FORWARD SLASH IN FRONT OF THE APP KEY ON THE LINE BELOW -->
<data android:scheme="notif" android:host="notification.xtify.com"
androidathPrefix="/a0ef3978-dcb9-424d-9b03-1567f5814817" />
</intent-filter>
</receiver>
The API key is correct. Xtifys support page throws an error when I ask them a question.
Any ideas?

Explanation for random ClassNotFoundExceptions?

I have an app with ~11k active installs for which I sometimes receive ClassNotFoundExceptions that I can't explain. They look like this:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{name.of.my.MainActivityClass}: java.lang.ClassNotFoundException: name.of.my.MainActivityClass in loader dalvik.system.PathClassLoader[/mnt/asec/name.of.my-2/pkg.apk]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1743)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1851)
at android.app.ActivityThread.access$1500(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: name.of.my.MainActivityClass in loader dalvik.system.PathClassLoader[/mnt/asec/name.of.my-2/pkg.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at android.app.Instrumentation.newActivity(Instrumentation.java:1040)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1735)
... 11 more
I received some of these exceptions from users that updated my app (not only for the most recent version), so I think it is not a problem that is specific to some phones as the app worked for them before.
I got these exception reports for my main activity class, a receiver class and a BackupAgent class.
All of those classes are always instantiated directly from Android. My Manifest file looks like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="name.of.my"
android:versionCode="20"
android:versionName="1.10.2"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8" />
<application android:icon="#drawable/icon" android:label="#string/app_name" android:backupAgent="name.of.my.OwnBackupAgent">
<activity android:name="name.of.my.MainActivityClass"
android:label="#string/app_name"
android:theme="#style/MyTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="name.of.my.OwnReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.media.RINGER_MODE_CHANGED" />
</intent-filter>
</receiver>
</application>
</manifest>
After searching the net for some hours, the most likely explanations I found are:
it might be related to moving the app to SD card while there are still some services running (but the android dev guide says that all services are canceled in this case, and it doesn't explain why my main activity class suddenly can't be found anymore)
the .apk might be corrupted after updating via the android market. Could this be true? If yes, what can I do against it - if not, what else might be the problem?

Categories

Resources