Skip to content

Instantly share code, notes, and snippets.

@ishitcno1
Last active August 29, 2015 14:11
Show Gist options
  • Save ishitcno1/2a191dca239b25d6a389 to your computer and use it in GitHub Desktop.
Save ishitcno1/2a191dca239b25d6a389 to your computer and use it in GitHub Desktop.
android build.gradle example
// main app code
apply plugin: 'com.android.application'
repositories {
jcenter()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.example.app"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0.0"
}
signingConfigs {
myConfig {
storeFile file("keystore")
storePassword "storePassword"
keyAlias "alias"
keyPassword "keyPassword"
}
}
buildTypes {
debug {
signingConfig signingConfigs.myConfig
}
release {
signingConfig signingConfigs.myConfig
minifyEnabled true
proguardFile file('proguard.txt')
}
}
lintOptions {
abortOnError false
}
}
android.applicationVariants.all { variant ->
variant.assemble.doLast {
variant.outputs.each { output ->
def outputFile = output.outputFile
def versionSuffix = variant.buildType.versionNameSuffix ? variant.buildType.versionNameSuffix : ""
// 自定义后缀
def customSuffix = project.hasProperty('suffix') ? "_" + suffix : ""
def versionCode = variant.mergedFlavor.versionCode + versionSuffix;
// 移出apk并重命名
if (outputFile != null && outputFile.name.endsWith('.apk')) {
println("copying apk")
def renameApkFile = outputFile.name.replace("app", "mrwind-"+versionCode).replace(".apk", customSuffix + ".apk")
copy {
from "$outputFile"
into "$rootProject.projectDir/../apk"
rename ("$outputFile.name", "$renameApkFile")
}
}
// 备份mapping.txt
if (output.name == "fullRelease") {
println("copying mapping.txt")
copy {
from "$rootProject.projectDir/app/build/outputs/mapping/full/release/mapping.txt"
into "$rootProject.projectDir/mapping"
rename ("mapping.txt", "mapping_" + versionCode + ".txt")
}
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:21.0.2'
compile 'com.google.code.gson:gson:2.2.2'
}
// module
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
apply plugin: 'android-library'
repositories {
jcenter()
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment