1. Preface
Maybe you will have this trouble. During development, the test suddenly tells you that there are some problems with the official package and you need to take a look. At this time, you open the test machine and find that it is installed with the test package. It’s okay, so uninstall and install the official package. Then, the problem of the official package has been confirmed and found that it is not a bug, but a feature. You need to go back to the test package to continue to develop. As a result, you have to uninstall the official package and install a test package.
How troublesome this is going to take a long time ~
How to solve it? Some people say that I have two test machines in my hand, one with a formal package and the other with a test package. I want to say, classmate, you sit down first, most of us only have one test machine.
So, the question is, how to install formal and test packages on a mobile phone at the same time. This is the problem that this article wants to solve.
2. Implement the installation of formal and test packages on one mobile phone at the same time
We know that the only identifier of an Android application is the package name, which is the applicationId in it. Duplicate unique identities of two packages that are not allowed to be installed on a mobile phone. Therefore, you just need to change the applicationId of the test package, that is, the package name.
2.1 Modify the test package name
After checking the documents, I found that Android official has long supported this scenario. I only need to set applicationIdSuffix under the android->buildTypes->debug node of app/. The example is as follows:
android { // ... buildTypes { debug { minifyEnabled false applicationIdSuffix ".test" // Add package name suffix to test package } release { // ... } } //... }
2.2 The problem is coming ~ Compilation failed
Things are often not that simple. After I modified the app/, I synced it and found that the compilation failed, the translation failed, the failure, the failure, the failure, the failure, the failure. . .
The error log is as follows:
[...]
:app:compileDebugJavaWithJavac
error: The generated class cannot be found
What to do? I don’t know what’s going on. It looks like the pot of AndroidAnnotation. Programming for search engines, after some search, I found this: Using a debug "applicationIdSuffix" causes compilation errors #1888.
2.3 Problem resolution
For specific explanations, please refer to the above issue and post a solution. Add javaCompileOptions configuration under android->defaultConfig:
javaCompileOptions { annotationProcessorOptions { arguments = [ "resourcePackageName": ] } }
resourcePackageName This parameter is defined by AndroidAnnotations. For its specific meaning, please refer to it.here
Last
So, you can finally install the official package and the test package on one mobile phone at the same time~~
Summarize
The above is the entire content of this article. I hope that the content of this article has a certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.