Gradle packaging android (implement external import signature file, multi-channel packaging, import ant script)

Source: Internet
Author: User

Gradle packaging android (implement external import signature file, multi-channel packaging, import ant script)

Android automatic packaging has been completed recently. Previously, it has completed packaging in the form of command lines, the original ant script packaging, and android-based SDK packaging, and implemented multi-channel packaging, later, my colleague recommended gradle. According to the online documents, gradle is good and I am also interested in implementing it. In fact, android's support for eclipse is generally diminished, most people use gradle and android studio for integration. There will be many examples in this case, but I still have a lot of projects in eclipse, since many errors are reported during the migration process, developers have not completely transplanted the tool (well, we will try to transplant it later). Therefore, I am using the eclipse IDE experiment, below are some basic knowledge posts:

First, create an android project and generate the gradle file with the built-in IDE. For details, refer to idea.

This is the original build. gradle

buildscript {    repositories {        mavenCentral()    }    dependencies {        classpath 'com.android.tools.build:gradle:0.8.+'    }}apply plugin: 'android'dependencies {    compile fileTree(dir: 'libs', include: '*.jar')}android {    compileSdkVersion 19    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/
 
          // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...        // This moves them out of them default location under src/
  
   /... 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')    }}
  
 

 

Next I will first attach my build. gradle

 

Buildscript {repositories {mavenCentral ()} dependencies {classpath 'com. android. tools. build: gradle: 0.12. + '} apply plugin: 'android' ant. importBuild 'build. xml' // The ant script dependencies {compile fileTree (dir: 'libs', include :'*. jar ')} android {compileSdkVersion 19 buildToolsVersion "255.0.0" signingConfigs {// signature. The file name and password here are incorrect, the statement myConfig {// both the absolute path and relative path will be available in storeFile file ("E: \ keystore \ mydemo. keystore ") // signature file storePassword" 276021750 "// password keyAlias" mydemo. keystore "keyPassword" 111 "}}buildtypes {release {// here is the step for generating the apk. For details, refer to the remarks. // 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'} productFlavors {// a multi-channel location, AndroidManifest. the xml file must be marked. the following file will be pasted: yingyongbao {manifestPlaceholders = [CHANNEL_NAME: "YINGYONGBAO"]} umeng {manifestPlaceholders = [CHANNEL_NAME: "UMENG"]} wandoujia {manifestPlaceholders = [CHANNEL_NAME: "WANDOUJIA"]} allprojects {// here is an external import file, and then change the attributes of the file, only the signature is changed here. You can also change other afterEvaluate {project-> def propsFile = rootProject. file ('e: \ keystore. properties ') def configName = 'myconfig' if (propsFile. exists () & android. signingConfigs. hasProperty (configName) {def props = new Properties () props. load (new FileInputStream (propsFile) android. signingConfigs [configName]. storeFile = file (props ['storefile']) android. signingConfigs [configName]. storePassword = props ['storepassword'] android. signingConfigs [configName]. keyAlias = props ['keyalias'] android. 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/
 
  
// For instance, build-types/debug/java, build-types/debug/AndroidManifest. xml,... // This moves them out of them default location under src/
  
   
/... 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 ')}}
  
 
You can view the remarks for the specific functions here. It is okay to paste the brute force information. Below we will post several files. One is the AndroidManifest. xml file, which adds a line.

 

 

 
 
Build. xml adds a target, and uses the cmd command to write gradle deploy to execute the content.
        
       
  
   
    
   
  
   
There is also a signature file
storeFile=E:\\keystore\\mydemo.keystorestorePassword=276021750keyPassword=276021750keyAlias=mydemo.keystore

You can download the demo here.

Http://download.csdn.net/detail/killer1989/8927225

We can see the benefits of using ant to change the file information. Here we specialize in multi-channel packaging, which can be separated. In fact, there are two steps to be fully automated. One is to automatically obtain the information from svn, there are many versions available for learning on the Internet, and the other is to use scripts to modify the build. gradle file, dynamically changing the signature (in fact, you can also make batch modifications) and dynamically adding code for these features, you can use shell, you can use python, you can try it

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.