Android Installation of Release and Debug Versions

  • 2021-10-27 09:12:03
  • OfStack

1 general project to achieve the later stage, in the test, need to be frequently switched between the test version and the official version, how to do? Local tyrants can consider using two machines and testing at the same time. However, in order to facilitate testing and save costs, the best way is to install different versions on the same machine.

However, in principle, two APP installation at the same time, due to the signature and package name problem is not allowed, however, under the omnipotent heaven, only you can't think of, not impossible, first of all, we analyze 1 reason, 1. Signature, 2 package name. That is to say, as long as we solve these two problems, we will succeed for 1.5%. The first one is naturally easy to solve. We can specify different signatures for debug and release respectively. What about the second one? Do you want to copy 1 code and change the package name? Isn't this too low? Moreover, it is easy to make mistakes when two projects are followed up and maintained at the same The most important thing is that you can't show the pressure! At this time, the omnipotent gradle came out (then who, don't throw shoes!......)

1. Find build. gradle (Module: app)

Find BuildTypes and add the following code


buildTypes {
  release {
   applicationIdSuffix ".release"
   resValue "string", "app_name", "@string/app_name_release"
//   minifyEnabled false
//   proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  }

  debug {
   applicationIdSuffix ".debug"
   resValue "string", "app_name", "@string/app_name_debug"
  }
} 

2. Find strings. xml

Add code


 <string name="app_name_release">Release Version </string>
 <string name="app_name_debug">Debug Version </string>

3. Find AndroidManifest. xml


<application
  android:allowBackup="true"
  android:icon="@mipmap/ic_launcher"
  android:label="@string/app_name"
  android:supportsRtl="true"
  android:theme="@style/AppTheme">
  
  <activity android:name=".MainActivity">
   <intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
  </activity>

 </application>

Related articles: