在xamarin表单中进行深层链接时,找不到类的异常

时间:2018-02-08 08:29:13

标签: xamarin.forms classnotfoundexception deep-linking

我正在尝试为我的项目添加深层链接功能。

我在Androidmanifest.xml中的代码

    <?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="com.companyname.sample">
        <uses-sdk android:minSdkVersion="15" />
        <application android:label="sample.Android">
        <activity android:icon="@drawable/icon" android:name="sample.Droid.MainActivity" android:label="sample">
          <intent-filter>
            <data android:scheme="http" android:host="www.sample.com" android:pathPrefix="/code" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
          </intent-filter>
        </activity>
      </application>
    </manifest>

Mainactivity.cs

    using Android.App;
    using Android.Content.PM;
    using Android.OS;

    namespace sample.Droid
    {
        [Activity(Label = "sample", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
        public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
        {
            protected override void OnCreate(Bundle bundle)
            {
                TabLayoutResource = Resource.Layout.Tabbar;
                ToolbarResource = Resource.Layout.Toolbar;

                base.OnCreate(bundle);

                global::Xamarin.Forms.Forms.Init(this, bundle);
                LoadApplication(new App());
            }
        }
    }

以下是我使用 http://www.sample.com/code/hi

的示例网址

当我点击此网址时,我收到以下例外情况:

    02-08 13:16:25.168 E/AndroidRuntime(12130): FATAL EXCEPTION: main
    02-08 13:16:25.168 E/AndroidRuntime(12130): Process: com.companyname.sample, PID: 12130
    02-08 13:16:25.168 E/AndroidRuntime(12130): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.companyname.sample/sample.Droid.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "sample.Droid.MainActivity" on path: DexPathList[[zip file "/mnt/asec/com.companyname.sample-2/base.apk"],nativeLibraryDirectories=[/mnt/asec/com.companyname.sample-2/lib/arm, /vendor/lib, /system/lib]]
    02-08 13:16:25.168 E/AndroidRuntime(12130):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2236)
    02-08 13:16:25.168 E/AndroidRuntime(12130):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
    02-08 13:16:25.168 E/AndroidRuntime(12130):     at android.app.ActivityThread.access$800(ActivityThread.java:151)
    02-08 13:16:25.168 E/AndroidRuntime(12130):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
    02-08 13:16:25.168 E/AndroidRuntime(12130):     at android.os.Handler.dispatchMessage(Handler.java:102)
    02-08 13:16:25.168 E/AndroidRuntime(12130):     at android.os.Looper.loop(Looper.java:135)
    02-08 13:16:25.168 E/AndroidRuntime(12130):     at android.app.ActivityThread.main(ActivityThread.java:5254)
    02-08 13:16:25.168 E/AndroidRuntime(12130):     at java.lang.reflect.Method.invoke(Native Method)
    02-08 13:16:25.168 E/AndroidRuntime(12130):     at java.lang.reflect.Method.invoke(Method.java:372)
    02-08 13:16:25.168 E/AndroidRuntime(12130):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
    02-08 13:16:25.168 E/AndroidRuntime(12130):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)
    02-08 13:16:25.168 E/AndroidRuntime(12130): Caused by: java.lang.ClassNotFoundException: Didn't find class "sample.Droid.MainActivity" on path: DexPathList[[zip file "/mnt/asec/com.companyname.sample-2/base.apk"],nativeLibraryDirectories=[/mnt/asec/com.companyname.sample-2/lib/arm, /vendor/lib, /system/lib]]
    02-08 13:16:25.168 E/AndroidRuntime(12130):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    02-08 13:16:25.168 E/AndroidRuntime(12130):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    02-08 13:16:25.168 E/AndroidRuntime(12130):     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    02-08 13:16:25.168 E/AndroidRuntime(12130):     at android.app.Instrumentation.newActivity(Instrumentation.java:1066)
    02-08 13:16:25.168 E/AndroidRuntime(12130):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2226)
    02-08 13:16:25.168 E/AndroidRuntime(12130):     ... 10 more
    02-08 13:16:25.168 E/AndroidRuntime(12130):     Suppressed: java.lang.ClassNotFoundException: sample.Droid.MainActivity
    02-08 13:16:25.168 E/AndroidRuntime(12130):         at java.lang.Class.classForName(Native Method)
    02-08 13:16:25.168 E/AndroidRuntime(12130):         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
    02-08 13:16:25.168 E/AndroidRuntime(12130):         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
    02-08 13:16:25.168 E/AndroidRuntime(12130):         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
    02-08 13:16:25.168 E/AndroidRuntime(12130):         ... 13 more
    02-08 13:16:25.168 E/AndroidRuntime(12130):     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
    02-08 13:16:25.186 I/Process (12130): Sending signal. PID: 12130 SIG: 9

任何人,请帮我解决这个问题。已经失去了很多日子。

在Google云端硬盘中上传了一个示例项目,以下是其中的链接: https://drive.google.com/file/d/1aSuwb_SuCIdC1E_BCFBdi4y7NRP5275y/view?usp=sharing

提前致谢

1 个答案:

答案 0 :(得分:0)

在android清单中设置android:name如下:

  android:name=".MainActivity"

在Mainactivity中添加如下名称:

 [Activity(Name = "packagename.MainActivity")]