Search code examples
androidandroid-contentproviderandroid-4.4-kitkat

Unable to get provider - rarely crash on kitkat


Few times in the week i receive crash report in GP console:

java.lang.RuntimeException: Unable to get provider mypackage.MyProvider: java.lang.ClassNotFoundException: Didn't find class "mypackage.MyProvider" on path: DexPathList[[zip file "/mnt/asec/mypackage-1/pkg.apk"],nativeLibraryDirectories=[/mnt/asec/mypackage-1/lib, /vendor/lib, /system/lib]]
    at android.app.ActivityThread.installProvider(ActivityThread.java:5018)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:4589)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4522)
    at android.app.ActivityThread.access$1500(ActivityThread.java:151)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1381)
    at android.os.Handler.dispatchMessage(Handler.java:110)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:5299)
    at java.lang.reflect.Method.invokeNative(Method.java)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
    at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: java.lang.ClassNotFoundException: Didn't find class "mypackage.MyProvider" on path: DexPathList[[zip file "/mnt/asec/mypackage-1/pkg.apk"],nativeLibraryDirectories=[/mnt/asec/mypackage-1/lib, /vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    at android.app.ActivityThread.installProvider(ActivityThread.java:5003)
    ... 12 more
    Suppressed: java.io.IOException: unable to open DEX file
        at dalvik.system.DexFile.openDexFileNative(DexFile.java)
        at dalvik.system.DexFile.openDexFile(DexFile.java:296)
        at dalvik.system.DexFile.<init>(DexFile.java:80)
        at dalvik.system.DexFile.<init>(DexFile.java:59)
        at dalvik.system.DexPathList.loadDexFile(DexPathList.java:263)
        at dalvik.system.DexPathList.makeDexElements(DexPathList.java:230)
        at dalvik.system.DexPathList.<init>(DexPathList.java:112)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:48)
        at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:65)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:57)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:326)
        at android.app.LoadedApk.makeApplication(LoadedApk.java:508)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4514)
        ... 10 more

Also, after adding Firebase features to my project i start to receive same crash reports about com.google.firebase.provider.FirebaseInitProvider.

According to reports, this errors happens only on:

Android 4.4 98,7 %

Android 4.2 1,3 %

I've try all this ClassNotFoundException for a ContentProvider, but no result.

Is this really a system bug and every developer deals with it, or it's my error? I really want to stop annoying users. Thanks.


Solution

  • Your case really looks like bug described there in Android's Issue Tracker. There you got issue when user starting app immediately after apk update.

    There is workaround from comments which could help you to prevent this bug:

    public class DevToolsApplication extends Application {
    private static final String TAG = "DevToolsApplication";
    
        @Override
        public void onCreate() {
            super.onCreate();
            AppLogger.i(TAG, "app start...");
            checkAppReplacingState();
        }
    
        private void checkAppReplacingState() {
            if (getResources() == null) {
                AppLogger.w(TAG, "app is replacing...kill");
                Process.killProcess(Process.myPid());
            }
        }
    }