Recently has been doing Android automatic packaging, has been completed in the form of pure command line packaging, the original eco-ant script packaging, and Android-based SDK packaging, and the implementation of multi-channel packaging, and later colleagues recommended Gradle, online information said Gradle all kinds of good, I am also interested in realizing that, in fact, because of the Android Eclipse support weakened, most people are using Gradle and Android Studio Fusion, such as the case will be more, but the author of the project is still more in eclipse, Because the developer in the transplant process found more error, so has not been fully ported (well, in fact, early party transplant), so I am using Eclipse IDE To do experiments, the following first put a few basic knowledge
The first is to create a new Android project, and then use your own IDE to generate the Gradle file, specific reference http://blog.csdn.net/x605940745/article/details/ 41242687, interested comrades can take a purely handwritten way, this way can not rely on the IDE, so it would be better
This is the original build.gradle .
Buildscript {repositories {mavencentral ()} dependencies {classpath ' Com.android.tools.build:gra dle:0.8.+ '}}apply plugin: ' Android ' dependencies {compile filetree (dir: ' Libs ', include: ' *.jar ')}android {Comp Ilesdkversion buildtoolsversion "19.0.3" sourcesets {main {manifest.srcfile ' 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 ')}}
Now I'm going to attach my own build.gradle .
Buildscript {repositories {mavencentral ()} dependencies {classpath ' Com.android.tools.build:gra dle:0.12.+ '}}apply plugin: ' Android ' ant.importbuild ' build.xml '//The ant script is imported here dependencies {compile Filetree (dir: ' Libs ', include: ' *.jar ')}android {compilesdkversion buildtoolsversion ' 20.0.0 ' signingconfigs { Signature, where the file name and password are wrong, there will be externally imported statements Myconfig {//absolute path and relative path can be StoreFile file ("E:\\keystore\\mydemo.keystore ")//Signature file Storepassword" 276021750 "//Password Keyalias" Mydemo.keystore " Keypassword "111"}} buildtypes{release {//Here is the step used to generate the APK, see note//1. Add a signature Signingconfig signingconfigs.myconfig//2.runproguard Execute obfuscation code runproguard TRUE//obfuscation rule file Proguar Dfiles getdefaultproguardfile (' proguard-android.txt '), ' Proguard-project.txt '}} productflavors { This is a multi-channel place, Androidman.Ifest.xml file to have the label, the following will be affixed to the file Yingyongbao {manifestplaceholders = [channel_name: "Yingyongbao"]} Umeng {manifestplaceholders = [channel_name: "Umeng"]} Wandoujia { Manifestplaceholders = [channel_name: "Wandoujia"]}} allprojects {//Here is an external import file, then change the file itself property, only the signature is changed, and you can change the other afterevaluate {project, def propsfile = Rootproject.file (' E:\\keystore\\keystore.prope Rties ') def configname = ' myconfig ' if (propsfile.exists () && android.signingConfigs.hasProperty (con Figname) {def props = new Properties () props.load (new FileInputStream (propsfile)) Andro Id.signingconfigs[configname].storefile = File (props[' storefile ') android.signingconfigs[configname].storepass Word = props[' storepassword ' Android.signingconfigs[configname].keyalias = props[' Keyalias '] Androi D.signingconfigs[confignAme].keypassword = props[' Keypassword '}}} sourcesets {main {manifest.srcfile ' 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 ')}} Here the specific function to see the notes on it, the violent paste up there is no problem, the following to paste a few files, a androidmanifest.xml file, inside is added a line
<meta-data android:name= "Umeng_channel" android:value= "${channel_name}"/>
Build.xml adds a target and writes the Gradle deploy with the cmd command to execute the contents.
<target name= "Deploy" > <!--<replaceregexp flags= "G" byline= "true" > <regexp pattern= " public static final Host host = Host.development; "/> substitution expression is the replacement value, and the substituted value is defined in the corresponding configuration file < Substitution expression= "public static final host host = Host.test;" The dir in the/> fileset attribute is used to specify the directory where the replaced file is located includ ES is used to specify which file to replace. <fileset dir= "./src/net/xtion/crm/base" includes= "Crmappcontext.java"/> </replaceregexp>-- > <replace encoding= "Utf-8" dir= "/src/com/example/learn723" ><include name= "Mainactivity.java"/ ><replacefilter token= "public static final String host =" Host.test "," value= "public static final String host =" Hos T.abc ";"/></replace></target>
There is also a signature file
Storefile=e:\\keystore\\mydemo.keystorestorepassword=276021750keypassword=276021750keyalias=mydemo.keystore
Specific demo can be downloaded here
http://download.csdn.net/detail/killer1989/8927225
Such benefits we can see, with ant full-time change file information, here specifically to do multi-channel packaging, can be separated, in fact, to do fully automatic still have two steps, one is automatically obtained from SVN, this online has a lot of version can learn, Another is to use a script to modify the Build.gradle file, dynamic transformation of the signature (in fact, can also do batch modification) and dynamically add the code of these functions, you can use the shell, you can use Python, you can use the need to try
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Gradle Pack Android (implement external import signature file, multi-channel packaging, import ant script)