gradlew 命令
快速构建命令
- 查看所有任务
./gradlew tasks --all
- gradlew命令都可以使用简写,例如:
./gradlew assembleRelease 简写为:./gradlew aR
- 查看项目的依赖都依赖了哪些库。
gradlew :app:dependencies
- 只编译清单文件,并查看具体日志,快速定位清单文件报错
gradlew :app:processDebugManifest --stacktrace:
- 清除build文件夹
./gradlew clean
- 检查依赖并编译打包
./gradlew build
- 编译并安装debug包
./gradlew installDebug
- 编译并打印日志
./gradlew build --info
- 调试模式构建并打印日志
./gradlew build --info --debug --stacktrace
- 强制更新最新依赖,清除构建并构建
./gradlew clean --refresh-dependencies build
注意build命令把 debug、release环境的包都打出来的如果需要指定构建使用如下命令
指定构建目标命令
- 编译并打Debug包
./gradlew assembleDebug
简写
./gradlew aD
- 编译并打Release的包
./gradlew assembleRelease
简写
./gradlew aR
构建并安装调试命令
- 编译app module 并打Debug包
./gradlew install app:assembleDebug
- Release模式打包并安装
./gradlew installRelease
- 卸载Release模式包
./gradlew uninstallRelease
多渠道打包
assemble还可以和productFlavors结合使用,如果出现类似 Task’install’isambiguousinroot project 这种错误,请查看配置的多个渠道然后修改命令为./gradlew install[productFlavorsName] app:assembleDebug
来用命令构建调试
- Release模式 test 渠道打包
./gradlew assembleTestRelease
- debug release模式全部渠道打包
./gradlew assemble
- 查看包依赖
./gradlew dependencies
- 编译时的依赖库
./gradlew app:dependencies --configuration compile
- 运行时的依赖库
./gradlew app:dependencies --configuration runtime
依赖管理
传递依赖特性
dependencies { transitivetrue}
手动配置transitive属性为false,阻止依赖的下载
强制
configurations.all{// transitive false// 强制指定版本resolutionStrategy{ force’org.hamcrest:hamcrest-core:1.3’// 强制不编译all*.excludegroup:‘org.hamcrest’,module:‘hamcrest-core’}}
动态依赖特性
dependencies {// 任意一个版本compile group:‘b’,name:‘b’,version:‘1.+’// 最新的版本compile group:‘a’,name:‘a’,version:‘latest.integration’}
查看详细依赖信息
- 使用离线模式
./gradlew aDR --offline
- 守护进程
./gradle build --daemon
- 并行编译模式
./gradle build --parallel --parallel-threads=N
- 按需编译模式
./gradle build --configure-on-demand
- 不使用snapshot依赖仓库
前提是离线可以使用时
./gradlew clean aDR
设定编码
allprojects {… tasks.withType(JavaCompile){ options.encoding =“UTF-8”}…}
仓库设置
- 设置中心仓库
默认是jcenter、可以是mavenCentral
repositories { maven { url"http://maven.oschina.net/content/groups/public"}}
Android Studio 提速
禁用插件
去掉一些没有用的插件
Google Cloud Testing、Google Cloud Tools For Android Studio、Goole Login、Google Services、JavaFX、SDK Updater、TestNG-J欢迎使用ShowDoc!