Skip to content

Instantly share code, notes, and snippets.

@mars3142
Created October 10, 2017 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mars3142/52fa40623c4c36fbe5522acd2ec06e06 to your computer and use it in GitHub Desktop.
Save mars3142/52fa40623c4c36fbe5522acd2ec06e06 to your computer and use it in GitHub Desktop.
Example build.gradle for split apk with flavors
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: file("script-git-version.gradle")
import com.android.build.OutputFile
task createObb {
description = "Create all OBB packages"
}
android {
def abiCodes = ['armeabi':1, 'armeabi-v7a':2, 'arm64-v8a':3, 'x86':5, 'x86_64':6, 'mips':8, 'mips64':9].withDefault {0}
def densityCodes = ['mdpi': 1, 'hdpi': 2, 'xhdpi': 3, 'xxhdpi': 4, 'xxxhdpi': 5].withDefault {0}
def versionMajor = 0
def versionMinor = 1
def versionPatch = 5
def versionBuild = 0
compileSdkVersion compileSdk
buildToolsVersion buildTools
defaultConfig {
applicationId "org.mars3142.game.xxx"
minSdkVersion minSdk
targetSdkVersion PROP_TARGET_SDK_VERSION
versionCode versionMajor * 1000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild
versionName gitVersionName
multiDexEnabled true
resConfigs "en", "de", "nl"
ndk {
abiFilters "armeabi-v7a", "arm64-v8a", "x86"
}
externalNativeBuild {
ndkBuild {
targets 'game'
arguments 'NDK_MODULE_PATH=../../cocos2d/cocos:../../cocos2d/external'
arguments '-j' + Runtime.runtime.availableProcessors()
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86'
}
}
}
externalNativeBuild {
ndkBuild {
path "jni/Android.mk"
}
}
sourceSets {
amazon {
assets {
srcDirs "../../Resources"
}
}
google {
assets {
srcDirs "../../Resources"
}
}
main {
jniLibs {
srcDirs "libs"
}
}
}
signingConfigs {
release {
if (project.hasProperty("RELEASE_STORE_FILE")) {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
}
}
buildTypes {
debug {
applicationIdSuffix ".dev"
versionNameSuffix ".debug"
if (project.hasProperty("RELEASE_STORE_FILE")) {
signingConfig signingConfigs.release
}
}
release {
minifyEnabled false
shrinkResources false
proguardFile getDefaultProguardFile('proguard-android.txt')
proguardFile file("proguard-cocos2dx.txt")
proguardFile file("proguard-project.txt")
proguardFile file(firebase_cpp_sdk_dir + "/libs/android/app.pro")
proguardFile file(firebase_cpp_sdk_dir + "/libs/android/analytics.pro")
proguardFile file(firebase_cpp_sdk_dir + "/libs/android/remote_config.pro")
if (project.hasProperty("RELEASE_STORE_FILE")) {
signingConfig signingConfigs.release
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
dexOptions {
javaMaxHeapSize = 5g
dexInProcess = true
}
splits {
density {
enable false
}
abi {
enable true
reset()
include 'armeabi-v7a', 'arm64-v8a', 'x86'
universalApk true
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.versionCodeOverride =
abiCodes.get(output.getFilter(OutputFile.ABI)) * 100000000 + android.defaultConfig.versionCode
}
}
flavorDimensions "store"
productFlavors {
amazon {
dimension "store"
applicationId "org.mars3142.game.xxx.amazon"
}
google {
dimension "store"
applicationId "org.mars3142.game.xxx"
}
all { currentFlavor ->
task("create" + currentFlavor.name.substring(0, 1).toUpperCase() + currentFlavor.name.substring(1) + "Obb", type: Zip) {
archiveName = "main.${defaultConfig.versionCode}.${currentFlavor.applicationId}.obb"
ext.destDir = new File(buildDir, "obb/${currentFlavor.name}")
ext.destFile = new File(destDir, archiveName)
duplicatesStrategy DuplicatesStrategy.EXCLUDE
doFirst {
destDir.mkdirs()
}
description = "Creates expansion file for APK flavour ${currentFlavor.name}"
destinationDir = new File(buildDir, "obb/${currentFlavor.name}");
entryCompression = ZipEntryCompression.STORED
from "obb/${currentFlavor.name}", "../../Resources"
tasks.createObb.dependsOn("create" + currentFlavor.name.substring(0, 1).toUpperCase() + currentFlavor.name.substring(1) + "Obb")
}
}
}
lintOptions {
/**
* Set whether lint should check for fatal errors during release builds. Default is true.
* If issues with severity "fatal" are found, the release build is aborted.
*/
checkReleaseBuilds false
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':libcocos2dx')
implementation 'com.android.support:multidex:1.0.2'
implementation "com.crashlytics.sdk.android:crashlytics:2.6.8"
implementation "com.crashlytics.sdk.android:crashlytics-ndk:1.1.6"
googleImplementation project(':libraries:play_apk_expansion')
googleImplementation project(':libraries:play_licensing')
googleImplementation "com.firebaseui:firebase-ui-database:$firebase_ui_version"
googleImplementation "com.firebaseui:firebase-ui-storage:$firebase_ui_version"
googleImplementation "com.google.android.gms:play-services-safetynet:$play_services"
implementation "com.google.android.gms:play-services-base:$play_services"
implementation "com.google.firebase:firebase-analytics:$play_services"
googleImplementation "com.google.firebase:firebase-appindexing:$play_services"
googleImplementation "com.google.firebase:firebase-crash:$play_services"
googleImplementation "com.google.firebase:firebase-config:$play_services"
googleImplementation "com.google.firebase:firebase-database:$play_services"
googleImplementation "com.google.firebase:firebase-messaging:$play_services"
googleImplementation "com.google.firebase:firebase-storage:$play_services"
implementation "com.jakewharton.timber:timber:4.5.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
apply plugin: 'com.google.gms.google-services'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment