Android app crashes instantly with “Didn't find class {hash}.MainApplication” [duplicate]

余生颓废 提交于 2019-12-12 19:29:21

问题


I've upgraded my Windows to 10.0.16299 (latest) and my Visual Studio to 15.5.1 (latest). Since then, when I build and run my Android app built in my Xamarin the app crashes instantly.

Unfortunately, [AppName] has stopped.

The issue appears no matter whether I want to run the app on an emulator or a connected real device. The output window shows this error message:

FATAL EXCEPTION: main
Process: [AppName], PID: 16778
java.lang.RuntimeException: Unable to instantiate application md53c5f17a815ca1a4a699c7162c91a7059.MainApplication: java.lang.ClassNotFoundException: Didn't find class "md53c5f17a815ca1a4a699c7162c91a7059.MainApplication" on path: DexPathList[[zip file "/data/app/nz.HUMANiT.Frank-1/base.apk"],nativeLibraryDirectories=[/data/app/nz.HUMANiT.Frank-1/lib/arm64, /data/app/[AppName]-1/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]
    at android.app.LoadedApk.makeApplication(LoadedApk.java:587)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4932)
    at android.app.ActivityThread.-wrap1(ActivityThread.java)
    ...
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

Caused by: java.lang.ClassNotFoundException: Didn't find class "md53c5f17a815ca1a4a699c7162c91a7059.MainApplication" on path: DexPathList[[zip file "/data/app/[AppName]-1/base.apk"],nativeLibraryDirectories=[/data/app/[AppName]-1/lib/arm64, /data/app/[AppName]-1/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    ...

Suppressed: java.lang.ClassNotFoundException: md53c5f17a815ca1a4a699c7162c91a7059.MainApplication
    at java.lang.Class.classForName(Native Method)
    at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
    ...

Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

I found hints that there were bugs in Xamarin in the past; however, the explained solutions and fixes don't work. Enabling or disabling multidex doesn't solve the issue either.

Is this a new bug in Xamarin? Any idea? Any advice?


回答1:


Had the same problem.

It looks like a Xamarin bug : the android package names are wrong in the generated AndroidManifest (not the same as those in the generated java classes).

Workaround : specify a package name for your android activities (and Application class if any) with the "Name" attribute.

If your activity was :

[Activity(Label = "App1", Icon = "@drawable/icon", Theme = "@style/MainTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, LaunchMode = LaunchMode.SingleTask)]
public class MainActivity : FormsAppCompatActivity {
...
}

Change it to :

[Activity(Name = "apackagename.MainActivity", Label = "App1", Icon = "@drawable/icon", Theme = "@style/MainTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, LaunchMode = LaunchMode.SingleTask)]
public class MainActivity : FormsAppCompatActivity {
...
}

This should solve the problem.



来源:https://stackoverflow.com/questions/47732293/android-app-crashes-instantly-with-didnt-find-class-hash-mainapplication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!