Gradle compilation learning transcript

Source: Internet
Author: User
Tags checkstyle
  • Gradle download and Configuration
Http://www.gradle.org/downloads download path

Configuration: After downloading gradle, decompress it to your directory disk, open the bin directory of gradle, copy its path, open the environment variable, and add the copied content to the path.

After the configuration is complete, open the CMD command tool and run gradle-version. If the correct version number is displayed, the configuration is successful!

  • Introduction to gradle simple commands
Build compilation command: run the CMD command to enter the project directory, and then run gradle build. After compilation is successful, you can view the file under build/project.

Run the clean command: gradle clean to clear files after the previous build.

Check command: gradle check allows you to use a checkstyle file similar to the checkstyle file for project check.

  • Build. gradle code details

Hide row number copy code? Build. gradle
  1. buildscript {
  2. ##### The general idea is to support Java dependency library management (Maven/Ivy) for project dependencies. This is where gradle is powerful...
  3.     ## How does Gradle find the files for external dependencies? Gradle looks for them in a repository. 
  4.     ## A repository is really just a collection of files, organized by group, name and version.
  5.     ## Gradle understands several different repository formats, such as Maven and Ivy, 
  6.     ## and several different ways of accessing the repository, such as using the local file system or HTTP.
  7.     repositories {
  8. #### Declare at least one type. If Maven is not used, this is the default type. ####
  9.         mavenCentral()
  10.         
  11.         ## a remote Maven repository ##
  12.         maven{
  13.             url "http://10.10.20.10:8080/nexus/content/groups/public"
  14.         }
  15.         
  16.     }
  17. ### Version of The gradle compilation tool ###
  18.     dependencies {
  19.         classpath ‘com.android.tools.build:gradle:0.9.2‘
  20.     }
  21. }
  22. #### Compile the project type ####
  23. apply plugin: ‘android‘
  24. ### Compile a third-party package ###
  25. dependencies {
  26. # Compile third-party packages under all libs #
  27.     compile fileTree(dir: ‘libs‘, include: ‘*.jar‘)
  28. # Compile a lib package #
  29.     compile files("libs\android-support-v4.jar");
  30. }
  31. ### Configuration items ###
  32. android {
  33.     
  34.     compileSdkVersion 19
  35.     buildToolsVersion "19"
  36.     
  37.     defaultConfig {
  38.         minSdkVersion 14
  39.         targetSdkVersion 19
  40.     }
  41. #### Configure the release signature project and code obfuscation ####
  42.     signingConfigs {
  43.         myConfig{
  44.             storeFile file("gradle.keystore")
  45.             storePassword "gradle"
  46.             keyAlias "gradle"
  47.             keyPassword "gradle"
  48. ### Use code obfuscation ###
  49.             runProguard true
  50.             proguardFile ‘proguard-android.txt‘
  51.         }
  52.     }
  53. #### Compiled versions (Release and DEBUG Versions )####
  54.     buildTypes{
  55.         release {
  56.             signingConfig  signingConfigs.myConfig
  57.         }
  58.         
  59.         debug {
  60.             packageNameSuffix ".debug"
  61.         }
  62.     }
  63. #### Change the package name of different channels through multiple channels (playstore and hiapk ####
  64.     productFlavors {
  65.         playstore {
  66.             packageName=‘com.youxiachai.androidgradle.playstore‘
  67.         }
  68.         hiapk {
  69.             packageName=‘com.youxiachai.androidgradle.amazonappstore‘
  70.         }
  71.     }
  72.     
  73.     sourceSets {
  74.         main {
  75.             manifest.srcFile ‘AndroidManifest.xml‘
  76.             java.srcDirs = [‘src‘]
  77.             resources.srcDirs = [‘src‘]
  78.             aidl.srcDirs = [‘src‘]
  79.             renderscript.srcDirs = [‘src‘]
  80.             res.srcDirs = [‘res‘]
  81.             assets.srcDirs = [‘assets‘]
  82.             jniLibs.srcDirs = [‘libs‘]
  83.         }
  84. ### Different files can be applied through different channels ###
  85.         hiapk {
  86.                manifest.srcFile ‘hiapk/AndroidManifest.xml‘
  87.            }
  88.            
  89.            playstore {
  90.                manifest.srcFile ‘hiapk/AndroidManifest.xml‘
  91.            }
  92.     
  93. ### Configure Android testing ###
  94.         instrumentTest.setRoot(‘tests‘)
  95.     }
  96. ### Use lint detection ###
  97.     lintOptions {
  98.         abortOnError false
  99.     }
  100. }

 

  • References source declaration 1. https://gist.github.com/youxiachai/5608223

2. http://www.cnblogs.com/youxilua/archive/2013/05/20/3087935.html

3. https://github.com/Goddchen/Android-Gradle-Examples

 

Maven usage:

  • References

Address: http://jingyan.baidu.com/article/60ccbceb01de4d64cbb19756.html

  •  

Build private servers for nexus:

  • References:

Address: http://www.blogjava.net/ldwblog/archive/2013/11/19/406529.html

  • Version selection:

JDK 6 selects the Nexus 2.6 version. Otherwise, it cannot be started. JDK 7 is required for nexus2.6 and later versions.

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.