C# Xamarin Android中的自定义应用程序类
我必须创建扩展应用程序类的自定义类。我创建了类,添加了应用程序类的实例,创建了额外的构造函数,在类的顶部添加了应用程序属性。之后,当我在android设备上测试应用程序时,它立即崩溃。没有错误消息,只在输出控制台中显示: 输出控制台消息的一部分: [art]art/runtime/indirect_reference_table.cc:128]JNI错误(应用程序(_ZN3art8CheckJNI16CallObjectMethodEP7_JNIEnvP8_jobjectP10_jmethodIDz+160) [art]art/runtime/runtime.cc:404]本机:#13 pc 000000000000 A640 /data/app/pl.esticrm.MyApp-1/lib/arm64/libmonodroid.so (java_interop_jnienv_call_object_method+36)[art] art/runtime/runtime.cc:404]本机:#14 pc 00000000000b9e10(?) [art]art/runtime/runtime.cc:404]位于 md51e2b575927e2fc0f467b22123a11ceb7.MyAppCustomClass.n_onCreate(本机) 方法)[art]art/runtime/runtime.cc:404]at md51e2b575927e2fc0f467b22123a11ceb7.MyAppCustomClass.onCreate(MyAppCustomClass.java:25) [art]art/runtime/runtime.cc:404]位于 android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1032) …[libc]致命信号6 (SIGABRT),tid 16574中的代码-6(icrm.MyApp) Manifest.xmlC# Xamarin Android中的自定义应用程序类,c#,xamarin,xamarin.android,C#,Xamarin,Xamarin.android,我必须创建扩展应用程序类的自定义类。我创建了类,添加了应用程序类的实例,创建了额外的构造函数,在类的顶部添加了应用程序属性。之后,当我在android设备上测试应用程序时,它立即崩溃。没有错误消息,只在输出控制台中显示: 输出控制台消息的一部分: [art]art/runtime/indirect_reference_table.cc:128]JNI错误(应用程序(_ZN3art8CheckJNI16CallObjectMethodEP7_JNIEnvP8_jobjectP10_jmethodI
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="pl.app.MyApp">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application android:theme="@style/AppTheme" android:icon="@drawable/ic_launcher" android:label="MyApp" />
</manifest>
我只看了stackoverflow和xamarin论坛的问题,没有什么能解决我的问题。记得调用
base.OnCreate()
@Cheesebaron我添加了它,它没有改变任何东西,我还更新了帖子,使其更加精确。我正确地理解到,您正在创建应用程序类的实例,您的意思是您正在执行类似于new MyAppCustomClass()的操作
?当我用NativeActions和AndroidActions注释掉这两行时,它可以正常工作。因此我认为这两个包存在问题。请检查NativeActions和AndroidActions包的使用情况。我创建了一个简单的xamarin.android项目,并将您的代码添加到我的项目中(唯一的区别是我用NativeActions和AndroidActions注释掉了2行代码)。但是我没有得到你的JNI错误消息。顺便说一句,我将目标版本从28改为27。我建议你删除obj和bin文件夹,然后重建项目。记得调用base.OnCreate()
@Cheesebaron我添加了它,它没有改变任何东西,我还更新了帖子,使其更加精确。我正确地理解到,您正在创建应用程序类的实例,您的意思是您正在执行类似于new MyAppCustomClass()的操作
?当我用NativeActions和AndroidActions注释掉这两行时,它可以正常工作。因此我认为这两个包存在问题。请检查NativeActions和AndroidActions包的使用情况。我创建了一个简单的xamarin.android项目,并将您的代码添加到我的项目中(唯一的区别是我用NativeActions和AndroidActions注释掉了2行)。但是我没有得到你的JNI错误消息。顺便说一下,我将目标版本从28改为27。我建议你删除obj和bin文件夹,然后重建项目。
namespace MyApp.Droid.Applications
{
[Application(Debuggable = true, Theme = "@style/AppTheme", Icon = "@drawable/ic_launcher", Label = "MyApp")]
public class MyAppCustomClass : Application
{
public MyAppCustomClass()
{
}
protected MyAppCustomClass(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
}
public readonly string[] permissions = { Manifest.Permission.WriteExternalStorage, Manifest.Permission.ReadExternalStorage };
public NativeActions native = new NativeActions();
public AndroidActions actions = new AndroidActions();
public override void OnCreate()
{
base.OnCreate();
System.Console.WriteLine("Custom Class test");
}
}
}