Author: Platform Front End Team @ Ocean

background

I had a problem with uninstalling the old package and reinstalling it when testing in different environments. React Native: The Multipackage Solution for Android

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

I’m going to focus on 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 formal</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

At first I thought my two versions of appiD were the same, but they weren’t

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 toSolved my problem

conclusion

Finally, I successfully solved my problem

Appid can be changed dynamically with productFlavors, which is a common way of packaging appID with different channels.