安装react-native-codepush后出现:react-native-code-push项目解析失败问题
安装react-native-codepush后执行Android构建时出现以下错误:
Could not determine the dependencies of task ':app:mergeDebugAssets'.
Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
Could not resolve project :react-native-code-push.
Required by:
project :appNo matching configuration of project :react-native-code-push was found. The consumer was configured to find a runtime of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' but:
- None of the consumable configurations have attributes.
解决方案:
版本兼容性检查
确认react-native-code-push版本与当前React Native版本匹配(比如RN 0.70+对应code-push 7.0+)。执行以下命令查看当前版本,不匹配则重装:npm list react-native-codepush npm uninstall react-native-codepush npm install react-native-codepush@适配版本号重新执行自动链接并清理缓存
即使RN 0.60+支持自动链接,仍可能出现链接不完整的情况,执行:npx react-native link react-native-codepush cd android && ./gradlew clean手动补全Android项目配置
- 打开
android/settings.gradle,确认添加以下配置:include ':react-native-code-push' project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app') - 打开
android/app/build.gradle,确保dependencies块包含:implementation project(':react-native-code-push') - 检查
buildTypes配置,确保debug、release等构建类型存在,且CodePush部署key配置正确:buildTypes { debug { signingConfig signingConfigs.debug // 可选:添加调试环境CodePush key // codePushDeploymentKey "YOUR_DEBUG_KEY" } release { signingConfig signingConfigs.release codePushDeploymentKey "YOUR_PRODUCTION_KEY" } }
- 打开
升级Gradle相关版本
打开android/build.gradle,更新Gradle插件版本到RN兼容的版本(如RN 0.70+对应7.2.0+):buildscript { dependencies { classpath("com.android.tools.build:gradle:7.2.3") } }修改
android/gradle/wrapper/gradle-wrapper.properties中的Gradle版本:distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
内容的提问来源于stack exchange,提问作者sakshya73

