[英]React Native build fails on building a new build type other than debug/release
I am trying to prepare a staging release build but by my build is failing.我正在尝试准备一个临时发布版本,但我的构建失败了。 It gives me a huge list of errors.它给了我一大堆错误。 I have modified my build.gradle to add a staging environment.我已经修改了我的 build.gradle 以添加一个临时环境。 I am not sure why this is happening as my debug and release build works fine.我不确定为什么会发生这种情况,因为我的调试和发布版本工作正常。
I used yarn android --variant=stagingrelease
to generate the build and run on my physical android device.我使用yarn android --variant=stagingrelease
生成构建并在我的物理 android 设备上运行。 Using React-Native: 0.61.5
.使用React-Native: 0.61.5
。
Some of the errors are as follows部分错误如下
FAILURE: Build failed with an exception.
* What went wrong: Could not determine the dependencies of task ':app:preStagingreleaseBuild'.
> Could not resolve all task dependencies for configuration ':app:stagingreleaseRuntimeClasspath'.
> Could not resolve project :@react-native-community_masked-view.
Required by:
project :app
> Unable to find a matching variant of project :@react-native-community_masked-view:
- Variant 'debugApiElements' capability Furry:@react-native-community_masked-view:unspecified:
- Incompatible attributes:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Variant 'debugRuntimeElements' capability Furry:@react-native-community_masked-view:unspecified:
- Incompatible attribute:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
- Variant 'releaseApiElements' capability Furry:@react-native-community_masked-view:unspecified:
- Incompatible attributes:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Variant 'releaseRuntimeElements' capability Furry:@react-native-community_masked-view:unspecified:
- Incompatible attribute:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
> Could not resolve project :react-native-bootsplash.
Required by:
project :app
> Unable to find a matching variant of project :react-native-bootsplash:
- Variant 'debugApiElements' capability Furry:react-native-bootsplash:unspecified:
- Incompatible attributes:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Variant 'debugRuntimeElements' capability Furry:react-native-bootsplash:unspecified:
- Incompatible attribute:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
- Variant 'releaseApiElements' capability Furry:react-native-bootsplash:unspecified:
- Incompatible attributes:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Variant 'releaseRuntimeElements' capability Furry:react-native-bootsplash:unspecified:
- Incompatible attribute:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
> Could not resolve project :react-native-config.
Required by:
project :app
> Unable to find a matching variant of project :react-native-config:
- Variant 'debugApiElements' capability Furry:react-native-config:unspecified:
- Incompatible attributes:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Variant 'debugRuntimeElements' capability Furry:react-native-config:unspecified:
- Incompatible attribute:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
- Variant 'releaseApiElements' capability Furry:react-native-config:unspecified:
- Incompatible attributes:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Variant 'releaseRuntimeElements' capability Furry:react-native-config:unspecified:
- Incompatible attribute:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
> Could not resolve project :react-native-gesture-handler.
Required by:
project :app
> Unable to find a matching variant of project :react-native-gesture-handler:
- Variant 'debugApiElements' capability Furry:react-native-gesture-handler:unspecified:
- Incompatible attributes:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Variant 'debugRuntimeElements' capability Furry:react-native-gesture-handler:unspecified:
- Incompatible attribute:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
- Variant 'releaseApiElements' capability Furry:react-native-gesture-handler:unspecified:
- Incompatible attributes:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Variant 'releaseRuntimeElements' capability Furry:react-native-gesture-handler:unspecified:
- Incompatible attribute:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
> Could not resolve project :react-native-reanimated.
Required by:
project :app
> Unable to find a matching variant of project :react-native-reanimated:
- Variant 'debugApiElements' capability com.swmansion.reanimated:react-native-reanimated:unspecified:
- Incompatible attributes:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Variant 'debugRuntimeElements' capability com.swmansion.reanimated:react-native-reanimated:unspecified:
- Incompatible attribute:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
- Variant 'releaseApiElements' capability com.swmansion.reanimated:react-native-reanimated:unspecified:
- Incompatible attributes:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Variant 'releaseRuntimeElements' capability com.swmansion.reanimated:react-native-reanimated:unspecified:
- Incompatible attribute:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
> Could not resolve project :react-native-safe-area-context.
Required by:
project :app
> Unable to find a matching variant of project :react-native-safe-area-context:
- Variant 'debugApiElements' capability Furry:react-native-safe-area-context:unspecified:
- Incompatible attributes:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Variant 'debugRuntimeElements' capability Furry:react-native-safe-area-context:unspecified:
- Incompatible attribute:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
- Variant 'releaseApiElements' capability Furry:react-native-safe-area-context:unspecified:
- Incompatible attributes:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Variant 'releaseRuntimeElements' capability Furry:react-native-safe-area-context:unspecified:
- Incompatible attribute:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
> Could not resolve project :react-native-screens.
Required by:
project :app
> Unable to find a matching variant of project :react-native-screens:
- Variant 'debugApiElements' capability com.swmansion.rnscreens:react-native-screens:unspecified:
- Incompatible attributes:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Variant 'debugRuntimeElements' capability com.swmansion.rnscreens:react-native-screens:unspecified:
- Incompatible attribute:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'debug'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
- Variant 'releaseApiElements' capability com.swmansion.rnscreens:react-native-screens:unspecified:
- Incompatible attributes:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Variant 'releaseRuntimeElements' capability com.swmansion.rnscreens:react-native-screens:unspecified:
- Incompatible attribute:
- Required com.android.build.api.attributes.BuildTypeAttr 'stagingrelease' and found incompatible value 'release'.
- Other attributes:
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
Snippets of android/app/build.gradle android/app/build.gradle 的片段
project.ext.envConfigFiles = [
debug: ".env",
release: ".env.production",
stagingrelease: ".env.staging",
]
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
project.ext.react = [
entryFile: "index.js",
enableHermes: false, // clean and rebuild if changing
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = true
def enableHermes = project.ext.react.get("enableHermes", false);
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.furry"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://facebook.github.io/react-native/docs/signed-apk-android.
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
stagingrelease {
initWith release
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "androidx.appcompat:appcompat:1.1.0-rc01"
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02"
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
project.ext.vectoricons = [
iconFontNames: [ 'MaterialIcons.ttf', 'MaterialCommunityIcons.ttf' ]
]
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
android/build.gradle android/build.gradle
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
proguard-rules.pro proguard-rules.pro
# Add any project specific keep options here:
-keep class com.furry.BuildConfig { *; }
Dependencies in package.json package.json 中的依赖项
"dependencies": {
"@react-native-community/masked-view": "^0.1.6",
"@react-navigation/native": "^5.0.7",
"@react-navigation/stack": "^5.0.8",
"axios": "^0.19.2",
"libphonenumber-js": "^1.7.44",
"react": "16.9.0",
"react-native": "0.61.5",
"react-native-bootsplash": "^1.2.1",
"react-native-config": "^0.12.0",
"react-native-gesture-handler": "^1.6.0",
"react-native-reanimated": "^1.7.0",
"react-native-safe-area-context": "^0.7.3",
"react-native-screens": "^2.0.0-beta.10",
"react-native-sms-retriever": "^1.1.1",
"react-native-svg": "^11.0.1",
"react-native-vector-icons": "^6.6.0",
"realm": "4.0.0-beta.0",
"recyclerlistview": "2.0.13-alpha.1"
},
Alright!, so I have been trying for many hours to resolve the issues and it turns out that there is a simple answer to it, matchingFallbacks
.好吧!,所以我已经尝试了好几个小时来解决这些问题,结果发现有一个简单的答案, matchingFallbacks
。
The issue occurs because I am adding a new build variant stagingrelease
to my app's build.gradle
whereas the native libraries that am using doesn't have the same matching variant in their build.gradle
hence during the build the repective libraries are not found.出现问题是因为我正在向我的应用程序的build.gradle
添加一个新的构建变体stagingrelease
而正在使用的本机库在它们的build.gradle
中没有相同的匹配变体,因此在构建过程中找不到相应的库。
stagingrelease {
initWith release
matchingFallbacks = ['debug', 'release'] // Addded this
}
try this commands one by one in your project directory在你的项目目录中一一试试这个命令
cd android
./gradlew clean
cd ..
wipe data of your virtual device start virtual device again擦除虚拟设备的数据再次启动虚拟设备
run npx react-native run-android
运行npx react-native run-android
this will help you to build debug apk again.这将帮助您再次构建调试 apk。 It will remove all previous apks.它将删除所有以前的 apk。
Android Support Repository was missing installed, again followed all the steps here:未安装 Android Support Repository,再次按照此处的所有步骤操作:
https://reactnative.dev/docs/getting-started.html https://reactnative.dev/docs/getting-started.html
https://github.com/facebook/react-native/issues/2772#issuecomment-140843907 https://github.com/facebook/react-native/issues/2772#issuecomment-140843907
Some of the packages have been renamed, particularly "Android Support Repository" seems to have been renamed to "Local Maven repository for Support Libraries".一些软件包已重命名,特别是“Android 支持库”似乎已重命名为“支持库的本地 Maven 库”。 Installing it fixed the error for me.安装它为我修复了错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.