无法获得提供者 - 很少在 kitkat 上崩溃

Unable to get provider - rarely crash on kitkat

一周内我在 GP 控制台中收到几次崩溃报告:

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.access00(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

此外,在我的项目中添加 Firebase 功能后,我开始收到关于 com.google.firebase.provider.FirebaseInitProvider.

的相同崩溃报告

根据报告,此错误发生在:

Android 4.4 98,7 %

Android 4.2 1,3 %

我已经尝试了所有这些ClassNotFoundException for a ContentProvider,但没有结果。

这真的是一个系统错误,每个开发人员都在处理它,还是我的错误?我真的很想停止烦人的用户。谢谢

您的案例看起来确实像 there in Android's Issue Tracker 中描述的错误。 当用户在 apk 更新后立即启动应用程序时,您会遇到问题。

评论中有解决方法可以帮助您防止此错误:

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());
        }
    }
}