Gradle Android client package, gradleandroid

Source: Internet
Author: User

Gradle Android client package, gradleandroid

  

I. Preface
When android client development came to an end, my SEO colleague suddenly sent me a message about 45 release channels. Previously, I only published my own channel work mode (manually modified the parameter package) and it was no longer sufficient, so we introduced the recently popular gradle packaging technology.
Gradle is based on the groovy language, and the reason for the introduction is also convenient to migrate from the current eclipse development environment to Android Studio, so blablabla ......, Let's not talk about it. Let's get the goods first.

2. Preparations
1. If eclipse is used as the development environment, right-click the project and select "Export…" from the menu ..."
2. Select "Android-> Generate Gradle build files" in the pop-up list"
3. Select "Next>"
4. Select "Next>"
5. Select the project in which you want to create the gradle configuration script in the list and continue "Next>"
6. Select "Finish"
At this point, the gradle configuration script has been generated in eclipse. You may need to right-click to refresh the project.

Iii. Configure the Gradle packaging script in a simple project
Buildscript {repositories {jcenter ()} dependencies {classpath 'com. android. tools. build: gradle: 0.12. + '} // The project configuration version, which is consistent with the apk output directory ext. appVersionCode = 2ext. appVersionName = "2.0" ext. appReleaseDir = "/Users/freedoms/Desktop/release" apply plugin: 'com. android. application '// obtain the timestamp def getDate () {def date = new Date () def formattedDate = date. format ('yyyymmdd') return formattedDate} // configure android {compileSdkVersion 19 buildToolsVersion "21.1.2" sourceSets {main {manifest. srcFile 'androidmanifest. xml 'java. srcDirs = ['src'] resources. srcDirs = ['src'] aidl. srcDirs = ['src'] renderscript. srcDirs = ['src'] res. srcDirs = ['res'] assets. srcDirs = ['assets'] // The so package is included in the project. You need to add the jni directory configuration. Otherwise, the jniLibs error will occur when the program is running so. srcDir (['libs'])} instrumentTest. setRoot ('tests') debug. setRoot ('Build-types/debug') release. setRoot ('Build-types/release')} // when the package starts, lint running may encounter errors. When an exception occurs, this setting ignores the warning, continue to run the script. If the script is ignored, the packaging process will be forcibly terminated by lintOptions {abortOnError false} // signingConfigs {myConfig {storeFile file ("/Users/freedoms/Desktop/product requirement document/android. keystore ") storePassword" 123123 "keyAlias" android. keystore "keyPassword" 123123 "}}// mixed configuration buildTypes {release {signingConfig signingConfigs. myConfig
// You do not need to set obfuscation to false runProguard true proguardFiles getdefadefaproguardfile('proguard-android.txt '), 'proguard-project.txt'} // custom configuration productFlavors {// baidu {
// AndroidManifest. complete the placeholder configuration defined in the xml configuration, which is in the AndroidManifest instance. configure "$ {UMENG_CHANNEL_VALUE}" in xml. After the script is run, the baidu_android_channel is automatically replaced with this location, AndroidManifest. for other xml parameters that need to be dynamically configured by channels, refer to this procedure manifestPlaceholders = [UMENG_CHANNEL_VALUE: "baidu_android_channel", BAIDU_CHANNEL_VALUE: "channels"]} // 360 "360" {// If the channel name starts with a number, you must quote manifestPlaceholders = [UMENG_CHANNEL_VALUE: "360_android_channel", BAIDU_CHANNEL_VALUE: "channels"]}.
// You can refer to the above two items for extension ......} // Input the xxx_android_v2.0_201601__baidu.apk to the output directory configured before the script. applicationVariants. all {variant-> def file = variant. outputFile if (variant. buildType. name. equals ('release') {variant. outputFile = new File (appReleaseDir + '/', 'xxx _ Android_v '+ appVersionName + getDate () +' _ '+ variant. productFlavors [0]. name + '.apk ') }}// coding configuration tasks. withType (Compile) {options. encoding = "UTF-8 "}

Iv. Configure the gradle packaging script with project dependency
1. dependent projects
A) if you use eclipse as the development environment, you must first generate the gradle configuration script (see section 2. preparation)
B) modify apply in the gradle script to set the following configurations:
apply plugin: 'android-library'

C) For other configurations of the same master project, refer to the gradle script configuration of the simple project.

2. Main project

A) if you use eclipse as the development environment, you must first generate the gradle configuration script (see section 2. preparation)

B) modify apply in the gradle script to set the following configurations:

apply plugin: 'com.android.application'

C) Create the setting. gradle text file under the root directory of the main project to reference the dependency project configuration.

// Introduce the dependent project name
Include 'library' include 'library _ pullToRefresh '// create a directory reference. The quotation marks are the absolute path project (': library') stored by the dependent project '). projectDir = new File ('/Users/freedoms/git/library') project (': library_pullToRefresh '). projectDir = new File ('/Users/freedoms/git/library_pullToRefresh ')

D) Add the following configuration in build. gradle of the main project:

// Dependency configuration dependencies {compile fileTree (dir: 'libs', include: '*. jar') compile project (': library_pullToRefresh ') compile project (': library ')}

5. Run the build script
1. cd to the root directory of the main project in the command line
2. Enter gradle clean to execute (clean up the check file generated by gradle and the generated APK, but there is no guarantee that there will be any strange problems in the middle, so it is a good habit to develop)
3. Enter gradle check to run the check item. The time required varies depending on the number of channels)
4. Enter gradle build to execute (execute the build script and start packaging. The time required varies depending on the number of channels, and the 45 channels will take more than one hour)
5. Check the output directory of build. gradle configuration of the main project. The channel package is already in it.

Vi. Precautions (to be continued)
Q1: the following error may be reported during check or build.
FAILURE: Build failed with an exception.* What went wrong:Execution failed for task ':lint'.> Lint found errors in the project; aborting build.  Fix the issues identified by lint, or add the following to your build script to proceed with errors:  ...  android {      lintOptions {          abortOnError false      }  }  ...* Try:Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.BUILD FAILED

A1: added in the build. gradle script

    lintOptions {          abortOnError false    }

Q2: the Java Virtual Machine memory insufficiency may be reported during packaging based on the number of channels.

The system is out of resources.Consult the following stack trace for details.java.lang.OutOfMemoryError: Java heap space    at com.sun.tools.javac.util.Position$LineMapImpl.build(Position.java:139)    at com.sun.tools.javac.util.Position.makeLineMap(Position.java:63)    at com.sun.tools.javadoc.DocCommentScanner.getLineMap(DocCommentScanner.java:438)    at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:512)    at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:550)    at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:804)    at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)    at com.sun.tools.javac.main.Main.compile(Main.java:353)    at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:115)

A2: Reduce the number of packaging channels at a time, and then package another channel (curve saving)



 

Related Article

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.