migu/capacitor/android/app/build.gradle
2024-08-05 23:15:06 +07:00

98 lines
3.7 KiB
Groovy

apply plugin: 'com.android.application'
def verCode = 0
def jsonFile = file('../../../electron/package.json')
def parsedJson = new groovy.json.JsonSlurper().parseText(jsonFile.text)
def verName = parsedJson.version
def versions = verName.tokenize('.')
versions.each (code) -> {
verCode = (verCode*100) + Integer.parseInt(code)
}
android {
namespace "watch.migu"
compileSdk rootProject.ext.compileSdkVersion
defaultConfig {
applicationId "watch.migu"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode verCode
versionName verName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
// Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
splits {
abi {
enable gradle.startParameter.taskNames.any { it.contains("Release") } // https://stackoverflow.com/a/39950584
reset()
include "arm64-v8a", "armeabi-v7a", "x86_64"
universalApk true
}
}
// Map for the version code
project.ext.versionCodes = ['arm64-v8a': 1, 'armeabi-v7a': 2, 'x86_64': 3, 'universal': 4, 'debug': 5]
android.applicationVariants.all { variant ->
// Assign different version code for each output
variant.outputs.each { output ->
def versionCodes = project.ext.versionCodes
def baseVersionCode = android.defaultConfig.versionCode
def abiVersionCode = 0
if (output.getFilter(com.android.build.OutputFile.ABI)) {
abiVersionCode = versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0)
} else {
// This is for the universal APK
abiVersionCode = versionCodes.get('universal', 0)
}
if (gradle.startParameter.taskNames.any { it.contains("Release") }) {
output.versionCodeOverride = abiVersionCode * 1000000 + baseVersionCode
} else {
output.versionCodeOverride = versionCodes.get('debug') * 1000000 + baseVersionCode
}
}
}
}
repositories {
flatDir{
dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"
implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"
implementation project(':capacitor-android')
testImplementation "junit:junit:$junitVersion"
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
implementation project(':capacitor-cordova-android-plugins')
}
apply from: 'capacitor.build.gradle'
try {
def servicesJSON = file('google-services.json')
if (servicesJSON.text) {
apply plugin: 'com.google.gms.google-services'
}
} catch(Exception e) {
logger.info("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
}