Last active
May 13, 2021 15:38
-
-
Save bradrice/920e1020ca75de91d06850cb3e999b32 to your computer and use it in GitHub Desktop.
setting for my nativescript with abi splits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.JsonSlurper | |
task replaceSettings { | |
description "Replaces configuration settings." | |
def jsonSlurper = new JsonSlurper() | |
def pathToSettingsJson | |
if (project.hasProperty("appResourcesPath")) { | |
pathToSettingsJson = "$project.appResourcesPath/Android/settings.json"; | |
} else { | |
pathToSettingsJson = "$rootDir/../../app/App_Resources/Android/settings.json"; | |
} | |
def settingsJsonFile = file(pathToSettingsJson); | |
def settingsResolvedPath = settingsJsonFile.getAbsolutePath(); | |
if(settingsJsonFile.exists()) | |
{ | |
println "\t Applying settings from $settingsResolvedPath" | |
String settingsGradleTemplate = android { | |
defaultConfig { | |
ndk { | |
abiFilters.clear() | |
} | |
splits { | |
abi { | |
enable true //enables the ABIs split mechanism | |
reset() //reset the list of ABIs to be included to an empty string | |
include 'arm64-v8a', 'armeabi-v7a', 'x86' | |
universalApk true | |
} | |
} | |
} | |
} | |
def settingsJsonContent = settingsJsonFile.getText("UTF-8"); | |
def settingsMap = jsonSlurper.parseText(settingsJsonContent); | |
for ( setting in settingsMap ) { | |
def placeholder = "__${setting.key}__"; | |
def settingValue = setting.value; | |
if (settingValue == null) { | |
settingValue = false | |
} | |
settingsGradleTemplate = settingsGradleTemplate.replaceAll( placeholder, settingValue as String); | |
} | |
new File( "$rootDir/temp_setting.gradle" ).write( settingsGradleTemplate, 'UTF-8'); | |
apply from: "$rootDir/temp_setting.gradle"; | |
} | |
project.ext.abiCodes = ['armeabi-v7a': 1, 'arm64-v8a': 2, 'x86': 3] | |
android.applicationVariants.all { variant -> | |
variant.outputs.each { output -> | |
def baseAbiVersionCode = project.ext.abiCodes.get(output.getFilter("ABI"), 0) | |
if (baseAbiVersionCode != null) { | |
output.versionCodeOverride = baseAbiVersionCode * 10000000 + variant.versionCode | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment