before you go through the pipeline packaging, take a look at the prep chapter and know what to pack for. See 1.0android Bulk Packaging awareness. Use Gradle multichannel to package all processes in eclipse
I. Generate the Gradle file, configure the local Gradle environment 1. Select the items you want to package right-click the expert-> generate Gradle file, as shown in
2. After completing the first step, refresh the project to get the file as shown
Obviously the project has more Gradle.build files, gradle folders. If it does not appear, click the project right--refresh refresh to see the generated Gradle folder, such as:
3. Open the above gradle-wrapper.properties file
Red indicates the part: The file you need to use when packing with Gradle.
4. Copy the above URL, or directly to the official website to download the corresponding gradle-1.12-all.zip. Why download the corresponding, may be due to differences between versions, resulting in packaging failure. You should also try upgrading the version of the Gradle plugin in ADT or Eclipse.
The above is the official website download, in the Red Flag section, you can choose the corresponding version you want to download. In the beginning I downloaded the highest version and the final package was unsuccessful. Download the matching version package successfully. However, if the test is high, the matching version is used. This selects the corresponding version of the match. 5. Configure the Gradle local environment. Gradle-1.12-all Decompression Path Gradle_home D:\Gradle\gradle-1.12-all\gradle-1.12
Configure path (Gradle_home only as a root path)
Create a new Gradle-repo folder configuration environment variable
Gradle_user_home
D:\Gradle\gradle-repo
Test that the GRADLE environment is configured successfully.
At the command prompt, enter: gradle-version
appears as a result, indicating that the Gradle configuration was successful.
Two. Use Gradle for packaging
1. View the Gradle.build file (the default generated file) in the project you want to package and add the relevant script code
The declaration in Buildscript {//buildscript is the resource that the Gradle script itself needs to use. Resources that can be declared include dependencies, third-party plug-ins, maven warehouse addresses, etc. repositories {mavencentral ()} dependencies {classpath ' Com.andro id.tools.build:gradle:0.12.+ '}}apply plugin: ' Android '//The dependencies, warehouse addresses, etc. that are directly declared in the Build.gradle file are resources required by the project itself dependencies {C Ompile Filetree (dir: ' Libs ', include: ' *.jar ')}android {compilesdkversion buildtoolsversion "19.1.0" Sourcese TS {main {manifest.srcfile ' androidmanifest.xml ' java.srcdirs = [' src '] resource S.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 themDefault location under src/<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 ')} lintoptions {AbortOnError False}////////////////////the above code out of the simplest package, typically generates two packages//////////////////////*-debug-unaligned.apk: No zipalign optimized APK package//*-release-unsigned.apk: Unsigned apk package//The above two packages are not formally required packages, add the following code to play the signature package Signingconfigs {myconfig { Both absolute and relative paths can be StoreFile file ("E:\\sjjywork\\key\\key4viponetoone\\jyvipkey.keystore") Storepassword "SJJ Y,vip "Keyalias" Jiayuan_vip_key "Keypassword" Sjjy,vip "}} buildtypes{Release {//1. Add signature Signingconfig signingconfigs.myconfig//2.runproguard Execute obfuscation code runproguard TRUE//obfuscation rule file Proguardfil Es getdefaultproguardfile (' proguard-android.txt '), ' Proguard-project.txt '}//After adding the above code, a signed apk has been played: where XXX-RELEASE-UNALIGNED.APK is the package signed for zipaligned optimization//xxx-rele ASE.APK is a signature and zipalign optimized package//Add obfuscation code to execute code as in the second step, you can implement the obfuscation package///code below to start the bulk package productflavors {googleplay{// Replace the placeholder in the manifest file (placeHolder) manifestplaceholders = [Umeng_channel_value: "GooglePlay"]} store360{ Manifestplaceholders = [Umeng_channel_value: "Store360"]}//below continue to add channel code for different channels}//Through the following methods are batch settings//Productflavors. All {flavor//flavor.manifestplaceholders = [Umeng_channel_value:name]//}}tasks.withtype (Compile) {options. encoding = "UTF-8"}
The code that was manually added to this file has been commented out in detail. 2.manifest to add the Friend League statistics key and channel code (about the Friends of the League statistics of key acquisition and add, direct reference to the Friends of the League statistical documents, not to explain) what is the purpose of hitting the channel pack? Why do you want to play a channel bag? This can be seen <<1.0apk bulk packaging cognition >> obtained the conclusion is to do statistics. In the above file, the Friend League statistics are used. At this point, you need to add the following code in Manifest.xml:
<!--channel Id,key directly using Umeng, convenient access Umeng SDK-- <meta-data android:name= "Umeng_appkey" android:value= "Your_ App_key "></meta-data> <!--configuration placeholder (placeholder) for multi-channel packaging when you replace-- <meta-data android: Name= "Umeng_channel" android:value= "${umeng_channel_value}"/>
A placeholder in the Placeholder:${umeng_channel_value} manifest file that is used primarily when hitting bulk packages. In bulk packaging the process of bulk replacing this umeng_channel_value field generates different APK packages. 3. Formally execute bulk package in the console, enter the directory where the project is located, and execute Gradle clean,gradle build. If there is no error, the package will be successful such as: Gradle clean
Reason for error: Add blank lines between comments and code. Because this scripting language is not familiar, there is no specific reason. Perform Gradle Build
The entire bulk packaging process is complete. Refresh the project folder to see the packages that were typed:
Where-the project name-channel-release.apk is ultimately the channel apk we need. The whole batch package process takes about more than 10 minutes to get done. But if there is still a lot of confusion about the packaging process. Recommended to see the following articles. ① automatically generated gradle.build files are packaged directly to generate those packages? Different packages, what's the difference? See 2.1 gradle Packaging blog②zipalign Optimization What does it mean? See 2.4③lint Tools for what? See the 2.5④ Configuration and packaging process for about more than 10 minutes. But if there is an error, it will be time-consuming. Common error Reference the following article: see 2.3gradle Packaging errors encountered
It's really the end of all the processes that are packaged. Add the code of the statistic function, directly according to the friend Union statistic document adds the corresponding location code to be possible.
See section above to be continued ....
Gradle multi-channel packaging and Friends League statistics-eclipse version