如何解决如何在Android Studio中定义变体以开发和发布React Native应用程序的应用程序
我使用react-native-config在生产和开发环境之间进行切换。
我可以根据IOS的方案切换环境dev / prod(捆绑程序标识符,appIcon,splashScreeen,appName等)。
对于开发人员:
ENVFILE=.env npx react-native run-ios --scheme 'testConfigAppDev'
和产品:
ENVFILE=.env.production npx react-native run-ios --scheme 'testConfigApp'
如果我想使用它类似于android:
对于开发人员:
ENVFILE=.env npx react-native run-android --variant debug
和产品:
ENVFILE=.env.production npx react-native run-ios --scheme 'testConfigApp'
我想在一个项目下拥有两种类型的appdev和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和开发com.my.app.dev构建用于生产的应用程序。
谢谢大家的帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。