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. 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. Using 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
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
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
# Add any project specific keep options here:
-keep class com.furry.BuildConfig { *; }
Dependencies in 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"
},
This happens because react-native init is always shipping the latest version of Gradle to your android project, and third party libraries might not have support for that Gradle version, making your Gradle version incompatible with the library. What you need to do is install a earlier version of Gradle for your project and then rebuild your app.
A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication).
Step 1: Go to the root of the project in the terminal and run the below command: react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res Step 1. Generate a keystore
Step 1. Generate a keystore You will need a Java generated signing key which is a keystore file used to generate a React Native executable binary for Android. You can create one using the keytool in the terminal with the following command
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
.
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.
stagingrelease {
initWith release
matchingFallbacks = ['debug', 'release'] // Addded this
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With