Android gradle build

Source: Internet
Author: User

It is troublesome to compile an ant script from the school. It is not very simple and the dependency is okay. The speed is good. A long time ago, Daniel wanted me to recommend gradle, which is much better than ant. Now, it is true that gradle was not officially supported in Android at that time,

A few days ago, I updated the ant script and suddenly thought I should try again. Some of the ways could not go straight, but the curve saved the country. I learned more about it because I wanted to re-Modify the jar source code and download it, I plan to test it and find that the dependency is not satisfied, and then Maven does not have this jar. Let's stop, update the source code, the network is not powerful, and the old times out.

Right-click the project and export it. For example, select generate gradle build files.

Select the project to be generated and complete

Then open build. by default, gradle generates COM. android. tools. build: gradle: 0.4 to com. android. tools. build: gradle: 0.4.2 the latest database. check it on the maven database.

,

Buildscript {repositories {mavencentral ()} dependencies {classpath 'com. android. tools. build: gradle: 0.4.2 '// The dependency is required currently 0.4.2 go to Google for details} apply Plugin: 'android' dependencies {compile filetree (DIR: 'libs', include: '*. jar ') // compile the jar files in libs} Android {compilesdkversion 8 buildtoolsversion "17.0.0" buildtypes {// set information such as debug release {runproguard trueproguardfile upload ')
Signingconfig signingconfigs. myconfig // set the signature configuration} signingconfigs {// The signature information can be customized to many debug {storefile file ("debug. keystore ")} myconfig {storefile file (" debug. keystore ") storepassword" android "keyalias" androiddebugkey "keypassword" android "}}sourcesets {main {// compile the configuration. Check the source code. manifest is rarely documented. srcfile 'androidmanifest. XML 'java. srcdirs = ['src'] resources. srcdirs = ['src'] aidl. srcdirs = ['src'] renderscript. srcdirs = ['src'] res. srcdirs = ['res'] assets. srcdirs = ['assets']} instrumenttest. setroot ('tests ')}//
// Productflavors: This is the channel package, and ant can actually do it. The more powerful one is flavor1, which has different package names and version numbers.

Productflavors {flavor1 {packagename "com. example. flavor1" versioncode 20} flavor2 {packagename "com. example. flavor2" minsdkversion 14 }}}

 

Compiling and using gradle build will compile the debug and signature packages at a proper speed. The build APK directory contains various packages, so I didn't put the keystore, so there is no signature.

When using gradle, you often need to control the process and use hooks. It is very easy to import the ant script. importbuild 'build. the XML file can be directly imported into the script and then registered into the task by gradle. At the beginning of the study, there is a book on the very powerful gradle official website that can be downloaded for free. The English version is quite simple to write, want to study can take a look at the http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Types Google documentation, not very full, a lot of NO, or Google
It should be very simple to search for groovy. After getting familiar with it, I feel very useful. Some things have been directly transferred from ANT import, and some things have to be complicated again.

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.