我们的Xamarin.Forms项目已经扩展到包含方法计数> = 64k的库,因此我们必须启用MultiDex。 自启用它以来,droid构建在部署到我的android模拟器后立即崩溃。
我搜索了网络,我找到的唯一解决方案是卸载设备上的所有xamarin.android和单一运行时,我已经完成了。这并没有解决它。
我的设备日志在应用崩溃后显示以下错误:
01-10 08:38:44.593 5" KitKat (4.4) XXHDPI Phone Error 1966 memtrack Couldn't load memtrack module (No such file or directory)
01-10 08:38:44.593 5" KitKat (4.4) XXHDPI Phone Error 1966 android.os.Debug failed to load memtrack module: -2
01-10 08:38:44.565 5" KitKat (4.4) XXHDPI Phone Error 1966 cutils-trace Error opening trace file: No such file or directory (2)
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime at android.app.ActivityThread.main(ActivityThread.java:5001)
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime Caused by: java.lang.ClassNotFoundException: Didn't find class "md5ca27074e405277e6c40e6a6588077a84.MainApplication" on path: DexPathList[[zip file "/data/app/com.cii.patrollive-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.cii.patrollive-1, /system/lib]]
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime at android.os.Looper.loop(Looper.java:136)
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime ... 11 more
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime at android.app.ActivityThread.access$1500(ActivityThread.java:135)
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime at android.app.LoadedApk.makeApplication(LoadedApk.java:507)
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime at java.lang.reflect.Method.invoke(Method.java:515)
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime at android.os.Handler.dispatchMessage(Handler.java:102)
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime at android.app.Instrumentation.newApplication(Instrumentation.java:975)
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime Process: com.cii.patrollive, PID: 1948
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4301)
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime java.lang.RuntimeException: Unable to instantiate application md5ca27074e405277e6c40e6a6588077a84.MainApplication: java.lang.ClassNotFoundException: Didn't find class "md5ca27074e405277e6c40e6a6588077a84.MainApplication" on path: DexPathList[[zip file "/data/app/com.cii.patrollive-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.cii.patrollive-1, /system/lib]]
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime at java.lang.reflect.Method.invokeNative(Native Method)
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime FATAL EXCEPTION: main
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime at dalvik.system.NativeStart.main(Native Method)
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime at android.app.LoadedApk.makeApplication(LoadedApk.java:502)
01-10 08:38:39.201 5" KitKat (4.4) XXHDPI Phone Error 1948 AndroidRuntime at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
01-10 08:38:38.917 5" KitKat (4.4) XXHDPI Phone Error 1938 memtrack Couldn't load memtrack module (No such file or directory)
01-10 08:38:38.917 5" KitKat (4.4) XXHDPI Phone Error 1938 android.os.Debug failed to load memtrack module: -2
01-10 08:38:38.845 5" KitKat (4.4) XXHDPI Phone Error 1938 cutils-trace Error opening trace file: No such file or directory (2)
01-10 08:38:38.541 5" KitKat (4.4) XXHDPI Phone Error 1926 cutils-trace Error opening trace file: No such file or directory (2)
01-10 08:38:38.469 5" KitKat (4.4) XXHDPI Phone Error 1926 memtrack Couldn't load memtrack module (No such file or directory)
01-10 08:38:38.469 5" KitKat (4.4) XXHDPI Phone Error 1926 android.os.Debug failed to load memtrack module: -2
01-10 08:38:34.757 5" KitKat (4.4) XXHDPI Phone Error 1896 android.os.Debug failed to load memtrack module: -2
01-10 08:38:34.757 5" KitKat (4.4) XXHDPI Phone Error 1896 memtrack Couldn't load memtrack module (No such file or directory)
01-10 08:38:34.729 5" KitKat (4.4) XXHDPI Phone Error 1896 cutils-trace Error opening trace file: No such file or directory (2)
01-10 08:38:34.445 5" KitKat (4.4) XXHDPI Phone Error 1880 android.os.Debug failed to load memtrack module: -2
01-10 08:38:34.445 5" KitKat (4.4) XXHDPI Phone Error 1880 memtrack Couldn't load memtrack module (No such file or directory)
01-10 08:38:34.421 5" KitKat (4.4) XXHDPI Phone Error 1880 cutils-trace Error opening trace file: No such file or directory (2)
01-10 08:38:34.145 5" KitKat (4.4) XXHDPI Phone Error 1866 android.os.Debug failed to load memtrack module: -2
01-10 08:38:34.145 5" KitKat (4.4) XXHDPI Phone Error 1866 memtrack Couldn't load memtrack module (No such file or directory)
01-10 08:38:34.113 5" KitKat (4.4) XXHDPI Phone Error 1866 cutils-trace Error opening trace file: No such file or directory (2)
答案 0 :(得分:1)
您的应用程序崩溃的原因可能是双重的:
MainApplication
没有ACW名称,因此会为您生成一个。Android Callable Wrappers将基于正在导出类型的程序集限定名称的MD5SUM。
在您发布的示例中,我们看到md5ca27074e405277e6c40e6a6588077a84.MainApplication
。因此,当我们在MainApplication
上查找dexlist
时,我们希望得到确切的名称。因此,将名称更改为更合理的名称(如包名称)有助于此处。
MainApplication
类未放在主classes.dex
列表中,因此在启动时,它会尝试查找该类但无法找到它,因为它位于辅助classes2.dex
中文件。在.dex
初始化之前,不会加载辅助Multidex
文件。您可以在此处阅读有关Multidex的更多信息:http://www.jon-douglas.com/2016/09/05/xamarin-android-multidex/
http://www.jon-douglas.com/2016/09/23/xamarin-android-multidex-keep/
答案 1 :(得分:0)
我发现了一个解决方案。 在droid项目的MainActivity上指定Name属性解决了这个问题。 (我之前没有指定名字)。 (还需要清洁和重建)
我不知道为什么你需要在添加MultiDex选项后指定活动名称,我猜这是一个Xamarin错误。
[Activity( ... , Name= "com.cii.patrolliveapp", ... ]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
...
}
编辑: 在另一个答案中,Jon还向我指出了第二个问题。这是Windows上的android sdk上的第一个dex类列表为空的错误。
修复方法是打开android-sdk\build-tools\<version>\mainDexClasses.bat
文件(版本是您安装的最高版本,这是默认版本)并更改:
if DEFINED output goto redirect
call "%java_exe%" -Djava.ext.dirs="%frameworkdir%" com.android.multidex.MainDexListBuilder "%disableKeepAnnotated%" "%tmpJar%" "%params%"
goto afterClassReferenceListBuilder
:redirect
call "%java_exe%" -Djava.ext.dirs="%frameworkdir%" com.android.multidex.MainDexListBuilder "%disableKeepAnnotated%" "%tmpJar%" "%params%" 1>"%output%"
:afterClassReferenceListBuilder
到此:
SET params=%params:'=%
if DEFINED output goto redirect
call "%java_exe%" -Djava.ext.dirs="%frameworkdir%" com.android.multidex.MainDexListBuilder %disableKeepAnnotated% "%tmpJar%" %params%
goto afterClassReferenceListBuilder
:redirect
call "%java_exe%" -Djava.ext.dirs="%frameworkdir%" com.android.multidex.MainDexListBuilder %disableKeepAnnotated% "%tmpJar%" %params% 1>"%output%"
:afterClassReferenceListBuilder