英文:
Unable to find explicit activity class when open deeplink
问题
Xamarin.Android 应用程序具有 API32 上的深度链接。在将 API 更新到 33 后,深度链接已经损坏。我在日志中看到以下异常:
时间 设备名称 类型 PID 标签 消息
02-14 08:25:48.878 OnePlus IN2015 错误 16453 AcceptInvitation android.content.ActivityNotFoundException:无法找到显式活动类 {PACKAGENAME/crc645ff435851f1c2612.MainActivity};您是否在 AndroidManifest.xml 中声明了此活动,或者您的意图与其声明的 <intent-filter> 不匹配?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2184)
...
我尝试谷歌解决这个问题,尝试了很多方法:
- 更改 ProGuard 设置
- 检查不同的调用 MainActivity 的变体,使用程序集名称或只用一个点
- 更新我的库和 SDK
- 尝试指定其他活动
- 检查程序集在调试和发布模式下都能正常工作
- 分析 dex 文件
但什么都没有真正帮助解决问题。
我的分析表明问题在于活动列表中有两个 MainActivities。
此外,我也附上了 AndroidManifest:
...
<application android:requestLegacyExternalStorage="true"
android:allowBackup="true" android:icon="@mipmap/icon"
android:largeHeap="true" android:supportsRtl="true"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:localeConfig="@xml/locales_config"
android:name=".MyApplication">
...
<activity android:name=".MainActivity" android:exported="true">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="https" />
<data android:scheme="http" />
<data android:host="SITE.com" />
<data android:host="OWN.LINK" />
</intent-filter>
</activity>
...
</application>
MainActivity 类具有 MainLauncher 属性。
请帮助我!我花了一整天的时间,如果没有帮助,我担心会陷入困境很长时间。看起来错误可能很明显。
英文:
I had Xamarin.Android App with deeplinks on API32. After I updated API to 33, Deeplinks has broken. I had this exception in my logs:
Time Device Name Type PID Tag Message
02-14 08:25:48.878 OnePlus IN2015 Error 16453 AcceptInvitation android.content.ActivityNotFoundException: Unable to find explicit activity class {PACKAGENAME/crc645ff435851f1c2612.MainActivity}; have you declared this activity in your AndroidManifest.xml, or does your intent not match its declared <intent-filter>?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2184)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1831)
at android.app.Activity.startActivityForResult(Activity.java:5555)
at hcm.platform_startActivityForResult(:com.google.android.gms@230413045@23.04.13 (190408-505809224):2)
at hcl.startActivityForResult(:com.google.android.gms@230413045@23.04.13 (190408-505809224):2)
at com.google.android.chimera.android.Activity.startActivityForResult(:com.google.android.gms@230413045@23.04.13 (190408-505809224):2)
at hgx.startActivityForResult(:com.google.android.gms@230413045@23.04.13 (190408-505809224):2)
at hcl.public_startActivityForResult(:com.google.android.gms@230413045@23.04.13 (190408-505809224):2)
at hcm.startActivityForResult(:com.google.android.gms@230413045@23.04.13 (190408-505809224):3)
at android.app.Activity.startActivityForResult(Activity.java:5508)
at hcm.platform_startActivityForResult(:com.google.android.gms@230413045@23.04.13 (190408-505809224):1)
at hcl.startActivityForResult(:com.google.android.gms@230413045@23.04.13 (190408-505809224):1)
at com.google.android.chimera.android.Activity.startActivityForResult(:com.google.android.gms@230413045@23.04.13 (190408-505809224):1)
at hgx.startActivityForResult(:com.google.android.gms@230413045@23.04.13 (190408-505809224):1)
at hcl.public_startActivityForResult(:com.google.android.gms@230413045@23.04.13 (190408-505809224):1)
at hcm.startActivityForResult(:com.google.android.gms@230413045@23.04.13 (190408-505809224):1)
at android.app.Activity.startActivity(Activity.java:6011)
at hcm.platform_startActivity(:com.google.android.gms@230413045@23.04.13 (190408-505809224):2)
at hcl.startActivity(:com.google.android.gms@230413045@23.04.13 (190408-505809224):2)
at com.google.android.chimera.android.Activity.startActivity(:com.google.android.gms@230413045@23.04.13 (190408-505809224):2)
at hcl.public_startActivity(:com.google.android.gms@230413045@23.04.13 (190408-505809224):2)
at hcm.startActivity(:com.google.android.gms@230413045@23.04.13 (190408-505809224):3)
at android.app.Activity.startActivity(Activity.java:5978)
at hcm.platform_startActivity(:com.google.android.gms@230413045@23.04.13 (190408-505809224):1)
at hcl.startActivity(:com.google.android.gms@230413045@23.04.13 (190408-505809224):1)
at com.google.android.chimera.android.Activity.startActivity(:com.google.android.gms@230413045@23.04.13 (190408-505809224):1)
at kmv.x(:com.google.android.gms@230413045@23.04.13 (190408-505809224):4)
at kmw.onPostExecute(:com.google.android.gms@230413045@23.04.13 (190408-505809224):3)
at android.os.AsyncTask.finish(AsyncTask.java:771)
at android.os.AsyncTask.-$$Nest$mfinish(Unknown Source:0)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:788)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:240)
at android.os.Looper.loop(Looper.java:351)
at android.app.ActivityThread.main(ActivityThread.java:8355)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
I tried to google a solution to this problem, tried a lot:
Changed ProGuard settings,
I checked various variations of calling MainActivity with the name of the assembly and just with a dot,
Updated my libraries and SDK,
I tried to prescribe other activities,
I checked the assemblies work both in debug and in release,
Analyzed dex files.
Nothing really helps.
Own analysis showed that the problem is that there are two MainActivities in
the list of activities.
I am also attaching AndroidManifest:
...
<application android:requestLegacyExternalStorage="true"
android:allowBackup="true" android:icon="@mipmap/icon"
android:largeHeap="true" android:supportsRtl="true"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:localeConfig="@xml/locales_config"
android:name=".MyApplication">
...
<activity android:name=".MainActivity" android:exported="true">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="https" />
<data android:scheme="http" />
<data android:host="SITE.com" />
<data android:host="OWN.LINK" />
</intent-filter>
</activity>
...
</application>
MainActivity class has MainLauncher attribute.
Help me please! I spent a day on this and I'm afraid that without help I can be stuck for a long time. Seems like the error might be obvious.
[Activity(ScreenOrientation = ScreenOrientation.Portrait, NoHistory = true, MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
...
}
UPD:
Sometimes I had this exception:
Time Device Name Type PID Tag Message
02-14 08:38:29.150 OnePlus IN2015 Info 28812 MonoDroid Caused by: java.lang.ClassNotFoundException: Didn't find class "PACKAGENAME.MainActivity" on path: DexPathList[[zip file "/data/app/~~jXWlqXqgllqjZ1bi2qN5dg==/PACKAGENAME-gqSZGEIemXo6mh-lUysz-w==/base.apk"],nativeLibraryDirectories=[/data/app/~~jXWlqXqgllqjZ1bi2qN5dg==/PACKAGENAME-gqSZGEIemXo6mh-lUysz-w==/lib/arm64, /data/app/~~jXWlqXqgllqjZ1bi2qN5dg==/PACKAGENAME-gqSZGEIemXo6mh-lUysz-w==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
at androidx.core.app.CoreComponentFactory.instantiateActivity(SourceFile:45)
at android.app.Instrumentation.newActivity(Instrumentation.java:1347)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3745)
... 12 more
答案1
得分: 0
"ActivityNotFoundException"错误通常在Android应用程序尝试使用Intent启动Activity时发生,但指定的Activity类找不到或不存在。您可以尝试以下一些试错方法:
问题可能是由于Activity类名称不正确,因此请确保Intent中的Activity类名称是正确的,包括包名称。
还要确保Activity类在您的AndroidManifest.xml文件中声明,否则Android系统将无法识别它。
如果Activity类存在于您的代码中,但仍然遇到此错误,可能是因为Activity类未包含在您的APK文件中。如果该类未在代码中正确引用,或者构建过程将该类从APK中排除,就会发生这种情况。
如果通过深度链接启动Activity类,请确保在AndroidManifest.xml文件中为Activity正确设置了Intent过滤器。
还有可能是从API 32升级到API 33可能导致Android框架发生更改,影响了您的深度链接。您可能需要查看Android开发者文档,了解在API 33中处理深度链接的方式是否发生了任何更改,并相应地更新您的代码。
希望这些发现可以帮助您解决疑惑。
谢谢。
英文:
The "ActivityNotFoundException" error generally occurs when an Android app is trying to launch an Activity using an Intent, but the specified Activity class cannot be found or does not exist. You can try below some hit and trial methods:
Issue can be because of incorrect activity class name so make sure that the activity class name in your Intent is correct, including the package name.
Also make sure that the activity class must be declared in your AndroidManifest.xml file, or it will not be recognized by the Android system.
If the Activity class is present in your code, but you still encountering this error, it could be because the Activity class is not being included in your APK file. This can happen if the class is not being referenced properly in your code, or if the build process is excluding the class from the APK.
If the Activity class is being launched through a deep link, just make sure that the correct Intent filters are set up for the Activity in your AndroidManifest.xml file.
It's also possible that the update from API 32 to API 33 could have caused changes in the Android framework that are affecting your deep links. You may want to check the Android Developer documentation for any changes in the way that deep links are handled in API 33, and make any necessary updates to your code accordingly.
I hope these findings may help you out to rectify your doubt.
Thanks.
答案2
得分: 0
从您发布的Manifest.xml
文件中,我找不到以下intent-filter
:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
因此,您可以重新检查是否已正确为您的Activity设置了MainLauncher = true
。
您可以参考我的设置,就像下面这样:
[Activity(Label = "SearchBarDemos", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, Exported = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[
IntentFilter
(
new[] { Android.Content.Intent.ActionView },
Categories = new[]
{
Android.Content.Intent.CategoryDefault,
Android.Content.Intent.CategoryBrowsable
},
DataSchemes = new[] { "myapp" }
)
]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
}
您可以参考类似的主题:使用Xamarin从一个应用程序导航到另一个应用程序。
注意:
如果您已经为您的MainActivity设置了ActivityAttribute MainLauncher = true
,则无需在Manifest.xml
文件中进行设置,否则可能会导致生成您提到的两个MainActivity
。
换句话说,您无需在生成的Manifest.xml
文件中添加任何代码。
有关更多信息,请参阅:使用Android清单。
英文:
From the generated Manifest.xml
file you posted, I couldn't find the following intent-filter
:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
so, you can recheck if you have set the MainLauncher = true
correctly for your Activity.
You can refer to my setting,just as follows:
[Activity(Label = "SearchBarDemos", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true,Exported =true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[
IntentFilter
(
new[] { Android.Content.Intent.ActionView },
Categories = new[]
{
Android.Content.Intent.CategoryDefault,
Android.Content.Intent.CategoryBrowsable
},
DataSchemes = new[] { "myapp" }
)
]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
}
And you can refer to a similar thread here: Navigate from one app to another using Xamarin.
Note:
If you have set ActivityAttribute MainLauncher = true
for your MainActivity, you don't need to set it on fileManifest.xml
,which easily leads to generating two MainActivity
s you said.
On other words,you don't need to add any code into the generating Manifest.xml
file.
For more information,please check:Working with the Android Manifest.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论