返回

解决 Adyen React Native for Android 配置错误:步骤指南

Android

解决 Adyen React Native for Android 中的配置错误

简介

在集成 Adyen React Native 模块时,开发者可能会遇到 "Cannot get property 'adyenReactNativeRedirectScheme' on extra properties extension as it does not exist." 错误。本文将逐步指导你解决此错误,并提供有关 Adyen React Native for Android 配置的深入见解。

原因

此错误通常是由于以下原因之一引起的:

  • 应用的 build.gradle 文件中未正确设置重定向方案。
  • MainActivity.kt 文件中缺少 Adyen Intent 处理程序。
  • AndroidManifest.xml 文件中未包含必要的意图过滤器。
  • Adyen React Native 模块未正确添加到 Android Studio 项目中。

步骤 1:验证应用构建文件

在应用的 build.gradle 文件中,确保已正确设置 redirectScheme

manifestPlaceholders = [redirectScheme: rootProject.ext.adyenReactNativeRedirectScheme]

步骤 2:检查 MainActivity

MainActivity.kt 文件中,添加以下代码以处理 Adyen Intents:

import android.content.Intent
import android.os.Bundle
import com.adyenreactnativesdk.AdyenCheckout.handleIntent
import com.adyenreactnativesdk.AdyenCheckout.setLauncherActivity

class MainActivity : ReactActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(null)
        setLauncherActivity(this)
    }

    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
        handleIntent(intent!!)
    }
}

步骤 3:查看 AndroidManifest.xml

AndroidManifest.xml 文件中,添加以下意图过滤器:

<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:host="${applicationId}" android:scheme="${redirectScheme}" />
</intent-filter>

步骤 4:检查项目配置

确保已将 Adyen React Native 模块正确添加到 Android Studio 项目中。

步骤 5:编译并运行应用

重新编译并运行应用以查看错误是否已解决。

常见问题解答

  1. redirectScheme 的正确值是什么?
    redirectScheme 可以是任何自定义方案,例如 myApp

  2. 为什么我需要设置 redirectScheme
    redirectScheme 用于处理付款完成时的重定向。

  3. 如何处理此错误的替代方法是什么?
    对于某些情况,可以修改 Adyen React Native 模块的源代码以删除对 adyenReactNativeRedirectScheme 的引用。但这不是推荐的方法。

  4. 此错误的潜在原因是什么?
    此错误可能是由于使用较旧版本的 Adyen React Native 模块或 Android Gradle 插件引起的。

  5. 如何避免将来出现此错误?
    保持 Adyen React Native 模块和 Android Gradle 插件的最新版本至关重要。此外,仔细按照官方文档进行操作并使用 Android Studio lint 检查器可以帮助及早发现此类错误。