用gradle生成debug和release包的问题。
问题1:直接在android studio里面run app和debug app生成的包应该都是debug模式的吧?
问题2:我想run app和debug app的时候指定生成的apk包名,但是生成名字却是release模式指定的名字。我生成release包用的命令是gradlew assemblerelease.
下面是我的build.gradle文件。
apply plugin: 'com.android.application'
def releaseTime() {
return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId 'com.xuetubao.android'
//为了调试暂时调高
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
packagingOptions {
exclude 'project.properties'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
lintOptions {
abortOnError false
}
signingConfigs {
debug {
// No debug config
}
release {
storeFile file *******
storePassword ********
keyAlias *******
keyPassword ********* }
}
buildTypes {
debug {
// 显示Log
buildConfigField "boolean", "LOG_DEBUG", "true"
versionNameSuffix "-debug"
minifyEnabled false
zipAlignEnabled false
shrinkResources false
}
release {
// 不显示Log
buildConfigField "boolean", "LOG_DEBUG", "false"
minifyEnabled false
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名称为boohee_v1.0_2015-01-15_wandoujia.apk
def fileName = "xtb_v${defaultConfig.versionName}_${releaseTime()}_${variant.productFlavors[0].name}.apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
}
repositories {
flatDir {
dirs 'libs'
}
}
productFlavors {
baidu {}
qq {}
productFlavors.all { flavor ->
flavor.manifestPlaceholders = [CHANNEL_VALUE: name]
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('src/main/libs/volly-1.0.11.jar')
compile files('libs/Volley.jar')
compile files('libs/gson-2.2.4.jar')
compile project(':barCode')
compile files('libs/bugly_1.2.3.8__release.jar')
compile project(':validate')
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.rengwuxian.materialedittext:library:2.1.4'
compile 'com.daimajia.numberprogressbar:library:1.2@aar'
compile 'de.greenrobot:eventbus:2.4.0'
}