android - 反应本机代码推送无法解析':app@releaseStaging/compileClasspath'的依赖关系:
问题描述
我正在尝试设置代码推送来管理我的 React Native 应用程序的发布。
按照本指南设置新的 buildTypes 后(https://github.com/Microsoft/react-native-code-push/blob/master/docs/multi-deployment-testing-android.md)我的项目不再同步我安装的所有第 3 方库都出现错误。
Unable to resolve dependency for ':app@releaseStaging/compileClasspath': Could not resolve project :react-native-camera.
...
对于我猜 Gradle 自动添加的一些 UnitTest 也是一样的 Unable to resolve dependency for
':app@releaseStagingUnitTest/compileClasspath': Could not resolve project :react-native-camera.
我在 MS Code Push 中找不到更多信息,并且示例应用程序没有任何第三方库来寻找提示。是什么原因造成的以及如何解决这个问题?
我的应用程序 build.gradle 是:
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.test"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
debug {
// Note: CodePush updates should not be tested in Debug mode as they are overriden by the RN packager. However, because CodePush checks for updates in all modes, we must supply a key.
buildConfigField "String", "CODEPUSH_KEY", '""'
}
releaseStaging {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
buildConfigField "String", "CODEPUSH_KEY", '"_acY9ZGwTFpxYTaD71ps0O4o352EB1UmlPoK7"' // fake key
}
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
buildConfigField "String", "CODEPUSH_KEY", '"xWEc8lRivDOYHdUAHxBz3hiyiF7hB1WEgPoKQ"' // fake key
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation project(':react-native-svg')
implementation project(':react-native-nfc-manager')
implementation project(':react-native-vector-icons')
implementation project(':react-native-camera')
implementation project(':react-native-google-signin')
implementation project(':react-native-fbsdk')
implementation project(':react-native-code-push')
implementation project(':react-native-braintree-xplat')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
implementation project(':react-native-fbsdk')
implementation(project(":react-native-google-signin")){
exclude group: "com.google.android.gms" // very important
}
implementation 'com.google.android.gms:play-services-auth:16.0.1' // should be at least 15.0.0 to work with the most recent APIs
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services' // <--- this should be the last line
和我的 android build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "27.0.3"
minSdkVersion = 16
compileSdkVersion = 27
targetSdkVersion = 26
supportLibVersion = "27.0.2"
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4' // <--- use this version or newer
classpath 'com.google.gms:google-services:3.2.1' // <--- use this version or newer
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.4'
distributionUrl = distributionUrl.replace("bin", "all")
}
解决方案
解决它!我的第 3 方库不知道如何处理 stagingRelease 构建类型,因此我需要提供一个后备版本,如下所示:
buildtypes {
...
releaseStaging {
...
matchingFallbacks = ["release"]
}
推荐阅读
- swift - Swift - 由于 statusBarWindows 导致应用程序崩溃
- solace - 安慰监控:寻找普罗米修斯出口商
- git - 交互式变基 git
- c# - 如何使用 Elastic 低级客户端批量插入嵌套类型对象?
- php - 在 PHP 搜索结果中循环 XPATH
- javascript - 使用反应测试库检查文本是否出现在元素内
- c# - Specflow 未在 Visual Studio 2019 中执行测试
- json - 使用 JQ 替换 JSON 模板中的变量
- swift - UINavigationController 在推送视图的左侧添加自动填充
- python-2.7 - Pass objects as arguments in keywords in robot framework