Javascript 如何在Android Studio中为React本机应用程序的开发和发布应用程序定义变体
我使用react native配置在生产环境和开发环境之间进行更改 我可以根据IOS的方案切换环境dev/prod(捆绑机标识符、appIcon、splashScreeen、appName等等) 对于开发人员:Javascript 如何在Android Studio中为React本机应用程序的开发和发布应用程序定义变体,javascript,android,react-native,react-native-android,react-native-config,Javascript,Android,React Native,React Native Android,React Native Config,我使用react native配置在生产环境和开发环境之间进行更改 我可以根据IOS的方案切换环境dev/prod(捆绑机标识符、appIcon、splashScreeen、appName等等) 对于开发人员: ENVFILE=.env npx react-native run-ios --scheme 'testConfigAppDev' ENVFILE=.env npx react-native run-android --variant debug 对于prod: ENVFILE=.e
ENVFILE=.env npx react-native run-ios --scheme 'testConfigAppDev'
ENVFILE=.env npx react-native run-android --variant debug
对于prod:
ENVFILE=.env.production npx react-native run-ios --scheme 'testConfigApp'
ENVFILE=.env.production npx react-native run-ios --scheme 'testConfigApp'
如果我想使用类似于android的软件:
对于开发人员:
ENVFILE=.env npx react-native run-ios --scheme 'testConfigAppDev'
ENVFILE=.env npx react-native run-android --variant debug
对于prod:
ENVFILE=.env.production npx react-native run-ios --scheme 'testConfigApp'
ENVFILE=.env.production npx react-native run-ios --scheme 'testConfigApp'
我希望在一个项目中有两种类型的应用程序开发和prod以及applicationId,例如:com.my.app用于生产和com.my.app.dev用于开发
我想切换环境dev/prod(绑定器标识符、appIcon、splashScreeen、appName等等)
但我每次都使用相同的appIcon和appName构建相同的应用程序
在Android/app/build.gradle中:
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
//applicationId project.env.get("APP_ID")
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
resValue "string", "app_name", project.env.get("APP_DISPLAY_NAME")
resValue "string", "build_config_package", project.env.get("APP_ID")
}
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
debuggable true
applicationIdSuffix ".dev"
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.debug
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
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 =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
我的目标是使用application_id com.My.app和development com.My.app.dev构建一个用于生产的应用程序
谢谢你们的帮助