Multi-channel packaging, generating packages with different package names

Source: Internet
Author: User

A summary of the knowledge points for multi-channel packaging and generating different package names. The reason for the need to generate different package names is to operate ASO.

Method: 1. Directly create the Channel folder, modify the package name inside the manifest 2. Using placeholders

Of course, the above two methods have their merits and demerits, and finally say a few of their respective characteristics.

First, the first method, step: 1. The package that generates as many package names as needed is established and the main sibling of the folder.

For example, if I need two packages with different package names, then I need to create two different channels of folders.

2. Create a new Maifest file inside the folder

Because the package name is defined in the manifest file, so need to build manifest file, of course, this manifest file inside copy, you may feel too much trouble, I just replace a package name need to copy the whole manifest, this is too pit, In fact, it is not so serious, the package name is generally included in the user's phone desktop above the name displayed, and you go to the application Manager to see the name, the two names can be different.

The name displayed in the application manager is determined by the Android:label property of the application node.

The name displayed on the user's mobile desktop is determined by the Android:label of the first activity of the application, and if the first activity does not specify a label attribute, it is the name of the application Android:label that is used.

Incidentally, the first activity of the application is the activity of the following intent-filter.

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

Here we understand that the application of the two package name, then since we need to change only the package name, we just need to put the application node and the first activity in the manifest inside the configuration copy .
So here are the two manifest files that are required here:
First, post the main manifest file for main channel :

<?xml version="1.0"encoding="Utf-8"? ><manifest package="Com.name.replace"Xmlns:android="Http://schemas.android.com/apk/res/android"> <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 "Android:label="@string/app_name"> <intent-filter> <action android:name="Android.intent.action.MAIN"/> <category android:name="Android.intent.category.LAUNCHER"/> </intent-filter> </activity>...Other configurations...</application></manifest>

app_name_1 Channel :

<?xml version= "1.0" encoding= "Utf-8"?><manifest  package  = "com.name.replace"  xmlns:android  = "http://schemas.android.com/apk/res/android"  xmlns:tools  = "Http://schemas.android.com/tools" ;     <application  android: Allowbackup  = "true"  android:icon  =< Span class= "Hljs-value" > "@mipmap/ic_launcher"  android:label  = "@string/app_name_1"  android:supportsrtl  = "true"  android:theme  = "@ Style/apptheme " tools:replace  =" Android: Label ";         <activityandroid:name=". Mainactivity "android:label=" @string/desk_name_1 "tools:replace=" Android: Label ">                                                <intent-filter>                <action android:name="Android.intent.action.MAIN"/>                <category android:name="Android.intent.category.LAUNCHER"/>            </intent-filter>        </activity>    </Application></manifest>

app_name_2 Channel :

<?xml version= "1.0" encoding= "Utf-8"?><manifest package = "com.name.replace"xmlns:android=" Http://schemas.android.com/apk/res/android "xmlns:tools=" Http://schemas.android.com/tools ">              <application  android: Allowbackup  = "true"  android:icon  =< Span class= "Hljs-value" > "@mipmap/ic_launcher"  android:label  = "@string/app_name_2"  android:supportsrtl  = "true"  android:theme  = "@ Style/apptheme " tools:replace  =" Android: Label ";         <activityandroid:name=". Mainactivity "android:label=" @string/desk_name_2 "tools:replace=" Android: Label ">                                                <intent-filter>                <action android:name="Android.intent.action.MAIN"/>                <category android:name="Android.intent.category.LAUNCHER"/>            </intent-filter>        </activity>    </Application></manifest>

Here can see app_name_1 inside of Manifest and app_name_2 inside of the manifest and not too big difference, just the package name changed a bit. There is no comparable value for these two files.

Focus on the App_name_2 channel manifest and main inside the manifest difference, if you say no difference, it is more embarrassing, mom eggs, I 450 degrees of glasses have seen the difference.

Two differences: (1). A new tools namespace was introduced into the app_name_2 channel.

Xmlns:tools= "Http://schemas.android.com/tools"
And the tools:replace= "Android:label" statement is added to the application node and the first activity node.
If you do not add gradle, there is a problem when merging manifest using the Manifest merger tool.

(2). App_name_2 Channel there is nothing else except the application node and the first activity node.

You don't need some of the other four components in main that are related to something.

