kiwix-android/custom/build.gradle

172 lines
5.5 KiB
Groovy

import groovy.json.JsonSlurper
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
String[] archs = ['arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64']
// Set custom app import directory
def map = [:]
def custom = new File("custom/src")
if (project.hasProperty("customDir")) {
custom = file(project.property("customDir"))
}
// Set up flavours for each custom app in the directory
if (custom.listFiles()) {
custom.eachFile() { file ->
def fileName = file.getName()
if (fileName.startsWith(".") ||
fileName.contains("test") ||
fileName == "main" ||
fileName.contains("Test")) {
return
}
map.put(fileName, file.getAbsolutePath())
}
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "org.kiwix.kiwixmobile.custom"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "default"
productFlavors {
// Custom apps built from a json file, zim file and icon set
map.each { name, directory ->
"$name" {
println "Configuring $name"
if (file(directory + "/build.gradle").exists()) {
apply from: directory + "/build.gradle"
}
def jsonFile
if (project.hasProperty("jsonFile")) {
// Read json file from properties e.g command line
jsonFile = file(project.property("jsonFile"))
} else {
// If no file provided use the test file
jsonFile = file(directory + "/info.json")
}
def parsedJson = new JsonSlurper().parseText(jsonFile.text)
def sourceFile = file(parsedJson.zim_file)
if (!sourceFile.exists()) {
sourceFile = file(directory + "/" + parsedJson.zim_file)
}
if (parsedJson.embed_zim) {
// Place content in each lib directory for embeded zims
for (String archName : archs) {
copy {
from sourceFile
into file(directory + "/jniLibs/" + archName)
rename { String filename -> "libcontent.so" }
}
}
parsedJson.zim_file = "libcontent.so"
}
// Set custom config from json
applicationId "$parsedJson.package"
buildConfigField "boolean", "IS_CUSTOM_APP", "true"
buildConfigField "boolean", "HAS_EMBEDDED_ZIM", "$parsedJson.embed_zim"
def filename
if (parsedJson.zim_file.lastIndexOf("/") >= 0) {
filename = parsedJson.zim_file.substring(parsedJson.zim_file.lastIndexOf("/") + 1)
} else {
filename = parsedJson.zim_file
}
buildConfigField "String", "ZIM_FILE_NAME", "\"$filename\""
if (project.hasProperty("zim_file_size")) {
def length = Long.parseLong(project.property("zim_file_size"))
buildConfigField "long", "ZIM_FILE_SIZE", "${length}L"
} else {
long length = sourceFile.length()
buildConfigField "long", "ZIM_FILE_SIZE", "${length}L"
}
if (project.hasProperty("version_code")) {
def version_code = project.property("version_code")
versionCode version_code.toInteger()
} else {
versionCode parsedJson.version_code.toInteger()
}
if (project.hasProperty("version_name")) {
versionName project.property("version_name")
} else {
versionName parsedJson.version_name
}
if (project.hasProperty("content_version_code")) {
def content_version_code = project.property("content_version_code")
buildConfigField "int", "CONTENT_VERSION_CODE", "$content_version_code"
} else if (parsedJson.content_version_code != null) {
buildConfigField "int", "CONTENT_VERSION_CODE", "$parsedJson.content_version_code"
} else if (project.hasProperty('version_code')) {
def version_code = project.property('version_code')
buildConfigField "int", "CONTENT_VERSION_CODE", "$version_code"
} else if (parsedJson.version_code != null) {
buildConfigField "int", "CONTENT_VERSION_CODE", "$parsedJson.version_code"
}
buildConfigField "String", "ENFORCED_LANG", "\"$parsedJson.enforced_lang\""
resValue "string", "app_name", "$parsedJson.app_name"
resValue "string", "app_search_string", "Search " + "$parsedJson.app_name"
}
}
}
// Set each custom apps respective source directory
sourceSets {
map.each { name, directory ->
"$name" {
setRoot directory
jni.srcDirs = []
jniLibs.srcDir directory + "/jniLibs"
}
}
}
compileOptions {
encoding = "UTF-8"
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lintOptions {
abortOnError true
checkAllWarnings true
warningsAsErrors true
ignore 'SyntheticAccessor',
//TODO stop ignoring below this
'MissingTranslation',
'CheckResult',
'LabelFor',
'DuplicateStrings',
'LogConditional'
warning 'UnknownNullness',
'SelectableText',
'IconDensities',
'SyntheticAccessor'
baseline file("lint-baseline.xml")
}
}
dependencies {
implementation project(':core')
implementation(Libs.appcompat)
}