首页 > 代码库 > Gradle 编译学习笔录
Gradle 编译学习笔录
-
Gradle下载与配置
下载路径: http://www.gradle.org/downloads
配置: 下载完gradle后, 解压缩到你的目录盘, 然后打开gradle的bin目录并将其路径复制, 打开环境变量, 将复制的内容加到Path中。
配置完毕后,可以打开cmd命令工具, 运行gradle –version 如果出现正确的版本号 那么将配置成功 !
Gradle简单命令介绍
build 编译命令: 使用cmd命令进入到项目目录下, 然后运行gradle build . 编译成功后可以在build/目下下查看文件
clean 命令: gradle clean 可以清除上一次build后的文件。
check 命令:gradle check 可以使编译用上类似checkstyle文件对项目进行检查。
build.gradle 代码详细介绍
<style type="text/css">.src_container{background-color:#e7e5dc; width:99%; overflow:hidden; margin:12px 0 12px 0 !important; padding:0px 3px 3px 0px}.src_container .titlebar{ background-color:#d4dfff; border:1px solid #4f81bd; border-bottom:0; padding:3px 24px; margin:0; width:auto; line-height:120%; overflow:hidden; text-align:left; font-size:12px}.src_container .toolbar{ display:inline; font-weight:normal; font-size:100%; float:right; cursor:hand; color:#00f; text-align:left; overflow:hidden}.toolbar span.button{ display:inline; font-weight:normal; font-size:100%; cursor:hand; color:#00f; text-align:left; overflow:hidden; cursor:pointer;}.src_container div.clientarea{ background-color:white; border:1px solid #4f81bd; margin:0; width:auto !important; width:100%; height:auto; overflow:auto; text-align:left; font-size:12px; font-family: "Courier New","Consolas","Fixedsys",courier,monospace,serif}.src_container ol.mainarea{ padding:0 0 0 52px; margin:0; background-color:#f7f7ff !important}.number_show{ padding-left:52px !important; list-style:decimal outside !important}.number_show li{ list-style:decimal outside !important; border-left:1px dotted #4f81bd}.number_hide{ padding-left:0px !important; list-style-type:none !important}.number_hide li{ list-style-type:none !important; border-left:0px}ol.mainarea li{ display:list-item !important; font-size:12px !important; margin:0 !important; line-height:18px !important; padding:0 0 0 0px !important; background-color:#f7f7ff !important; color:#4f81bd}ol.mainarea li pre{color:black; line-height:18px; padding:0 0 0 12px !important; margin:0em; background-color:#fff !important}.linewrap ol.mainarea li pre{white-space:pre-wrap; white-space:-moz-pre-wrapwhite-space:-pre-wrap; white-space:-o-pre-wrap; word-wrap:break-word}ol.mainarea li pre.alt{ background-color:#f7f7ff !important}</style><style type="text/css">.src_container{background-color:#e7e5dc; width:99%; overflow:hidden; margin:12px 0 12px 0 !important; padding:0px 3px 3px 0px}.src_container .titlebar{ background-color:#d4dfff; border:1px solid #4f81bd; border-bottom:0; padding:3px 24px; margin:0; width:auto; line-height:120%; overflow:hidden; text-align:left; font-size:12px}.src_container .toolbar{ display:inline; font-weight:normal; font-size:100%; float:right; cursor:hand; color:#00f; text-align:left; overflow:hidden}.toolbar span.button{ display:inline; font-weight:normal; font-size:100%; cursor:hand; color:#00f; text-align:left; overflow:hidden; cursor:pointer;}.src_container div.clientarea{ background-color:white; border:1px solid #4f81bd; margin:0; width:auto !important; width:100%; height:auto; overflow:auto; text-align:left; font-size:12px; font-family: "Courier New","Consolas","Fixedsys",courier,monospace,serif}.src_container ol.mainarea{ padding:0 0 0 52px; margin:0; background-color:#f7f7ff !important}.number_show{ padding-left:52px !important; list-style:decimal outside !important}.number_show li{ list-style:decimal outside !important; border-left:1px dotted #4f81bd}.number_hide{ padding-left:0px !important; list-style-type:none !important}.number_hide li{ list-style-type:none !important; border-left:0px}ol.mainarea li{ display:list-item !important; font-size:12px !important; margin:0 !important; line-height:18px !important; padding:0 0 0 0px !important; background-color:#f7f7ff !important; color:#4f81bd}ol.mainarea li pre{color:black; line-height:18px; padding:0 0 0 12px !important; margin:0em; background-color:#fff !important}.linewrap ol.mainarea li pre{white-space:pre-wrap; white-space:-moz-pre-wrapwhite-space:-pre-wrap; white-space:-o-pre-wrap; word-wrap:break-word}ol.mainarea li pre.alt{ background-color:#f7f7ff !important}</style>build.gradle
buildscript { ##### 大意就是支持java 依赖库管理(maven/ivy),用于项目的依赖。这也是gradle 强力的地方。。。 ## How does Gradle find the files for external dependencies? Gradle looks for them in a repository. ## A repository is really just a collection of files, organized by group, name and version. ## Gradle understands several different repository formats, such as Maven and Ivy, ## and several different ways of accessing the repository, such as using the local file system or HTTP. repositories { #### 至少声明一个类型, 如果不用maven的话, 默认的就是这个了。 #### mavenCentral() ## a remote Maven repository ## maven{ url "http://10.10.20.10:8080/nexus/content/groups/public" } } ### 依赖什么版本的Gradle编译工具 ### dependencies { classpath ‘com.android.tools.build:gradle:0.9.2‘ } } #### 编译项目类型 #### apply plugin: ‘android‘ ### 编译第三方包 ### dependencies { # 编译所有libs下的第三方包 # compile fileTree(dir: ‘libs‘, include: ‘*.jar‘) # 编译一个Lib包 # compile files("libs\android-support-v4.jar"); } ### 配置项 ### android { compileSdkVersion 19 buildToolsVersion "19" defaultConfig { minSdkVersion 14 targetSdkVersion 19 } #### 配置release版本的签名项目以及代码混淆 #### signingConfigs { myConfig{ storeFile file("gradle.keystore") storePassword "gradle" keyAlias "gradle" keyPassword "gradle" ### 配置使用代码混淆 ### runProguard true proguardFile ‘proguard-android.txt‘ } } #### 编译版本 (release和debug版本) #### buildTypes{ release { signingConfig signingConfigs.myConfig } debug { packageNameSuffix ".debug" } } #### 配置多渠道 (playstore 与 hiapk) 改变不同渠道的包名 #### productFlavors { playstore { packageName=‘com.youxiachai.androidgradle.playstore‘ } hiapk { packageName=‘com.youxiachai.androidgradle.amazonappstore‘ } } sourceSets { main { manifest.srcFile ‘AndroidManifest.xml‘ java.srcDirs = [‘src‘] resources.srcDirs = [‘src‘] aidl.srcDirs = [‘src‘] renderscript.srcDirs = [‘src‘] res.srcDirs = [‘res‘] assets.srcDirs = [‘assets‘] jniLibs.srcDirs = [‘libs‘] } ### 不同渠道可以应用不同的文件 ### hiapk { manifest.srcFile ‘hiapk/AndroidManifest.xml‘ } playstore { manifest.srcFile ‘hiapk/AndroidManifest.xml‘ } ### 配置android测试 ### instrumentTest.setRoot(‘tests‘) } ### 使用lint检测 ### lintOptions { abortOnError false } }
参考资料来源声明
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 使用:
- 参考资料
地址: http://jingyan.baidu.com/article/60ccbceb01de4d64cbb19756.html
Nexus 搭建私服:
- 参考资料:
地址: http://www.blogjava.net/ldwblog/archive/2013/11/19/406529.html
- 版本选择:
JDK6 选择nexus 2.6一下版本, 否则启动不了。 nexus2.6以上版本需要JDK7
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。