3. Configure the channel information inside the Build.gradle
    {        app_name_1 {}        {}        {}        }

The channel name here is the same as the name of the folder that was created at the beginning, if not, the package that was typed is the package inside main.

4. The second method of packaging is as follows:

Thanks to Gradle's support for placeholders, the second approach is far less cumbersome than the first.
There are many uses for placeholders, such as the ability to dynamically define activity names, service names, and so on. The details can be self-Google.
A list of Gradle can be seen in this translation of the article, the explanation is very detailed:
Checklist Merge: http://blog.csdn.net/maosidiaoxian/article/details/42671999

1. Configure placeholders inside the manifest

Since there is no need to create a folder, the manifest here is the manifest in main.
When a property value contains a placeholder, the merge tool replaces the value of this placeholder with an injected value. The injected value is defined in the Build.gradle.
The syntax for placeholder values is ${name}, because the @ symbol has been reserved for the link. All values with placeholders will be replaced with injected values before the final file merge occurs, and before the output of the merged Android manifest file is generated. If the variable name is unknown, it will cause the build to fail.
Manifest file:

<?xml version= "1.0" encoding= "Utf-8"?><manifest package = "com.name.replace"xmlns:android="http/ Schemas.android.com/apk/res/android ">    <applicationandroid:allowbackup="true"android:icon="@mipmap/ Ic_launcher "android:label=" ${app_name} "android:supportsrtl=" true "  android:theme="@style/apptheme">                                                <meta-dataandroid:name= "umeng_channel"android:value="${umeng_ Channel} "/>                                <activityandroid:name=". Mainactivity "android:label=" ${desk_name} ">                                    <intent-filter>                <action android:name="Android.intent.action.MAIN"/>                <category android:name="Android.intent.category.LAUNCHER"/>            </intent-filter>        </activity>    </Application></manifest>

There are three placeholders defined here, App_name,desk_name,umeng_channel.
Placeholder can be replaced by a lot of useful, want to know more can check the information on their own.

2. Configure the channel information inside the Build.gradle

The whole manifest file is posted here for you to see better.

Apply plugin:' Com.android.application 'Android {Compilesdkversion atBuildtoolsversion"23.0.3"Defaultconfig {ApplicationID"Com.name.replace"Minsdkversion theTargetsdkversion atVersioncode1Versionname"1.0"Manifestplaceholders = [App_name:"@string/app_name", Desk_name:"@string/app_name", Umeng_channel:"Beta"]} buildtypes {release {minifyenabled false proguardfiles Getdefaultproguardfile (' Proguard-android.txt '),' Proguard-rules.pro '}} productflavors {//app_name_1 {}//app_name_2 {}//App_main {} app_QQ {manifestplaceholders = [app_name: "@string/app_name_1", Desk_name: "@string/desk_name_1", Umeng_channel: "App Bao"]}app_pp {manifestplaceholders = [app_name:"@string/app_name_2", Desk_name:"@string/desk_name_2", Umeng_channel:"pp Helper"]}}}dependencies {compile Filetree (dir:' Libs ', include: [' *.jar ']) Testcompile' junit:junit:4.12 'Compile' com.android.support:appcompat-v7:23.3.0 '}

You can see that we have replaced the three placeholders defined in manifest.
Here we both define in the Defaultconfig, and in different channels within the definition, the final channel inside the priority will be high.
In fact, if you do not configure the channel information at the beginning, but we define the placeholder, it is not compiled, you must define some of the default properties in the Defaultconfig.

3. Pack and then

At the very beginning, we said that both approaches have advantages and disadvantages, and the first option was used in previous companies for two reasons:
1. Using the first scheme, you can add channel logo for each channel, such as 360 channels need 360 logo, Baidu Channel needs Baidu logo, then the first method is very good to achieve, the main inside of the res/ Layout inside of the start interface copy to the corresponding channel file inside to modify, replace the logo.
The first method can not only place the manifest file, but also the Res directory.

2. Then the channel package does not need our technical staff to play, by the operation to play, the technical side at that time was developed a tool for operation over there channel package dedicated, technical side only need to play a different package name package can be.

So the advantage of the first method is that some of the rest of the special operations can be done, the disadvantage is more troublesome. The second method is simple to implement, but some special operations cannot be done.

Demo Address: http://download.csdn.net/detail/qy274770068/9498668

Multi-channel packaging, generating packages with different package names

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.