【问题标题】:Razorpay implementation error in Android StudioAndroid Studio 中的 Razorpay 实现错误
【发布时间】:2022-01-23 13:06:20
【问题描述】:

我已经实施了 Razorpay-checkout, 但是当我点击构建时它只显示明显的错误,我尝试了很多次,但它总是显示错误,我附上了一些代码,请帮助我。我看到了这种类型的错误 清单合并失败:需要明确指定 android:exported 。当相应组件定义了 Intent 过滤器时,面向 Android 12 及更高版本的应用需要为 android:exported 指定显式值

Gradle

plugins {
    id 'com.android.application'
}
android {
    compileSdk 31

    defaultConfig {
        applicationId "com.example.razopay"
        minSdk 21
        targetSdk 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        targetSdkVersion 31
        minSdkVersion 21
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
    implementation 'com.razorpay:checkout:1.6.12'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

构建错误

Manifest merger failed : android:exported needs to be explicitly specified for <activity>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

Android 清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.razopay">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Razopay">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>

</manifest>

【问题讨论】:

    标签: android-studio build.gradle razorpay


    【解决方案1】:

    解决方案是覆盖 razorpay 的清单设置。

    在您的 AndroidManifest.xml 文件中添加以下行以覆盖 razorpay 的清单设置。

    <receiver
        android:name="com.razorpay.RzpTokenReceiver"
        android:exported="false">
        <intent-filter>
            <action android:name="rzp.device_token.share" />
        </intent-filter>
    </receiver>
    
    <activity
        android:name="com.razorpay.CheckoutActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:exported="true"
        android:theme="@style/RazorpayTheme"
        tools:replace="android:theme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <data
                android:host="rzp.io"
                android:scheme="io.rzp" />
        </intent-filter>
    </activity>
    

    而且我们还必须更换 CheckoutActivity 的主题以解决进一步的崩溃问题,

    tools:replace="android:theme
    

    标签在这里很重要,上面manifest设置中已经提到过,现在将下面的代码添加到styles.xml中。

     <style name="RazorpayTheme" parent="Theme.AppCompat.Dialog">
        <item name="android:windowActionBar">false</item>
        <item name="android:windowFrame">@null</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:colorBackgroundCacheHint">@null</item>
        <item name="android:background">@android:color/transparent</item>
        <item name="android:windowCloseOnTouchOutside">false</item>
    </style>
    

    【讨论】:

      猜你喜欢
      • 2021-10-03
      • 2023-01-29
      • 1970-01-01
      • 2021-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多