问题
I am trying to add deeplinking feature to my project.
My code in 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());
}
}
}
Here is the sample url I am using http://www.sample.com/code/hi
When I tap on this url I am getting the following Exception:
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
Anybody, please help me to solve this issue. Already lost a lot of days for this.
Uploaded a sample project in google drive and following is the link of that: https://drive.google.com/file/d/1aSuwb_SuCIdC1E_BCFBdi4y7NRP5275y/view?usp=sharing
Thanks in advance
回答1:
In android manifest set android:name like below:
android:name=".MainActivity"
And in Mainactivity add Name like below:
[Activity(Name = "packagename.MainActivity")]
来源:https://stackoverflow.com/questions/48680875/getting-class-not-found-exception-when-doing-deeplinking-in-xamarin-forms