Xamarin.Android 链接器问题
Xamarin.Android Linker issue
我有一个以前在发布模式下工作的旧 Xamarin Androd 项目。现在,大约 8-9 个月后,出现了一些变化,所以我做了它们并检查了在调试模式下运行良好的应用程序。但是当我尝试 运行 它释放模式时,应用程序崩溃了。以下是崩溃发生时 android 监视器的错误日志。
10-22 15:51:12.796: E/AndroidRuntime(16511): android.runtime.JavaProxyThrowable: Cirrious.CrossCore.Exceptions.MvxIoCResolveException: Failed to construct LocalCacheService ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: libsqlite3_xamarin assembly:<unknown assembly> type:<unknown type> member:(null)
10-22 15:51:12.796: E/AndroidRuntime(16511): at (wrapper managed-to-native) SQLite.Net.Platform.XamarinAndroid.SQLiteApiAndroidNInternal.sqlite3_config(SQLite.Net.Interop.ConfigOption)
10-22 15:51:12.796: E/AndroidRuntime(16511): at SQLite.Net.Platform.XamarinAndroid.SQLiteApiAndroidN.Config (SQLite.Net.Interop.ConfigOption option) [0x00000] in <360d65bfaa3e44c0b2b5840d827a452d>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at CygMobile.Droid.Helpers.SQLiteConnectionFactory.Create (System.String database) [0x00029] in <f456e9b7efc54b949a703cf133b30114>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at CygMobile.Core.Services.LocalCacheService..ctor (CygMobile.Core.Interfaces.ISQLiteConnectionFactory factory) [0x00012] in <19ac0b1a45404947b9cc363b69761b6e>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at (wrapper managed-to-native) System.Reflection.RuntimeConstructorInfo.InternalInvoke(System.Reflection.RuntimeConstructorInfo,object,object[],System.Exception&)
10-22 15:51:12.796: E/AndroidRuntime(16511): at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x00005] in <b3da7d1603ac4e70afba2b0463d79a7b>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): --- End of inner exception stack trace ---
10-22 15:51:12.796: E/AndroidRuntime(16511): at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x0001d] in <b3da7d1603ac4e70afba2b0463d79a7b>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at System.Reflection.RuntimeConstructorInfo.DoInvoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00086] in <b3da7d1603ac4e70afba2b0463d79a7b>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at System.Reflection.RuntimeConstructorInfo.Invoke (System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <b3da7d1603ac4e70afba2b0463d79a7b>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in <b3da7d1603ac4e70afba2b0463d79a7b>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x0003a] in <cec644c19aec488eb4600e7788c2008f>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): --- End of inner exception stack trace ---
10-22 15:51:12.796: E/AndroidRuntime(16511): at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x0005b] in <cec644c19aec488eb4600e7788c2008f>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at Cirrious.CrossCore.Mvx.IocConstruct[T] () [0x00005] in <cec644c19aec488eb4600e7788c2008f>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at Cirrious.CrossCore.Mvx.ConstructAndRegisterSingleton[TInterface,TType] () [0x00005] in <cec644c19aec488eb4600e7788c2008f>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at CygMobile.Droid.MiniSetup.InitializeServices (Android.Content.Context applicationContext) [0x0000f] in <f456e9b7efc54b949a703cf133b30114>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at CygMobile.Droid.MiniSetup.EnsureInit (Android.Content.Context applicationContext) [0x00057] in <f456e9b7efc54b949a703cf133b30114>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at CygMobile.Droid.SplashActivity.Startup () [0x00000] in <f456e9b7efc54b949a703cf133b30114>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at CygMobile.Droid.SplashActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00017] in <f456e9b7efc54b949a703cf133b30114>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <d0ba74ae6dd346ba93d5085dca229dd8>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.3(intptr,intptr,intptr)
10-22 15:51:12.796: E/AndroidRuntime(16511): at md508c3e82ce365ea781ae67f1d3460864c.SplashActivity.n_onCreate(Native Method)
10-22 15:51:12.796: E/AndroidRuntime(16511): at md508c3e82ce365ea781ae67f1d3460864c.SplashActivity.onCreate(SplashActivity.java:31)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.Activity.performCreate(Activity.java:7327)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.Activity.performCreate(Activity.java:7318)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3094)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.os.Handler.dispatchMessage(Handler.java:106)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.os.Looper.loop(Looper.java:214)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.ActivityThread.main(ActivityThread.java:7050)
10-22 15:51:12.796: E/AndroidRuntime(16511): at java.lang.reflect.Method.invoke(Native Method)
10-22 15:51:12.796: E/AndroidRuntime(16511): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
10-22 15:51:12.796: E/AndroidRuntime(16511): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
经过一番研究,我发现链接器存在一些问题。当前 selection 仅是 Link SDK 程序集。这会使应用程序崩溃。
如果我 select Link None 那么应用程序工作正常。
我已经尝试过 https://docs.microsoft.com/en-us/xamarin/android/deploy-test/linker and https://docs.microsoft.com/en-us/xamarin/cross-platform/deploy-test/linker.Those 中的东西,但没有用。
仍然,如果有人可以帮助解决这个问题,那将是帮助满满的。
谢谢
看起来 proguard 正在删除一些与 SQLite 相关的符号。您可以通过访问 您项目的属性 -> Android 选项让混淆器跳过这些库 -> 跳过链接程序集 -> 将值设置为
SQLite-net;SQLitePCLRaw.batteries_green;SQLitePCLRaw.batteries_v2;SQLitePCLRaw.core;SQLitePCLRaw.provider.sqlite3
通过将 Mono.Data.Sqlite 添加到 Skip Linikingassemblies 来解决。
感谢@Saranga Athukorale 帮助我们朝着那个方向前进。
显然,当您使用 neww Visualstudio 构建应用程序时,访问该 dll 时出现问题。
我有一个以前在发布模式下工作的旧 Xamarin Androd 项目。现在,大约 8-9 个月后,出现了一些变化,所以我做了它们并检查了在调试模式下运行良好的应用程序。但是当我尝试 运行 它释放模式时,应用程序崩溃了。以下是崩溃发生时 android 监视器的错误日志。
10-22 15:51:12.796: E/AndroidRuntime(16511): android.runtime.JavaProxyThrowable: Cirrious.CrossCore.Exceptions.MvxIoCResolveException: Failed to construct LocalCacheService ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: libsqlite3_xamarin assembly:<unknown assembly> type:<unknown type> member:(null)
10-22 15:51:12.796: E/AndroidRuntime(16511): at (wrapper managed-to-native) SQLite.Net.Platform.XamarinAndroid.SQLiteApiAndroidNInternal.sqlite3_config(SQLite.Net.Interop.ConfigOption)
10-22 15:51:12.796: E/AndroidRuntime(16511): at SQLite.Net.Platform.XamarinAndroid.SQLiteApiAndroidN.Config (SQLite.Net.Interop.ConfigOption option) [0x00000] in <360d65bfaa3e44c0b2b5840d827a452d>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at CygMobile.Droid.Helpers.SQLiteConnectionFactory.Create (System.String database) [0x00029] in <f456e9b7efc54b949a703cf133b30114>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at CygMobile.Core.Services.LocalCacheService..ctor (CygMobile.Core.Interfaces.ISQLiteConnectionFactory factory) [0x00012] in <19ac0b1a45404947b9cc363b69761b6e>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at (wrapper managed-to-native) System.Reflection.RuntimeConstructorInfo.InternalInvoke(System.Reflection.RuntimeConstructorInfo,object,object[],System.Exception&)
10-22 15:51:12.796: E/AndroidRuntime(16511): at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x00005] in <b3da7d1603ac4e70afba2b0463d79a7b>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): --- End of inner exception stack trace ---
10-22 15:51:12.796: E/AndroidRuntime(16511): at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x0001d] in <b3da7d1603ac4e70afba2b0463d79a7b>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at System.Reflection.RuntimeConstructorInfo.DoInvoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00086] in <b3da7d1603ac4e70afba2b0463d79a7b>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at System.Reflection.RuntimeConstructorInfo.Invoke (System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <b3da7d1603ac4e70afba2b0463d79a7b>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in <b3da7d1603ac4e70afba2b0463d79a7b>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x0003a] in <cec644c19aec488eb4600e7788c2008f>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): --- End of inner exception stack trace ---
10-22 15:51:12.796: E/AndroidRuntime(16511): at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x0005b] in <cec644c19aec488eb4600e7788c2008f>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at Cirrious.CrossCore.Mvx.IocConstruct[T] () [0x00005] in <cec644c19aec488eb4600e7788c2008f>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at Cirrious.CrossCore.Mvx.ConstructAndRegisterSingleton[TInterface,TType] () [0x00005] in <cec644c19aec488eb4600e7788c2008f>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at CygMobile.Droid.MiniSetup.InitializeServices (Android.Content.Context applicationContext) [0x0000f] in <f456e9b7efc54b949a703cf133b30114>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at CygMobile.Droid.MiniSetup.EnsureInit (Android.Content.Context applicationContext) [0x00057] in <f456e9b7efc54b949a703cf133b30114>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at CygMobile.Droid.SplashActivity.Startup () [0x00000] in <f456e9b7efc54b949a703cf133b30114>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at CygMobile.Droid.SplashActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00017] in <f456e9b7efc54b949a703cf133b30114>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <d0ba74ae6dd346ba93d5085dca229dd8>:0
10-22 15:51:12.796: E/AndroidRuntime(16511): at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.3(intptr,intptr,intptr)
10-22 15:51:12.796: E/AndroidRuntime(16511): at md508c3e82ce365ea781ae67f1d3460864c.SplashActivity.n_onCreate(Native Method)
10-22 15:51:12.796: E/AndroidRuntime(16511): at md508c3e82ce365ea781ae67f1d3460864c.SplashActivity.onCreate(SplashActivity.java:31)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.Activity.performCreate(Activity.java:7327)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.Activity.performCreate(Activity.java:7318)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3094)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.os.Handler.dispatchMessage(Handler.java:106)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.os.Looper.loop(Looper.java:214)
10-22 15:51:12.796: E/AndroidRuntime(16511): at android.app.ActivityThread.main(ActivityThread.java:7050)
10-22 15:51:12.796: E/AndroidRuntime(16511): at java.lang.reflect.Method.invoke(Native Method)
10-22 15:51:12.796: E/AndroidRuntime(16511): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
10-22 15:51:12.796: E/AndroidRuntime(16511): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
经过一番研究,我发现链接器存在一些问题。当前 selection 仅是 Link SDK 程序集。这会使应用程序崩溃。 如果我 select Link None 那么应用程序工作正常。
我已经尝试过 https://docs.microsoft.com/en-us/xamarin/android/deploy-test/linker and https://docs.microsoft.com/en-us/xamarin/cross-platform/deploy-test/linker.Those 中的东西,但没有用。
仍然,如果有人可以帮助解决这个问题,那将是帮助满满的。 谢谢
看起来 proguard 正在删除一些与 SQLite 相关的符号。您可以通过访问 您项目的属性 -> Android 选项让混淆器跳过这些库 -> 跳过链接程序集 -> 将值设置为
SQLite-net;SQLitePCLRaw.batteries_green;SQLitePCLRaw.batteries_v2;SQLitePCLRaw.core;SQLitePCLRaw.provider.sqlite3
通过将 Mono.Data.Sqlite 添加到 Skip Linikingassemblies 来解决。 感谢@Saranga Athukorale 帮助我们朝着那个方向前进。
显然,当您使用 neww Visualstudio 构建应用程序时,访问该 dll 时出现问题。