background
One day the test reflected that the old package had to be uninstalled every time the different environment was tested. Too much trouble, how to solve?
Two kinds of schemes
The study found two options
- You can cut different environments inside the app
- Through the coexistence of multiple packages – xx. Formal, XX. Test, XX. The development environment is mainly about app coexistence
Many packets coexistence
Package type
Let’s say I have an app package and it might have several types
- Debug package (default channel)
- Release package (default channel)
- Debug package (from other channels – like Meituan)
- Release package (other channels – like Meituan)
How to coexist
I’m a front man, but I’ll do it. After unremitting efforts, finally found
Android uses the applicationId attribute to differentiate between applicationsCopy the code
So the next problem is how to change the appId. After searching the information, I found that productFlavors can be set up with Gradle, which can be conveniently implemented.
Specific operation
Update Android /app/build.gradle productFlavors {beta {// Test the environment
applicationId "com.x.beta"
// applicationIdSuffix ".beta"
manifestPlaceholders = [
app_name: "@string/app_name_beta",]// resValue("string", "envTag", "beta environment ")
}
product {// Production environment
applicationId "com.x.product"
// applicationIdSuffix ".product"
manifestPlaceholders = [
app_name: "@string/app_name",]// resValue("string", "envTag", "production environment ")}}Copy the code
There are two kinds of access to change the appId
- The first way is to set a different ID directly
- The second way is to set “applicationIdSuffix”, which is the application suffix. For example, my default appID is com.x. The /gradlew assembleReleaseBeta will append com.x.eat to the file. You can also see this option in Android Studio without using the command line
Dynamically set app_name, icon, and AppKey
It can be set up by the Manifestplaceholder
// Extend above beta {... manifestPlaceholders = [ app_name: "@string/app_name_beta", app_icon: '@xxxx' JPUSH_APPKEY: '123' // GoogleMap: '456' // GoogleMap] product {}Copy the code
Build. Gradle finished modify, then set the/android/app/SRC/main/AndroidManifest. The inside of the XML content
<application android:icon="${app_icon}" android:label="${app_name}" xxxxx> <! -- Google Map Key --> <meta-data android:name="com.google.android.geo.API_KEY" android:value="${GoogleMapKey}" /> <! -- Aurora push --> <! - the User defined. User defined radio receiver - > < receiver android: name = "com. Ablegenius. Member. The receiver. JpushReceiver" android:enabled="true"> <! -- Android :process=":remote" Broadcast is running in a separate remote process, debugging breakpoints cannot be executed. --> <intent-filter> xxxxx <! <category Android :name="${applicationId}" /> </intent-filter> </receiver> </application>Copy the code
The final configuration package name android/app/SRC/main/res/values/strings. XML
<resources> <string name="app_name">x official </string> <string name="app_name_beta"> X beta </string> </resources>Copy the code
Start packing —–
The result is as follows
Start installing both versions
Then came the following question
Google again in —–
The authorities provider in a third-party library
Find the local tripartite library again at —-
Finally found a library author is written dead not dynamic and then changed to
conclusion
Finally, I successfully solved my problem