App build.gradle
apply plugin: 'com.android.application'
apply plugin: 'android-apt'def AAVersion = '3.0.1'
//修改keystore自己的路径
def KeyStoreFile = 'test.keystore'
def KeyStorePwd = '111'
def KeyStoreAlias = 'test_web.keystore'
def KeyPwd = 'nowqw'
android {
compileSdkVersion 17
buildToolsVersion '21.1.2'
/**渠道名称**/
productFlavors {
xiaomi {}
_360 {}
baidu {}
wandoujia {}
}
/**指向manifest中自定义变量**/
productFlavors.all {
flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
/**签名设置**/
signingConfigs {
icsonConfig {
storeFile file("$KeyStoreFile")
storePassword "$KeyStorePwd"
keyAlias "$KeyStoreAlias"
keyPassword "$KeyPwd"
}
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java', 'build/generated/source/apt/${variant.dirName}']
resources.srcDirs = ['src/main/resources']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
}
}
defaultConfig {
applicationId "com.icson"
minSdkVersion 10
targetSdkVersion 21
versionCode 33
versionName "v2.3.7"
}
buildTypes {
//debug发布
debug {
// 显示Log
buildConfigField "boolean", "LOG_DEBUG", "true"
versionNameSuffix "-debug"
minifyEnabled false
zipAlignEnabled false
shrinkResources false
signingConfig signingConfigs.icsonConfig
}
//release模式发布
release {
//不显示Log
buildConfigField "boolean", "LOG_DEBUG", "false"
signingConfig signingConfigs.icsonConfig
/**表示开始使用代码混淆如果混淆请设置为true**/
minifyEnabled false
zipAlignEnabled true
// 移除无用的resource文件
shrinkResources true
/**代码混淆使用**/
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
/**渠道apk成型**/
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
// 输出apk名称为51Buy_v3.*.*_channlename.apk
def fileName = "51Buy_${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
}
}
dependencies {
compile project(':sss_common_viewlib')
compile project(':sss_common_lib')
compile project(':sss_common_module')
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName 'com.icson'
}
}
/*****
./gradlew assembleRelease //打出所有渠道包
./gradlew assembleWandoujiaRelease //只打某个渠道的发布包
./gradlew assembleWandoujia //只打某个渠道debug和发布包
./gradew clean;
./gradlew assembleDebug 编译并打Debug包
./gradlew installRelease Release模式打包并安装
./gradlew uninstallRelease 卸载Release模式包
****/
project build.gradle
buildscript {
repositories {
//jcenter()
mavenCentral()
}
dependencies {//这里我认为只是设定脚本运行需要的依赖的东西
classpath 'com.android.tools.build:gradle:1.0.0' //android gradle 插件版本,而非gradle本身,此说法参见http://www.cnblogs.com/youxilua/p/3348162.html
//这就好像我们下载个SVN客户端在电脑上直接使用,要在eclipse里面直接使用还不行,需要我们在eclipse里面集成SVN插件一个道理
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'//apt是处理注解的解析器
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
//jcenter()
mavenCentral()
mavenLocal()
}
}
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://localhost:8080/gradle-2.2.1-all.zip
这里原本是一个网络路径,后面我在tomcat下本地下载一下,就可以避免再去网络下载
另外此路径一旦变更,gradlew命令首次运行时候就会去按照此路径去下载
产生的APK文件位置
...app\build\outputs\apk