as中添加混淆的功能需要在as自动生成的build.gradle中添加如下代码:
buildTypes {
release {
//混淆规则文件 1.true 混淆 2.false 不混淆
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg'
}
}
其中:proguard.cfg可以改成其他文件中,其中包含的是混淆的代码和不需要混淆的代码
as中给apk添加签名
signingConfigs {
myConfig {
//绝对路径和相对路径都可以
storeFile file("******")
storePassword "******"
keyAlias "name"
keyPassword "******" }}
buildTypes { release { //1.添加签名如果项目中存在.so文件的话需要添加如下代码signingConfig signingConfigs.myConfig
}}
sourceSets { main { jniLibs.srcDirs = ['libs'] } }批量打包代码:productFlavors { 91{}//渠道号 baidu{}//渠道号 } productFlavors.all { flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] }其中${UMENG_CHANNEL_VALUE}是在AndroidManifest.xml配置的
<meta-data
android:name="UMENG_CHANNEL"
android:value="${UMENG_CHANNEL_VALUE}" />
完整代码如下:
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':*******')//关联项目
}
android {
compileSdkVersion 19
buildToolsVersion "23.0.2"
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']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
signingConfigs {
myConfig {
//绝对路径和相对路径都可以
storeFile file("******")
storePassword "******"
keyAlias "name"
keyPassword "******"
}
}
buildTypes {
release {
//1.添加签名
signingConfig signingConfigs.myConfig
//混淆规则文件 true 混淆 false 不混淆
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg'
}
}
productFlavors {
91{}
baidu{}
}
productFlavors.all {
flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
lintOptions {
abortOnError false
// if true, only report errors
ignoreWarnings true
}
}