Android - Gradle系列文章
Gradle 是一种多用途的构建工具. 它可以在你的构建脚本里构建任何你想要实现的东西,类似Linux下的make;
【参考来源:http://code.tutsplus.com/tutorials/the-ins-and-outs-of-gradle--cms-22978】
Top-Level Gradle Build File
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | buildscript { //Project-level Gradle build files use buildscript to define dependencies.// repositories { jcenter() } //This file relies on the jJCenter repository.// dependencies { classpath 'com.android.tools.build:gradle:1.0.0' //Project is dependent on version 1.0.0 of the Android plugin for Gradle.// } } allprojects { //Defines the dependencies required by your application.// repositories { jcenter() } } //Application depends on the jCenter repository.// |
Module-Level Gradle Build Files
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | apply plugin: 'com.android.application' //Since this project is an Android app, the build.gradle file utilises the Android plugin.// android { //The following section configures all your project’s Android-specific parameters, <br>//and tells Gradle which version of Android it should build your project with. <br>//If you’ve developed Android applications before, the following should all be familiar.// compileSdkVersion 21 //The API your project is targeting.// buildToolsVersion "21.1.1" ////The version of the build tools you want to use.// defaultConfig { applicationId "com.example.jessica.myapplication" //Defines your application’s ID. Note, earlier versions of the Android plugin used ‘packageName’ instead of ‘applicationID.’// minSdkVersion 16 //The minimum API required by your project.// targetSdkVersion 21 //The version of Android you’re developing your application for.// versionCode 1 versionName "1.0" } buildTypes { release { //‘BuildTypes’ controls how your app is built and packaged. If you want to create your own build variants, you’ll need to add them to this section.// minifyEnabled true //Gradle runs ProGuard during the build process.// proguardFiles getDefaultProguardFile( 'proguard-android.txt' ), 'proguard-rules.pro' //Applies the default ProGuard settings from the Android SDK.// } } } dependencies { //Declares the dependencies for the current module.// compile fileTree(dir: 'libs' , include: [ '*.jar' ]) //Although you can add JAR files by compiling them individually, this can be time-consuming if you have lots of JARs. <br>//In this example, we’re telling Gradle to add all the JAR files in the app/libs folder.// compile 'com.android.support:appcompat-v7:21.0.3' //To create more dependencies, add them to the depencies closure.// } |
gradle-wrapper.properties (Gradle Version)
This file allows other people to build your code, even if they don't have Gradle installed on their machine.
This file checks whether the correct version of Gradle is installed and downloads the necessary version if necessary.
In our sample app, gradle-wrapper.properties contains the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | distributionBase=GRADLE_USER_HOME //Determines whether the unpacked wrapper distribution should be stored in the project, or in the Gradle user home directory.// distributionPath=wrapper/dists //The path where the Gradle distributions required by the wrapper are unzipped.// zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\: //services.gradle.org/distributions/gradle-2.2.1-all.zip //The URL where the correct version of Gradle should be downloaded from.// |
http://tools.android.com/tech-docs/new-build-system/user-guide
0、Gradle 插件 官方文档
http://stormzhang.com/android/2016/07/02/gradle-for-android-beginners/
0、给 Android 初学者的 Gradle 知识普及
http://stormzhang.com/devtools/2015/06/17/android-studio-all/
1、Gradle基础
2、Gradle命令详解与导入第三方包
3、Gradle多渠道打包
http://stormzhang.com/android/2016/03/13/gradle-config/
4、Gradle依赖的统一管理
http://stormzhang.com/android/2014/02/28/android-gradle/
5、Gradle介绍
https://www.gitbook.com/@dongchuan
6、Gradle User Guide 中文版
http://avatarqing.github.io/Gradle-Plugin-User-Guide-Chinese-Verision/
7、Gradle Android插件使用指南中文版
http://stormzhang.com/android/2015/01/25/gradle-build-field/
8、Gradle自定义你的BuildConfig
http://stormzhang.com/android/2015/03/01/android-reference-local-aar/
9、Android模块化编程之引用本地的aar
10、Gradle build生成签名APK
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | android { signingConfigs { release { storeFile file( "myrelease.keystore" ) storePassword "********" keyAlias "******" keyPassword "******" } } buildTypes { release { signingConfig signingConfigs.release } } } |
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步