Method of Installing Formal Package and Test Package on Android Mobile Phone at the Same Time

  • 2021-11-02 02:25:47
  • OfStack

1. Preface

Maybe you will have this trouble. When developing, the test suddenly tells you that there is something wrong with the official package, so you need to look at it. At this time, you open the test machine and find that it is loaded with a test package. It's okay, so uninstall it and install a formal package. Then, the problem of the official package was confirmed, and it was found that it was not Bug, but an Feature. You need to go back to the test package to continue development, and it turns out that you have to uninstall the official package and install a test package.

How troublesome it is to go 1 to 2 ~

How to solve it? Some people say that I have two testing machines in my hand, one with a formal package and the other with a test package. I want to say, Chen Duxiu, sit down first. Most of us only have one test machine.

Then, the question comes, how to install the official package and the test package on one mobile phone at the same time? This is the problem to be solved in this paper.

2. Install the official package and the test package on one mobile phone at the same time

As we know, the only identification of Android application is the package name, that is, applicationId in build. gradle. Two packages that are not allowed to be installed on one mobile phone have duplicate only 1 identities. Therefore, just change the applicationId of the test package, that is, the package name, by 1 ~

2.1 Modify the test package name

After consulting the documents, it was found that Android officially supported this scenario for a long time, only in android-of app/build. gradle- > buildTypes- > applicationIdSuffix can be set below the debug node, as shown below:


android {
 // ...
 
 buildTypes {
  debug {
   minifyEnabled false
   applicationIdSuffix ".test"   //  Add package name suffix to test package 
  }
  release {
   // ...
  }
 }
 
 //...
}

2.2 Here comes the problem ~ compilation failed

Things are often not so simple. After I modified app/build. gradle, under sync 1, I found that compilation failed, translation failed, failed, failed, failed. . .

The error log is as follows:

[...]
:app:compileDebugJavaWithJavac
error: The generated com.xxx.xx.test.R class cannot be found

What should I do? I don't know what happened. It looks like a pot of AndroidAnnotation. Programming for search engine, after one search, I found this: Using a debug "applicationIdSuffix" causes compilation errors # 1888.

2.3 Problem solving

For specific explanation, please refer to the solution under issue and Stick 1 above. In android- > Add javaCompileOptions configuration under defaultConfig:


javaCompileOptions {
 annotationProcessorOptions {
  arguments = [
   "resourcePackageName": android.defaultConfig.applicationId
  ]
 }
}

The parameter resourcePackageName is defined by AndroidAnnotations. For its specific meaning, please refer to here
Last

So, finally you can install both the official package and the test package on one mobile phone ~ ~

Summarize


Related articles: