You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET MAUI集成Stripe支付后深度链接报错:无法实例化Activity ComponentInfo

解决.NET MAUI Android深度链接无法找到MainActivity的问题

核心原因

你遇到的ClassNotFoundException是因为AndroidManifest.xml中手动指定的MainActivity路径与实际编译后的类路径不匹配:

  • C#代码里MainActivity的命名空间是degano,编译后对应的Java类名是degano.MainActivity
  • 但Manifest里写的android:name=".MainActivity"会被解析为com.apatinisbruksnys.degano.MainActivity,系统找不到这个类

另外,.NET MAUI会自动根据C#中的[Activity]特性生成AndroidManifest条目,手动添加<activity>节点容易造成冲突。

解决方案

方法一:用MAUI特性自动生成IntentFilter(推荐)

移除AndroidManifest.xml中手动添加的整个<activity>节点,转而在MainActivity.cs中通过[IntentFilter]特性配置深度链接:

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

namespace degano;

[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
// 添加深度链接的IntentFilter特性
[IntentFilter(new[] { Intent.ActionView },
              Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
              DataSchemes = new[] { "degano" },
              DataHosts = new[] { "stripe-payment" })]
public class MainActivity : MauiAppCompatActivity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        
        Intent intent = Intent;
        string action = intent.Action;
        string scheme = intent.Scheme;

        if (Intent.ActionView.Equals(action) && scheme.Equals("degano"))
        {
            Uri data = intent.Data;
            // 在这里处理Stripe支付回调,比如提取支付状态参数
        }
    }
}

方法二:手动修正Manifest中的类路径(不推荐)

如果坚持手动修改AndroidManifest.xml,需要指定完整的类名,而不是相对路径:

<!-- 修正android:name为完整类名 -->
<activity android:name="degano.MainActivity"
          android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data android:scheme="degano"
              android:host="stripe-payment" />
    </intent-filter>
</activity>

测试步骤

  1. 彻底清理项目:删除bin、obj文件夹
  2. 重新编译并部署应用到测试设备/模拟器
  3. 再次运行adb测试命令:
adb shell am start -W -a android.intent.action.VIEW -d "degano://stripe-payment"

内容的提问来源于stack exchange,提问作者Justas Mileika

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 02:27:03