Gradle常用命令
上面大家接触了一些命令如 ./gradlew -v ./gradlew clean ./gradlew build, 这里注意是./gradlew, ./代表当前目录,gradlew代表 gradle wrapper,意思是gradle的一层包装,大家可以理解为在这个项目本地就封装了gradle,即gradle wrapper, 在9GAG/gradle/wrapper/gralde-wrapper.properties文件中声明了它指向的目录和版本。只要下载成功即可用grdlew wrapper的命令代替全局的gradle命令。
理解了gradle wrapper的概念,下面一些常用命令也就容易理解了。
./gradlew -v 版本号
./gradlew clean 清除9GAG/app目录下的build文件夹
./gradlew build 检查依赖并编译打包
这里注意的是 ./gradlew build 命令把debug、release环境的包都打出来,如果正式发布只需要打Release的包,该怎么办呢,下面介绍一个很有用的命令 assemble, 如
./gradlew assembleDebug 编译并打Debug包
./gradlew assembleRelease 编译并打Release的包
除此之外,assemble还可以和productFlavors结合使用,具体在下一篇多渠道打包进一步解释。
./gradlew installRelease Release模式打包并安装
./gradlew uninstallRelease 卸载Release模式包
下一篇来介绍用Gradle进行方便的多渠道打包,以及项目中完整的Gradle配置。有问题或建议欢迎大家直接博客留言。
<code><meta-data
android:name="UMENG_CHANNEL"
android:value="Channel_ID" ><code>
<code><meta-data
android:name="UMENG_CHANNEL"
android:value="${UMENG_CHANNEL_VALUE}" ><code>
<code>android {
productFlavors {
xiaomi {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "xiaomi"]
}
_360 {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "_360"]
}
baidu {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "baidu"]
}
wandoujia {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
}
}
}</code>
<code>android {
productFlavors {
xiaomi {}
_360 {}
baidu {}
wandoujia {}
}
productFlavors.all {
flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
}</code>
<code>apply plugin: 'com.android.application'
def releaseTime() {
return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC")) }
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.boohee.*"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
// dex突破65535的限制
multiDexEnabled true // 默认是umeng的渠道
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "umeng"]
}
lintOptions {
abortOnError false }
signingConfigs {
debug {
// No debug config }
release {
storeFile file("../yourapp.keystore") storePassword "your password"
keyAlias "your alias"
keyPassword "your password"
}
}
buildTypes {
debug {
// 显示Log
buildConfigField "boolean", "LOG_DEBUG", "true"
versionNameSuffix "-debug"
minifyEnabled false zipAlignEnabled false shrinkResources false signingConfig signingConfigs.debug }
release {
// 不显示Log
buildConfigField "boolean", "LOG_DEBUG", "false"
minifyEnabled true zipAlignEnabled true // 移除无用的resource文件
shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
applicationVariants.all { variant -> variant.outputs.each { output -> def outputFile = output.outputFile if (outputFile != null && outputFile.name.endsWith('.apk')) {
// 输出apk名称为booheev1.0_2015-01-15_wandoujia.apk def fileName = "boohee_v${defaultConfig.versionName}${releaseTime()}_${variant.productFlavors[0].name}.apk"
output.outputFile = new File(outputFile.parent, fileName) }
}
}
}
}
// 友盟多渠道打包
productFlavors {
wandoujia {}
_360 {}
baidu {}
xiaomi {}
tencent {}
taobao {}
…
}
productFlavors.all { flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:support-v4:21.0.3'
compile 'com.jakewharton:butterknife:6.0.0'
…
}</code>
大家有问题或疑问、建议欢迎博客留言,Android Studio的教程暂且到这里结束了,相信大家基本的都已会使用了,还有其他技巧与操作靠大家自己摸索了,之后有时间也会在博客上整理下一些Tips之类的,欢迎大家关注。