urbanairship / android-library

Urban Airship Android SDK
Other
112 stars 123 forks source link

com.urbanairship.analytics.EventService: java.lang.ClassNotFoundException #81

Closed uzairaslam1993 closed 6 years ago

uzairaslam1993 commented 6 years ago

I am getting this crash on fabric. Seems to be related to Event service. I have registered the event service class in the manifest as follows.

    <!-- Required for analytics -->
    <service
        android:name="com.urbanairship.analytics.EventService"
        android:label="Event Service" />

UA version : implementation ('com.urbanairship.android:urbanairship-sdk:9.0.4')

Fatal Exception: java.lang.RuntimeException: Unable to instantiate service com.urbanairship.analytics.EventService: java.lang.ClassNotFoundException: Didn't find class "com.urbanairship.analytics.EventService" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.olx.pk-2/base.apk"],nativeLibraryDirectories=[/data/app/com.olx.pk-2/lib/arm64, /data/app/com.olx.pk-2/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]] at android.app.ActivityThread.handleCreateService(ActivityThread.java:3449) at android.app.ActivityThread.-wrap6(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1721) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6682) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

rlepinski commented 6 years ago

The event service no longer exists. You should remove all Urban Airship manifest entries and allow the manifest merger to keep it up to date.

tszpinda commented 6 years ago

Hey, we're getting the same issue but with:

com.urbanairship.android:urbanairship-gcm:9.2.0

stacktrace:

Fatal Exception: java.lang.RuntimeException: Unable to instantiate service 
com.urbanairship.analytics.EventService: java.lang.ClassNotFoundException: 
Didn't find class "com.urbanairship.analytics.EventService" 
on path: DexPathList[[zip file "/data/app/company.android-Jluq5ELoynpCP_dXbPNxKg==/base.apk"],
nativeLibraryDirectories=[/data/app/company.android-Jluq5ELoynpCP_dXbPNxKg==/lib/arm64, 
/data/app/company.android-Jluq5ELoynpCP_dXbPNxKg==/base.apk!/lib/arm64-v8a,
/system/lib64, /vendor/lib64, /product/lib64]]
       at android.app.ActivityThread.handleCreateService(ActivityThread.java:3786)
       at android.app.ActivityThread.-wrap5(Unknown Source)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1994)

it only seems to be happening Android 8 and huawei devices, at least that's what Fabric says. We use manifest merger and don't have urbanairship service entry in our manifest.

any ideas please?

rlepinski commented 6 years ago

If you are using 9.2.0 then the service com.urbanairship.analytics.EventService does not exist. Double check your dependencies.

tszpinda commented 6 years ago

Double checked, the only urbanairship dependancies we have are these two:

com.urbanairship.android:urbanairship-core:9.2.0
com.urbanairship.android:urbanairship-gcm:9.2.0
rlepinski commented 6 years ago

Is this a recent update? We removed the service back in 7.2.0.

tszpinda commented 6 years ago

We just released new version of our app where UA was upgraded from 7.2.4 to 9.2.0. this issue has similar bits: https://github.com/firebase/firebase-jobdispatcher-android/issues/122

rlepinski commented 6 years ago

So I was wrong on the version, it was removed in 7.3.0 - https://github.com/urbanairship/android-library/commit/5f55e5490d2380f0d5fbc209317511e2423a4523#diff-ef3ffea5c865bcecd34b64ad52617f5d

We use to schedule alarms for event uploads. My guess is that huawei is not cancelling alarms on upgrade, so those alarms are still active and fire even though the component is no longer available on the app. I bet this issue will go away in time as new user update.

The only thing I can think of to potentially minimize the amount of errors would be to cancel the old alarms/pending intents on update:

public class UpdateReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Intent eventServiceIntent = new Intent()
                .setClassName(context.getPackageName(), "com.urbanairship.analytics.EventService");

        PendingIntent pendingIntent = PendingIntent.getService(context, 0, eventServiceIntent, PendingIntent.FLAG_NO_CREATE);
        if (pendingIntent != null) {
            AlarmManager alarmManager = (AlarmManager) context
                    .getSystemService(Context.ALARM_SERVICE);

            alarmManager.cancel(pendingIntent);
            pendingIntent.cancel();
        }
    }
}

For the manifest entry:

<receiver android:name=".UpdateReceiver" >
    <intent-filter >
        <action   android:name="android.intent.action.MY_PACKAGE_REPLACED" />
    </intent-filter>
</receiver>