使用友盟多渠道发布apk,使用gradle自动打apk是十分方便的,这里贴出build.gradle代码
AndroidManifest.xml配置如下:
<meta-data
android:value="${UMENG_CHANNEL}"
android:name="UMENG_CHANNEL"/>
build.gradle代码如下:
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':PushSDK')
}
android {
compileSdkVersion 22
buildToolsVersion "24.0.2"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
lintOptions {
abortOnError false
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['.apt_generated','src']
resources.srcDirs = ['.apt_generated','src']
aidl.srcDirs = ['.apt_generated','src']
renderscript.srcDirs = ['.apt_generated','src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// 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("/Users/allen/Documents/workspace/game.keystore")
storePassword "abc123"
keyAlias "game"
keyPassword "abc123"
}
}
buildTypes {
release {
//添加签名
signingConfig signingConfigs.myConfig
//执行混淆
//runProguard true
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
productFlavors {
AA {
manifestPlaceholders = [ UMENG_CHANNEL:"AA"]
}
BB {
manifestPlaceholders = [ UMENG_CHANNEL:"BB"]
}
}
//重命名
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith("release.apk")) {
//这里按照实际情况重命名
def fileName = outputFile.name.replace("-release","");
output.outputFile = new File(outputFile.parent, fileName);
}
}
}
}