Gradle multi-channel packaging and umeng statistics-eclipse version, gradle-eclipse
Before packaging the channel, let's take a look at the preparation documents and know what the packaging is. See 1.0android batch packaging cognition.
Batch packaging Cognition
Use gradle for multi-channel packaging in eclipse
1. Generate the gradle file and configure the local gradle environment. 1. Right-click the project to be packaged and choose expert> Generate the gradle file, as shown in
2. After completing step 1, refresh the project to obtain the file shown in
Obviously, the gradle. build File and the gradle folder are added to the project. If not, right-click the project and Click refresh to refresh the generated gradle folder, for example:
3. Open the above gradle-wrapper.properties File
RED: indicates the file to be used when gradle is used for packaging.
4.copy the URL directly to the official website to download the corresponding gradle-1.12-all.zip. The reason may be that the package fails due to version differences. You can also try to upgrade the version of the gradle plug-in adt or eclipse.
The above is downloaded from the official website. In the red section, you can select the version you want to download. In the initial stage, I downloaded the highest version, but the package was not successful. The matching version is successfully downloaded. However, if a higher version is tested, a matched version is used. The matched version is selected. 5. Configure the local environment of gradle. Decompression path for gradle-1.12-all
GRADLE_HOME D: \ Gradle \ gradle-1.12-all \ gradle-1.12
Configure path (GRADLE_HOME is only used as a root path)
Create a new gradle-repo folder to configure Environment Variables
GRADLE_USER_HOME
D: \ Gradle \ gradle-repo
Test whether the gradle environment is configured successfully.
Enter gradle-version in the command prompt.
If the result is displayed, the gradle configuration is successful.
Ii. Use gradle for packaging
1. view the gradle. build File (generated by default) in the project to be packaged and add the relevant script code
The declaration in buildscript {// buildscript is the resource required by the gradle script. // Resources that can be declared include dependencies, third-party plug-ins, maven repository addresses, and Other repositories {mavenCentral ()} dependencies {classpath 'com. android. tools. build: gradle: 0.12. + '} apply plugin: 'android' // In build. the dependency and repository address directly declared in the gradle file are the resources required by the project. dependencies {compile fileTree (dir: 'libs', include :'*. jar ')} android {compileSdkVersion 19 buildToolsVersion "19.1.0" 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-types/debug/java, build-types/debug/AndroidManifest. xml ,... // This moves them out of them default location under src/<type> /... which wocould // conflict with src/being used by the main source set. // Adding new build types or product flavors shoshould be accompanied // by a similar customization. debug. setRoot ('Build-types/debug') release. setRoot ('Build-types/release ')} lintOptions {abortOnError false} // The code above indicates the simplest package, generally, two packages are generated: // * -debug-unaligned.apk: apk package without zipAlign optimization // * -release-unsigned.apk: Unsigned apk package // both of the above packages are not officially required, add the following code to generate the signature package signingConfigs {myConfig {// both the absolute path and the relative path can be storeFile file ("E: \ sjjywork \ key \ key4VipOneToOne \ JyVipKey. keystore ") storePassword" sjjy, vip "keyAlias" jiayuan_vip_key "keyPassword" sjjy, vip "}}buildtypes {release {// 1. add signingConfig signingConfigs. myConfig // 2. runProguard executes the obfuscation code runProguard true // the obfuscation rule file proguardFiles getDefaultProguardFile('proguard-android.txt '), 'proguard-project.txt'} // After the code is added, the signed apk is displayed: among them xxx-release-unaligned.apk is signed for zipAligned optimized package // The xxx-release.apk is signed and zipAlign optimized package // Add obfuscated code to execute the code above step 2, the following code can be used to create a obfuscation package // start to create a batch package productFlavors {GooglePlay {// Replace the placeHolder (placeHolder) manifestPlaceholders = [UMENG_CHANNEL_VALUE: "GooglePlay"]} Store360 {manifestPlaceholders = [UMENG_CHANNEL_VALUE: "Store360"]} // Add the channel code for different channels below} // set the channel in batches using the following method: // productFlavors. all {flavor-> // flavor. manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] //} tasks. withType (Compile) {options. encoding = "UTF-8 "}
The code manually added to this file has been commented out in detail.
2. in manifest, add the key and channel code of umeng statistics (for how to obtain and add the key of umeng statistics, refer to umeng statistics documents for details). What is the purpose of Channel package? Why channel packages? For more information, see <1.0apk batch packaging cognition>. The preceding file uses umeng statistics. Add the following code in manifest. xml:
<! -- The channel id and key use umeng directly to facilitate access to umeng sdk --> <meta-data android: name = "UMENG_APPKEY" android: value = "YOUR_APP_KEY"> </meta-data> <! -- Configure placeHolder (placeHolder) for replacement during multi-channel packaging --> <meta-data android: name = "UMENG_CHANNEL" android: value = "$ {UMENG_CHANNEL_VALUE}"/>
The placeHolder in the placeHolder: $ {UMENG_CHANNEL_VALUE} list file is mainly used during batch packaging. Replace the UMENG_CHANNEL_VALUE field in batch packaging to generate different apk packages.
3. Perform Batch packaging on the console, enter the project directory, and run gradle clean and gradle build. If no error is reported, the package is successful, for example, gradle clean.
Cause of error: Empty lines are added between comments and codes. I am not familiar with this script language, so I don't know the specific reason. Execute gradle build
The entire batch packaging process ends perfectly. Refresh the project folder and check the package:
Among them, the -project name-channel-release.apk is the final channel apk we need. The whole batch packaging process is completed in about 10 minutes. However, there are still many questions about the packaging process. We recommend that you read the following articles.
① Which packages will be generated when the automatically generated gradle. build File is directly packaged? What are the differences between various packages? Refer to 2.1 gradle for blog Packaging
Gradle build android applications step by step
② What does zipAlign optimization mean? See 2.4
ZipAlign Optimization
③ What is the lint tool used? See 2.5
Lint tool-Zhang xingye
④ The configuration and packaging process lasted for more than 10 minutes. However, if an error is reported, it takes time. For common errors, see 2.3gradle errors.
Gradle packaging error Summary
So far, all the packaging procedures have really ended. Add the code of the statistical function and add the code of the corresponding position based on the relevant statistics documents of umeng.
For more information, see the section above ....