View Original: http://blog.csdn.net/u010818425/article/details/52319382
Gradle Combat Series Articles:
"Gradle basic knowledge point and common configuration"
Gradle: Co-existence of packages with different types of compilation
"Gradle: Release AAR package to maven warehouse"
"Gradle: Execute SQL Operations Hive database"
This article will continue the previous several blog style, first from the basic concept, which helps us understand the latter, in the subsequent code if you forget the specific meaning of a concept, you can review the head to revisit the concept of the introduction.
In this paper, the implementation principle of the General Batch packaging scheme is introduced in detail, and the basic realization principle of the mass packaging is introduced, and several implementation schemes are quoted for everyone's reference.
Introduction of Basic concepts
1. Package
2. PlaceHolder
The variables in the Androidmanifest file are expressed by ${PlaceHolder}
means that placeholder is a variable that can be assigned, such as the channel in the Friend League statistic:
<meta-data android:name="UMENG_CHANNEL" android:value="${UMENG_CHANNEL_VALUE}"></meta-data>
3. ApplicationID
4. Buildtypes
Packages for generating different compilation types, such as Debug and release packages
android{ buildTypes { debug { ... } release { ... } }}
Debug and release are the two build type that are gradle by default, and in the project auto-generated buildconfig, the difference is as follows:
// release版本生成的BuildConfig特性信息public final class BuildConfig { public static final boolean DEBUG = false; public static final String BUILD_TYPE = "release";}// debug版本生成的BuildConfig特性信息public final class BuildConfig { public static final boolean DEBUG = true; public static final String BUILD_TYPE = "debug";}
Customize a different build type, such as
android{ buildTypes { debug { ... } release { ... } beta { ... } }}
5. Productflavors
6. Signingconfigs
Signature configuration, release compilation type configuration such as:
release { storeFile file("../yourapp.keystore") //签名证书文件 storePassword "your password" //签名证书密码 keyAlias "your alias" //别名 keyPassword "your password" //别名密码}
Of course, signature information can be hidden by reading the configuration file (see previous article) and configuration file ignore, which is not detailed in this article.
7. Meta-infFile
- Some information to store the signature, add an empty file within the Meta-inf directory, and the app does not need to be re-signed.
Second, multi-channel packaging configuration
1. General Packaging Solutions
Generate Package Time Def releasetime () {return new Date (). Format ("Yyyy-mm-dd", Timezone.gettimezone ("UTC"))} and roid {compilesdkversion buildtoolsversion "23.0.3" defaultconfig {applicationid "com. Company.appname "Minsdkversion targetsdkversion versioncode 1 Versionnam E "1.0"//default channel for official website manifestplaceholders = [Umeng_channel_value: "Official"]} Lintoptio NS {Checkreleasebuilds false Abortonerror false}//configure compiled JDK version compileoptions {sourcecompatibility org.gradle.api.JavaVersion.VERSION_1_7 targetcompatibility Org.gradle.api.Java Version.version_1_7}//Signature configuration Signingconfigs {debug {//No debug Config StoreFile file ("${rootdir}/keystores/xqsg_debug.jks")//debug certificate} release { StoreFile file ("${roOtdir}/keystores/xqsg.jks ")//release certificate Storepassword" test "//Signing Certificate Password Keyalias "Test"//alias Keypassword "Test"/ /alias Password}} buildtypes {debug {Buildconfigfield ("boolean", "log_on", "t Rue ")//config log switch by compile type Versionnamesuffix"-debug "//package name suffix"-debug "minifye Nabled false//whether to confuse zipalignenabled false//zipalig n Optimize shrinkresources false//Remove useless resource file Signingconfig signin Gconfigs.debug//Signing with Debug certificate} release {Buildconfigfield "boolean", "L Og_on "," false "//does not display log minifyenabled true//Open confusion Zipalignena Bled true Turn on Zipalign optimization shrinkresources true//Remove useless resource file, this entry only when the confusion is turned on Effective Proguardfiles getdefaultproguardfile (' proguard-android.txt '), ' Proguard-rules.pro ' signin Gconfig Signingconfigs.release//Signing with Release certificate//multi-channel packaging configuration Applicationvariants.all {variant-variant.outputs.each {output, def outputFile = Output.out Putfile if (outputFile! = null && outputFile.name.endsWith ('. apk ')) { The output apk name is called test_v1.0_2016-08-15_wandoujia.apk def fileName = "Test_v${defaultconfig.versi Onname}_${releasetime ()}_${variant.productflavors[0].name}.apk "output.outputfile = new File (ou Tputfile.parent, FileName)}}}}// Channel Configuration ProductflavoRS {wandoujia {} _360 {} Baidu {} Xiaomi {}} productflavors.al L {flavor-flavor.manifestplaceholders = [Umeng_channel_value:name]//dynamically modify channel name in Androidmanifest} }
Note: The above log switch allows you to get the value of the variable in Java code, such as:
if(BuildConfig.LOG_ON){ Log.d("test","xxx"); }
2. US Package Solution
Implementation principle: Android App install package apk file is a compressed file, you can change the suffix to zip direct decompression. After extracting, you will find a Meta-inf directory under the root directory. If you add an empty file within the Meta-inf directory, the app does not need to be re-signed. Therefore, you can uniquely identify a channel by adding different empty files for different channels of application.
In this way, one channel package per dozen only needs to copy an apk and add an empty file named after the channel number in Meta-inf.
- Android Automation Tour-Generate channel packs
- American group Android Automation Tour-adaptation channel pack
- Implementation Reference 1
- Implementation Reference 2
Learn more about Android Studio Series Tutorial six –gradle multi-channel packaged Android product development (v) –> multi-channel packaging more convenient Android multi-channel packaging Android Packaging series-multi-channel fast packaging
View Original: http://blog.csdn.net/u010818425/article/details/52319382
Gradle Combat: Android Multi-channel Packaging solution Summary