The original package hasn't been studied yet.
First, add code to the manifest file
<pre name= "code" class= "Java" >
<meta-data android:name= "channel_id" android:value= "${channel_id_value}"/>
And then change from the outer build.gradle first.
ext{} and Task clean{} are new code:
<pre name= "code" class= "Java" >//top-level build file where can add configuration options common to all sub-proj Ects/modules.buildscript { repositories { mavencentral () } dependencies { classpath ' com.android.tools.build:gradle:2.0.0 ' }}ext { minsdkversion = 8 targetsdkversion = Compilesdkversion = buildtoolsversion = ' 23.0.3 ' <span style= "color: #ff0000;" > sourcecompatibilityversion = javaversion.version_1_7 targetcompatibilityversion = Javaversion.version_1_7</span>}task Clean (type:delete) { Delete Rootproject.builddir}
The specific version number according to their own needs to
Then change most of the build.gradle in the inner layer, which is the model Build.gradle
<pre name= "code" class= "java" >apply plugin: ' com.android.application ' dependencies {compile filetree (dir: ' Libs ') , include: ' *.jar ') Compile project (':P ushsdk ')}buildscript {repositories {mavencentral ()} Dependenc ies {classpath ' com.android.tools.build:gradle:2.0.0 '}}android {compilesdkversion buildtoolsversion "23.0.3" defaultconfig {applicationid "com. XX "//com. XX for Package name Minsdkversion rootProject.ext.minSdkVersion//Just set the outer build.gradle just for this use targetsdkversion Rootproject.ext . targetsdkversion//Reason ditto Versioncode versionname "1.1.6"//version name and version number according to your own needs manifestplaceholders = [Application_name: "XX",//xx for the project name Umeng_appkey_value: "Friends of the APPKEY",//My project inserted a friend Au, can be ignored Umeng_channel_value: "Here is the channel number of Friends Alliance",//Friends of the channel number did not cite friends can ignore Channel_id_value: "xxxx_99999", Default channel number This is not about friends. The channel number you want to generate is not negligible!!!! Umeng_message_secret_value: "* * *"//AU related can be ignored"} signingconfigs {//signature file related can be automatically generated here settings reference the following figure Myconfig {key Alias ' Alias ' Keypassword ' key password ' storefile file (' key path ') Storepassword ' automatically generated password ' }} buildtypes {release {///package will run this mode signingconfig signingconfigs.myconfig minify Enabled false//whether to turn on confusion generally does not turn on confusion, because the open confusion of various audits are not easy by the best of all packaging after the 360 reinforcement and other tools to encrypt zipalignenabled true//support zip file compression Shrinkresources true//whether to prune unused resources//Proguardfiles getdefaultproguardfile (' proguard-android.txt '), ' Progua Rd-project.txt ' This line in opening confusion with no open confusion on the comment out} debug {//Normal run will go this signingconfig signingconfigs.myconf IG minifyenabled false zipalignenabled true shrinkresources true//proguardfiles Getdefaultproguardfile (' Proguard-android.txt '), ' Proguard-project.txt '}} compileoptions {SourceCom Patibility JAVAVERSION.VErsion_1_7 targetcompatibility Javaversion.version_1_7} sourcesets {main {MANIFEST.SRCFI Le ' androidmanifest.xml ' java.srcdirs = [' src '] resources.srcdirs = [' src '] aidl.srcdirs = [' src '] renderscript.srcdirs = [' src '] res.srcdirs = [' res '] assets.srcdirs = [' Assets ' ]}//Move The tests to Tests/java, tests/res, etc ... Instrumenttest.setroot (' tests ')//Move The build types to build-types/<type>//For instance, build-t Ypes/debug/java, Build-types/debug/androidmanifest.xml, ...//This moves them out of them the default location under s rc/<type>/which would//conflict with src/being used by the main source set. Adding New build types or product flavors should be accompanied//by a similar customization. Debug.setroot (' Build-types/debug ') release.setroot (' Build-types/release ')} ProductflavORS {//here to write the desired channel number xxxx_99999//360 Mobile Assistant xxxx_99998//app Bao xxxx_99997//Baidu Application} Applicationvarian Ts.all {variant--//Set the generated apk path and name Variant.outputs.each {OUTPUT, def outputFile = OUTPUT.O Utputfile if (outputFile! = null && outputFile.name.endsWith ('. apk ')) {def variantname = Variant.name; Variantname = variantname.substring (0, Variantname.lastindexof ("_")) def fileName = "${variantname}_v${de Faultconfig.versionname}_${releasetime ()}_${variant.buildtype.name}.apk "output.outputfile = new File (" F:\\ Xxxx\\xxxx\\xxxx\\xxxx ", FileName)}}} productflavors.all {flavor-Manifestplaceholde rs = [Channel_id_value:name, umeng_channel_value:name]}}//compile time def releasetime () {return new Date (). Format ("yyyy -mm-dd ", Timezone.gettimezone (" UTC "))}tasks.withtype (javacompile) {options.encoding =" UTF-8 "}
The above about signing files are automatically generated after Setup opens open Module settings find your own module→signing
So the basic configuration is complete.
Finally, to generate the various channel APK when choosing Gradle
So double-clicking will generate two packages at the same time, a normal package a debug package
Can be set so that only one normal package is generated
It's basically done. I didn't cancel the debug, and I automatically generated two.
It's basically done. To get the channel ID, you can add a method to the MyApplication to get the channel ID.
Public String Getchannelid () {String id = "99999"; The default channel number Try{applicationinfo info = Getpackagemanager (). Getapplicationinfo (Getpackagename (), packagemanager.get_ META_DATA); id = String.Format ("%05d", Info.metaData.getInt ("channel_id")); LOG.E ("Rhid", "Rhid_s_1:" + ID); if (id = = NULL | | Id.trim (). Length () = = 0 | | Id.equals ("00000")) {id = "99999"; Default channel number LOG.E ("Rhid", "rhid_s_2:" + ID);} LOG.E ("Rhid", "Rhid_s_3:" + ID);} catch (Exception e) {e.printstacktrace (); id = "99999"; Default channel number LOG.E ("Rhid", "Rhid_f:" + ID);} return ID;}
Get the MyApplication instance, and it's finished.
Eclipse turns into an Android studio project for multi-channel packaging