枚举字段上的 ActiveAndroid NoClassDefFoundError 异常
ActiveAndroid NoClassDefFoundError exception on enum field
它只在 Android 4.3 的 Galaxy Nexus 上发生过一次。
枚举字段的 Active Android 中是否存在一些已知问题?
Google 没有帮助,我什至不知道去哪里看。
我必须提到我有 multiDexEnabled=true,这可能就是 ActiveAndroid 在这个奇怪的地方搜索 class 的原因 (my_app_name-1.apk)
java.lang.NoClassDefFoundError: .../models/QuickAction$ActionType
at java.lang.Class.getDeclaredFields(Native Method)
at java.lang.Class.getDeclaredFields(Class.java:560)
at com.activeandroid.util.ReflectionUtils.getDeclaredColumnFields(ReflectionUtils.java:73)
at com.activeandroid.TableInfo.<init>(TableInfo.java:66)
at com.activeandroid.ModelInfo.loadModelFromMetaData(ModelInfo.java:101)
at com.activeandroid.ModelInfo.<init>(ModelInfo.java:61)
at com.activeandroid.Cache.initialize(Cache.java:66)
at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:44)
at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:34)
at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:30)
at com.activeandroid.app.Application.onCreate(Application.java:25)
at ...MyApplication.onCreate(MyApplication.java:12)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4444)
at android.app.ActivityThread.access00(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
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 "...models.QuickAction$ActionType" on path: DexPathList[[zip file "/data/app/...-1.apk"],nativeLibraryDirectories=[/data/app-lib/...-1, /vendor/lib, /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)
... 24 more
根据 MultiDex documentation,您需要从您的应用程序调用 MultiDex.install(this)
:
Patches the application context class loader by appending extra dex files loaded from the application apk.
您可以通过扩展 MultiDexApplication
class:
public class MyApplication extends MultiDexApplication { ... }
或者,如果您有自己的自定义应用程序 class,它已经扩展了其他内容,请直接调用 install
:
public class MyApplication extends SomeOtherApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
为什么我们只需要为 4.4 及以下版本执行此操作?如果我们 look at the docs again 我们可以看到 MultiDex 支持内置于 Android 5.0 (L) 及更高版本:
Android 5.0 (API level 21) and higher uses a runtime called ART which natively supports loading multiple DEX files from APK files.
事实上,如果我们进入 MultiDex 支持库,我们可以看到如果设备 VM 被认为是空操作 "multi dex capable":
public static void install(Context context) {
Log.i("MultiDex", "install");
if(IS_VM_MULTIDEX_CAPABLE) {
Log.i("MultiDex", "VM has multidex support, MultiDex support library is disabled.");
} else if(VERSION.SDK_INT < 4) {
throw new RuntimeException("Multi dex installation failed. SDK " + VERSION.SDK_INT + " is unsupported. Min SDK version is " + 4 + ".");
} else {
// Set up multidex
...
}
}
它只在 Android 4.3 的 Galaxy Nexus 上发生过一次。 枚举字段的 Active Android 中是否存在一些已知问题? Google 没有帮助,我什至不知道去哪里看。
我必须提到我有 multiDexEnabled=true,这可能就是 ActiveAndroid 在这个奇怪的地方搜索 class 的原因 (my_app_name-1.apk)
java.lang.NoClassDefFoundError: .../models/QuickAction$ActionType
at java.lang.Class.getDeclaredFields(Native Method)
at java.lang.Class.getDeclaredFields(Class.java:560)
at com.activeandroid.util.ReflectionUtils.getDeclaredColumnFields(ReflectionUtils.java:73)
at com.activeandroid.TableInfo.<init>(TableInfo.java:66)
at com.activeandroid.ModelInfo.loadModelFromMetaData(ModelInfo.java:101)
at com.activeandroid.ModelInfo.<init>(ModelInfo.java:61)
at com.activeandroid.Cache.initialize(Cache.java:66)
at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:44)
at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:34)
at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:30)
at com.activeandroid.app.Application.onCreate(Application.java:25)
at ...MyApplication.onCreate(MyApplication.java:12)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4444)
at android.app.ActivityThread.access00(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
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 "...models.QuickAction$ActionType" on path: DexPathList[[zip file "/data/app/...-1.apk"],nativeLibraryDirectories=[/data/app-lib/...-1, /vendor/lib, /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)
... 24 more
根据 MultiDex documentation,您需要从您的应用程序调用 MultiDex.install(this)
:
Patches the application context class loader by appending extra dex files loaded from the application apk.
您可以通过扩展 MultiDexApplication
class:
public class MyApplication extends MultiDexApplication { ... }
或者,如果您有自己的自定义应用程序 class,它已经扩展了其他内容,请直接调用 install
:
public class MyApplication extends SomeOtherApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
为什么我们只需要为 4.4 及以下版本执行此操作?如果我们 look at the docs again 我们可以看到 MultiDex 支持内置于 Android 5.0 (L) 及更高版本:
Android 5.0 (API level 21) and higher uses a runtime called ART which natively supports loading multiple DEX files from APK files.
事实上,如果我们进入 MultiDex 支持库,我们可以看到如果设备 VM 被认为是空操作 "multi dex capable":
public static void install(Context context) {
Log.i("MultiDex", "install");
if(IS_VM_MULTIDEX_CAPABLE) {
Log.i("MultiDex", "VM has multidex support, MultiDex support library is disabled.");
} else if(VERSION.SDK_INT < 4) {
throw new RuntimeException("Multi dex installation failed. SDK " + VERSION.SDK_INT + " is unsupported. Min SDK version is " + 4 + ".");
} else {
// Set up multidex
...
}
}