-
I am trying to get an android release build working, and my env variables are coming through as undefined when I build with:
I can log them out through Logcat and see that they are undefined. However, when I bundle with
I'm guessing there's something wrong with my app/build.gradle file but I'm very stuck. Any ideas? I am in a monorepo and am in the middle of a React Native upgrade. Because of the funny monorepo architecture, where node_modules exists further up relative to native files, my build.gradle file looks like this: apply plugin: "com.android.application"
apply plugin: "com.facebook.react"
import com.android.build.OutputFile
import org.gradle.internal.os.OperatingSystem
react {
root = file("../")
reactNativeDir = file("../../../../node_modules/react-native")
codegenDir = file("../../../../node_modules/react-native-codegen")
cliFile = file("../../../../node_modules/react-native/cli.js")
entryFile = file("../../index.js")
def hermesBinDir = 'linux64-bin'
if (OperatingSystem.current() === OperatingSystem.MAC_OS) {
hermesBinDir = 'osx-bin'
}
hermesCommand = "$rootDir/../../../node_modules/react-native/sdks/hermesc/$hermesBinDir/hermesc"
}
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
def jscFlavor = 'org.webkit:android-jsc:+'
def reactNativeArchitectures() {
def value = project.getProperties().get("reactNativeArchitectures")
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}
def appConfigFile = new File("$rootDir/../app.json")
def appConfig = new groovy.json.JsonSlurper().parseText(appConfigFile.text)
android {
ndkVersion rootProject.ext.ndkVersion
compileSdkVersion rootProject.ext.compileSdkVersion
namespace "com.myproject"
defaultConfig {
applicationId appConfig.packageName
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 17
versionName "0.1.0"
resConfigs "en"
manifestPlaceholders = [
releaseStage: appConfig.releaseStage
]
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include (*reactNativeArchitectures())
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
release {
// In github actions, we decode and store keystore file
// in android/app/release.keystore
storeFile file("release.keystore")
storePassword '------'
keyAlias 'my-key-alias'
keyPassword '------'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// 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:
// https://developer.android.com/studio/build/configure-apk-splits.html
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
}
}
}
}
dependencies {
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")
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
}
}
apply from: file("../../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) Update |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This was a silly mistake. I did not have |
Beta Was this translation helpful? Give feedback.
This was a silly mistake. I did not have
root
set correctly in android/app/build.gradle. It should be../..