Differentiated subcontracting and packaging of Android apps

Differentiated subpackage packaging on android studio.

Option 1 Configure the applicationId suffix (applicationIdSuffix) of the subpackage:

(1) Add productFlavors{} to the build.gradle file under the corresponding module, and configure the applicationId suffix (applicationIdSuffix) in the sub-package, as shown in the figure

(2) In the xml file of the manifest, you can refer to the content defined by different packages under productFlavors, so that when the package is installed, different icons, names, and even theme styles can be displayed according to the different packages installed.

Among them, if you encounter a push notification, when different packages are installed at the same time, which leads to a conflict in opening the page, you can define the data scheme in the intent-fliter to solve the conflict. specific methods:

1) Under different packages of productFlavors, define a variable, such as:

2) In the xml of the manifest, when declaring the activity, assign the content of this variable to the sheme attribute of the data of the intent-filter, namely:

3) In the jump intent, define as follows:

(3) When compiling and packaging, in BuildVariants in android studio, choose to compile different packages

(4) After selecting the package to be compiled, run it under the debug package to  see the effects of different packages.

 

 

Option 2 Configure the applicationId of the subpackage and create a different package name for the subpackage:

(1) In the build.gradle file under the corresponding module, add productFlavors{}, define different packages, and define different applicationIds, as shown in the figure:

(2) Create different package names according to the different applicationIds defined;

1) Right-click new activity in the corresponding module, as shown in the figure:

2) In the activity creation page, select some relevant properties, before creating the corresponding package name (first switch to the corresponding package in BuildVarians, so that the package name defined under productFlavors can be parsed), as shown in the figure :

After creation, it looks like this,

(3) Add the private resources of your own installation package to the respective res directory, namely:

(4) In the manifest xml file in the main directory, refer to the resources of each package to realize that different installation packages have different styles, namely:

(5) Define different entry activities for different installation packages. In the manifest xml file under the respective package name, define, namely:

It should be noted that after each package defines its own entry activity, remember to remove the entry activity of the manifest xml file in the main directory, so that two identical icons and names will not appear when installing the package. which is:

 

 

In the build.gradle file of the module, when adding dependent libraries, you can add them according to the labels of different packages, such as:

Finally, in subcontracting and packaging, you need to pay attention to the conflict between the resource naming in the subcontract and the resource name in the main directory. If you encounter a resource naming conflict, you can choose to modify the resource name in the subcontract or delete and modify the resource name in the main directory. .

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325024423&siteId=291194637