It is very convenient to use Umeng to publish apk through multiple channels, and it is very convenient to use gradle to automatically play apk. Here, the build.gradle code is posted and the
AndroidManifest.xml configuration is as follows:
<meta-data
android:value="${UMENG_CHANNEL}"
android:name="UMENG_CHANNEL"/>
The build.gradle code is as follows:
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 {
//add signature
signingConfig signingConfigs.myConfig
// perform obfuscation
//runProguard true
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
productFlavors {
AA {
manifestPlaceholders = [ UMENG_CHANNEL:"AA"]
}
BB {
manifestPlaceholders = [ UMENG_CHANNEL:"BB"]
}
}
//Rename
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith("release.apk")) {
//rename here according to the actual situation
def fileName = outputFile.name.replace("-release","");
output.outputFile = new File(outputFile.parent, fileName);
}
}
}
}