React Native集成PhonePe SDK失败:无法找到IntentSDK:2.4.1依赖
PhonePe支付网关SDK集成到React Native项目构建失败问题
问题背景
尝试将PhonePe支付网关SDK集成到React Native项目,已完成Top-level和app级build.gradle的配置,但项目构建失败。
报错信息
无法确定任务':app:compileDebugJavaWithJavac'的依赖,无法解析':app:debugCompileClasspath'的所有任务依赖,找不到phonepe.intentsdk.android.release:IntentSDK:2.4.1,该依赖为项目:app所需。
当前配置代码
Top-level build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { buildToolsVersion = "33.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33 // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP. ndkVersion = "23.1.7779620" } repositories { google() mavenCentral() // phonepe step 1 maven { url "https://phonepe.mycloudrepo.io/public/repositories/phonepe-intentsdk-android" } } dependencies { classpath("com.android.tools.build:gradle") classpath("com.facebook.react:react-native-gradle-plugin") classpath ("com.google.gms:google-services:4.4.0") } }
App级build.gradle
apply plugin: "com.android.application" apply plugin: "com.facebook.react" apply plugin: 'com.google.gms.google-services' dependencies { // phonepe step 3 implementation("phonepe.intentsdk.android.release:IntentSDK:2.4.1") // The version of react-native is set by the React Native Gradle Plugin implementation("com.facebook.react:react-android") // react native camera // implementation 'com.google.mlkit:barcode-scanning:17.2.0' implementation platform('com.google.firebase:firebase-bom:32.3.1') implementation("com.google.firebase:firebase-analytics") debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { exclude group:'com.squareup.okhttp3', module:'okhttp' } debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") if (hermesEnabled.toBoolean()) { implementation("com.facebook.react:hermes-android") } else { implementation jscFlavor }
解决方案
问题出在Maven仓库的配置位置错误:你把PhonePe的Maven仓库配置在了buildscript块的repositories里,而Gradle只会在allprojects块的repositories中查找项目依赖包。
修改Top-level build.gradle,添加allprojects块并配置PhonePe仓库,调整后的配置如下:
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { buildToolsVersion = "33.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33 // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP. ndkVersion = "23.1.7779620" } repositories { google() mavenCentral() } dependencies { classpath("com.android.tools.build:gradle") classpath("com.facebook.react:react-native-gradle-plugin") classpath ("com.google.gms:google-services:4.4.0") } } // 添加allprojects块,配置项目依赖仓库 allprojects { repositories { google() mavenCentral() maven { url "https://phonepe.mycloudrepo.io/public/repositories/phonepe-intentsdk-android" } } }
修改后重新执行构建,Gradle就能正确找到PhonePe的SDK依赖了。
内容的提问来源于stack exchange,提问作者Jasim Khan
相关产品推荐
相关产品推荐

