我已经将android项目转换为aar之类的库,然后将其添加为Xamarin绑定库(Android)中的jar。构建该解决方案并获取dll文件,并在相同位置添加Android App(Xamarin)作为参考并进行构建。 当我运行它时,显示下面的错误,
Process: com.companyname.TestApp1, PID: 17644
06-25 08:30:38.946 E/AndroidRuntime(17644): java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/jvm/internal/Lambda;
06-25 08:30:38.946 E/AndroidRuntime(17644): at java.lang.Class.classForName(Native Method)
06-25 08:30:38.946 E/AndroidRuntime(17644): at java.lang.Class.forName(Class.java:453)
06-25 08:30:38.946 E/AndroidRuntime(17644): at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
06-25 08:30:38.946 E/AndroidRuntime(17644): at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:30)
06-25 08:30:38.946 E/AndroidRuntime(17644): at android.view.View.performClick(View.java:7339)
06-25 08:30:38.946 E/AndroidRuntime(17644): at android.widget.TextView.performClick(TextView.java:14222)
06-25 08:30:38.946 E/AndroidRuntime(17644): at android.view.View.performClickInternal(View.java:7305)
06-25 08:30:38.946 E/AndroidRuntime(17644): at android.view.View.access$3200(View.java:846)
06-25 08:30:38.946 E/AndroidRuntime(17644): at android.view.View$PerformClick.run(View.java:27787)
06-25 08:30:38.946 E/AndroidRuntime(17644): at android.os.Handler.handleCallback(Handler.java:873)
06-25 08:30:38.946 E/AndroidRuntime(17644): at android.os.Handler.dispatchMessage(Handler.java:99)
06-25 08:30:38.946 E/AndroidRuntime(17644): at android.os.Looper.loop(Looper.java:214)
06-25 08:30:38.946 E/AndroidRuntime(17644): at android.app.ActivityThread.main(ActivityThread.java:7073)
06-25 08:30:38.946 E/AndroidRuntime(17644): at java.lang.reflect.Method.invoke(Native Method)
06-25 08:30:38.946 E/AndroidRuntime(17644): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
06-25 08:30:38.946 E/AndroidRuntime(17644): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
06-25 08:30:38.946 E/AndroidRuntime(17644): Caused by: java.lang.ClassNotFoundException: Didn't find class "kotlin.jvm.internal.Lambda" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.companyname.TestApp1-5PPAd0T1XIo7m0pRoutt5w==/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.TestApp1-5PPAd0T1XIo7m0pRoutt5w==/lib/arm, /data/app/com.companyname.TestApp1-5PPAd0T1XIo7m0pRoutt5w==/base.apk!/lib/armeabi-v7a, /system/lib]]
06-25 08:30:38.946 E/AndroidRuntime(17644): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
06-25 08:30:38.946 E/AndroidRuntime(17644): at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
06-25 08:30:38.946 E/AndroidRuntime(17644): at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
06-25 08:30:38.946 E/AndroidRuntime(17644): ... 16 more
Unhandled Exception:
注意:该android studio项目成功运行,但相同的代码aar文件在visual studio xamarin应用程序中不起作用。 请帮助我解决此问题。
答案 0 :(得分:0)
了解R8(proguard),pleae。不会受伤的。
如果使用Xamarin.Android,则将proguard文件添加到您的项目中(并且BuildAction = ProguardConfiguration):
## Kotlin wrapper
-keep class kotlin.jvm.internal.** { }
-keep class kotlin.jvm.internal.FunctionReference { }
-keep class kotlin.jvm.internal.Lambda { }
-keep class kotlin.jvm.functions.Function0 { }
-keep class kotlin.jvm.functions.Function1 { }
-keep class kotlin.jvm.functions.Function2 { }
-keep class kotlin.jvm.functions.* { }
## don't waring Kotlin
-dontwarn kotlin.jvm.internal.**
-dontwarn kotlin.jvm.functions.**
特别是使用较新的工具(D8,R8,aapt2等)
查看最近几天我绑定的库的最新样本: