|
Question: project different distribution channels may need to package a variety of APK (same code), package names may not be the same, if a package name to modify a reprogrammed apk is very troublesome, may refer to the following steps to manipulate the Android Studio Gradle to package different package name apk.
Examples goal here is that the same code, and packaged into com.example.android.newsreader com.example.android.newsreaderdev two different package name apk
1. First, add the following code to the android node build.gradle
productFlavors {
flavors_release {
manifestPlaceholders = [str: "releaseStr", package_name: "com.example.android.newsreader"]
applicationId "com.example.android.newsreader"
}
flavors_dev {
manifestPlaceholders = [str: "devStr", package_name: "com.example.android.newsreaderdev"]
applicationId "com.example.android.newsreaderdev"
}
}
This functionality is packaged productFlavors parametric provided, flavors_release and flavors_dev can be regarded as two variable set their own definition, the actual operation can be customized
Noting there is a manifestPlaceholders argument, which is actually provided several parameters variables and values, where the parameter $ {name} can be used in a manner in AndroidManifest.xml. The original is to manifest in AndroidManifest node in the package to a dozen different parameterization to achieve the purpose apk package names, namely:
< Manifest xmlns: android = "http://schemas.android.com/apk/res/android"
package = "$ {package_name}"
android: versionCode = "1"
android: versionName = "1.0">
< Uses-sdk android: minSdkVersion = "11" android: targetSdkVersion = "14" />
...
The results of Lint Android Studio automatically gave me a hint:
I recommend using Android Studio Description applicationId way to set the parameters of the package name
Ever since, I flavors_release and flavors_dev he also added applicationId settings
Let's see if there are effects
2. This step requires manipulation Gradle panel
At this time we click on How to Android Studio to play more package names APK Android Studio refresh button on the right side panel under gradle, so there is something in the following subsection of the build:
Which are beginning to assemble * option to generate apk, apk generated in build / outputs / apk, and here we can double-click on any one to generate the corresponding apk
3. Check the contents of the following Project panel
Open the project panel, we find that there have been a few really apk:
Gradle can be seen in three apk will generate a double-click every time we put newsreader-flavors_dev-debug.apk and newsreader-flavors_release-debug.apk out to check under their package names with aapt command (command aapt dump badging {filename.apk})
Sure enough, the package name is not the same.
So whether it is possible to install it, here are the two apk installed into the simulator, it really is possible:
You can see the emergence of two NewsReader, in fact, they are exactly the same, just different package names
4. How do you specify the time signature in the package
In Android Studio menu bar to enter the Build-> Generate Signed Apk:
Specify your keystore and click next:
Flavors here will find there are two items that we set in two flavors parameters inside gradle configuration, each selected, click on the apk finish to generate the required
5. There is a question, why modify applicationId to modify the package name it? applicationID and packagename in the end what is the relationship
In fact, package represents the java code package. applicationId represents a unique identification applications. And signed application and other applications together to distinguish different. I think this is why Google market reason to allow the same application of different applicationId.
One last tip: Before After packing out best to publish comprehensive testing to avoid problems. |
|
|
|