mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-08 06:42:21 -04:00
#947 convert build.gradle to build.gradle.kts
This commit is contained in:
parent
43f5f9bf63
commit
7d74969dd9
@ -1,83 +0,0 @@
|
|||||||
import plugin.KiwixConfigurationPlugin
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
id("com.android.application")
|
|
||||||
id("com.github.triplet.play") version("2.5.0")
|
|
||||||
}
|
|
||||||
apply plugin: KiwixConfigurationPlugin
|
|
||||||
|
|
||||||
apply from: rootProject.file("jacoco.gradle")
|
|
||||||
|
|
||||||
ext {
|
|
||||||
versionMajor = 3
|
|
||||||
versionMinor = 0
|
|
||||||
versionPatch = 4
|
|
||||||
}
|
|
||||||
|
|
||||||
private String generateVersionName() {
|
|
||||||
"${ext.versionMajor}.${ext.versionMinor}.${ext.versionPatch}"
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* max version code: 21-0-0-00-00-00
|
|
||||||
* our template : UU-D-A-ZZ-YY-XX
|
|
||||||
* where:
|
|
||||||
* X = patch version
|
|
||||||
* Y = minor version
|
|
||||||
* Z = major version (+ 20 to distinguish from previous, non semantic, versions of the app)
|
|
||||||
* A = number representing ABI split
|
|
||||||
* D = number representing density split
|
|
||||||
* U = unused
|
|
||||||
*/
|
|
||||||
|
|
||||||
private Integer generateVersionCode() {
|
|
||||||
20 * 10000 +
|
|
||||||
(ext.versionMajor * 10000) +
|
|
||||||
(ext.versionMinor * 100) +
|
|
||||||
(ext.versionPatch)
|
|
||||||
}
|
|
||||||
|
|
||||||
def buildNumber = System.getenv('TRAVIS_BUILD_NUMBER') ?: "dev"
|
|
||||||
|
|
||||||
android {
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
archivesBaseName = "$buildNumber"
|
|
||||||
resValue "string", "app_name", "Kiwix"
|
|
||||||
resValue "string", "app_search_string", "Search Kiwix"
|
|
||||||
versionCode generateVersionCode()
|
|
||||||
versionName generateVersionName()
|
|
||||||
}
|
|
||||||
|
|
||||||
buildTypes {
|
|
||||||
debug {
|
|
||||||
multiDexKeepProguard file("multidex-instrumentation-config.pro")
|
|
||||||
buildConfigField "boolean", "KIWIX_ERROR_ACTIVITY", "false"
|
|
||||||
}
|
|
||||||
|
|
||||||
release {
|
|
||||||
buildConfigField "boolean", "KIWIX_ERROR_ACTIVITY", "true"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
androidTest {
|
|
||||||
java.srcDirs += "$rootDir/core/src/sharedTestFunctions/java"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
play {
|
|
||||||
enabled = true
|
|
||||||
serviceAccountCredentials = file("../google.json")
|
|
||||||
track = "alpha"
|
|
||||||
releaseStatus = "draft"
|
|
||||||
resolutionStrategy = "fail"
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation(Libs.squidb)
|
|
||||||
implementation(Libs.squidb_annotations)
|
|
||||||
implementation(Libs.ink_page_indicator)
|
|
||||||
kapt(Libs.squidb_processor)
|
|
||||||
}
|
|
80
app/build.gradle.kts
Normal file
80
app/build.gradle.kts
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
import plugin.KiwixConfigurationPlugin
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
android
|
||||||
|
id("com.github.triplet.play") version Versions.com_github_triplet_play_gradle_plugin
|
||||||
|
}
|
||||||
|
plugins.apply(KiwixConfigurationPlugin::class)
|
||||||
|
|
||||||
|
apply(from = rootProject.file("jacoco.gradle"))
|
||||||
|
|
||||||
|
ext {
|
||||||
|
set("versionMajor", 3)
|
||||||
|
set("versionMinor", 0)
|
||||||
|
set("versionPatch", 4)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun generateVersionName() = "${ext["versionMajor"]}.${ext["versionMinor"]}.${ext["versionPatch"]}"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* max version code: 21-0-0-00-00-00
|
||||||
|
* our template : UU-D-A-ZZ-YY-XX
|
||||||
|
* where:
|
||||||
|
* X = patch version
|
||||||
|
* Y = minor version
|
||||||
|
* Z = major version (+ 20 to distinguish from previous, non semantic, versions of the app)
|
||||||
|
* A = number representing ABI split
|
||||||
|
* D = number representing density split
|
||||||
|
* U = unused
|
||||||
|
*/
|
||||||
|
|
||||||
|
fun generateVersionCode() =
|
||||||
|
20 * 10000 +
|
||||||
|
((ext["versionMajor"] as Int) * 10000) +
|
||||||
|
((ext["versionMinor"] as Int) * 100) +
|
||||||
|
ext["versionPatch"] as Int
|
||||||
|
|
||||||
|
val buildNumber get() = System.getenv("TRAVIS_BUILD_NUMBER") ?: "dev"
|
||||||
|
|
||||||
|
android {
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
// archivesBaseName = "$buildNumber"
|
||||||
|
resValue("string", "app_name", "Kiwix")
|
||||||
|
resValue("string", "app_search_string", "Search Kiwix")
|
||||||
|
versionCode = generateVersionCode()
|
||||||
|
versionName = generateVersionName()
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTypes {
|
||||||
|
getByName("debug") {
|
||||||
|
multiDexKeepProguard = file("multidex-instrumentation-config.pro")
|
||||||
|
buildConfigField("boolean", "KIWIX_ERROR_ACTIVITY", "false")
|
||||||
|
}
|
||||||
|
|
||||||
|
getByName("release") {
|
||||||
|
buildConfigField("boolean", "KIWIX_ERROR_ACTIVITY", "true")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
getByName("androidTest") {
|
||||||
|
java.srcDirs("$rootDir/core/src/sharedTestFunctions/java")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
play {
|
||||||
|
isEnabled = true
|
||||||
|
serviceAccountCredentials = file("../google.json")
|
||||||
|
track = "alpha"
|
||||||
|
releaseStatus = "draft"
|
||||||
|
resolutionStrategy = "fail"
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(Libs.squidb)
|
||||||
|
implementation(Libs.squidb_annotations)
|
||||||
|
implementation(Libs.ink_page_indicator)
|
||||||
|
add("kapt", Libs.squidb_processor)
|
||||||
|
}
|
@ -31,7 +31,7 @@ import org.gradle.plugin.use.PluginDependencySpec
|
|||||||
object Versions {
|
object Versions {
|
||||||
const val de_fayard_buildsrcversions_gradle_plugin: String = "0.6.1"
|
const val de_fayard_buildsrcversions_gradle_plugin: String = "0.6.1"
|
||||||
|
|
||||||
const val com_github_triplet_play_gradle_plugin: String = "2.4.1" // available: "2.4.2"
|
const val com_github_triplet_play_gradle_plugin: String = "2.5.0" // available: "2.4.2"
|
||||||
|
|
||||||
const val android_arch_lifecycle_extensions: String = "1.1.1"
|
const val android_arch_lifecycle_extensions: String = "1.1.1"
|
||||||
|
|
||||||
|
49
buildSrc/src/main/kotlin/custom/CustomApp.kt
Normal file
49
buildSrc/src/main/kotlin/custom/CustomApp.kt
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Kiwix Android
|
||||||
|
* Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package custom
|
||||||
|
|
||||||
|
import java.text.ParseException
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
|
data class CustomApp(
|
||||||
|
val name: String,
|
||||||
|
val url: String,
|
||||||
|
val enforcedLanguage: String,
|
||||||
|
val displayName: String,
|
||||||
|
val versionName: String = parseVersionNameFromUrlOrUsePattern(url, "YYYY-MM")
|
||||||
|
) {
|
||||||
|
val versionCode: Int = formatDate("YYDDD0").toInt()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun parseVersionNameFromUrlOrUsePattern(url: String, pattern: String) =
|
||||||
|
url.substringAfterLast("_")
|
||||||
|
.substringBeforeLast(".")
|
||||||
|
.takeIf {
|
||||||
|
try {
|
||||||
|
SimpleDateFormat(pattern, Locale.ROOT).parse(it) != null
|
||||||
|
} catch (parseException: ParseException) {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?: formatDate(pattern)
|
||||||
|
|
||||||
|
private fun formatDate(pattern: String) =
|
||||||
|
Date().let(SimpleDateFormat(pattern, Locale.ROOT)::format)
|
@ -19,12 +19,10 @@
|
|||||||
package custom
|
package custom
|
||||||
|
|
||||||
import com.android.build.gradle.internal.dsl.ProductFlavor
|
import com.android.build.gradle.internal.dsl.ProductFlavor
|
||||||
import custom.CustomApps.CustomApp
|
|
||||||
import org.gradle.api.NamedDomainObjectContainer
|
import org.gradle.api.NamedDomainObjectContainer
|
||||||
import java.text.ParseException
|
import org.json.simple.JSONObject
|
||||||
import java.text.SimpleDateFormat
|
import org.json.simple.parser.JSONParser
|
||||||
import java.util.Date
|
import java.io.File
|
||||||
import java.util.Locale
|
|
||||||
|
|
||||||
object CustomApps {
|
object CustomApps {
|
||||||
private val example = CustomApp(
|
private val example = CustomApp(
|
||||||
@ -143,7 +141,7 @@ object CustomApps {
|
|||||||
enforcedLanguage = "de",
|
enforcedLanguage = "de",
|
||||||
displayName = "Wikivoyage auf Deutsch"
|
displayName = "Wikivoyage auf Deutsch"
|
||||||
)
|
)
|
||||||
val all = listOf(
|
private val all = listOf(
|
||||||
example,
|
example,
|
||||||
phet,
|
phet,
|
||||||
tunisie,
|
tunisie,
|
||||||
@ -165,49 +163,47 @@ object CustomApps {
|
|||||||
wikivoyagede
|
wikivoyagede
|
||||||
)
|
)
|
||||||
|
|
||||||
fun createCustomAppFromJson(
|
fun createStatically(productFlavors: NamedDomainObjectContainer<ProductFlavor>) {
|
||||||
name: String,
|
productFlavors.create(all)
|
||||||
url: String,
|
|
||||||
enforcedLanguage: String,
|
|
||||||
displayName: String,
|
|
||||||
versionName: String?
|
|
||||||
) = if (versionName == null) CustomApp(name, url, enforcedLanguage, displayName)
|
|
||||||
else CustomApp(name, url, enforcedLanguage, displayName, versionName)
|
|
||||||
|
|
||||||
data class CustomApp(
|
|
||||||
val name: String,
|
|
||||||
val url: String,
|
|
||||||
val enforcedLanguage: String,
|
|
||||||
val displayName: String,
|
|
||||||
val versionName: String = parseVersionNameFromUrlOrUsePattern(url, "YYYY-MM")
|
|
||||||
) {
|
|
||||||
val versionCode: Int = formatDate("YYDDD0").toInt()
|
|
||||||
|
|
||||||
fun createFlavor(namedDomainObjectContainer: NamedDomainObjectContainer<ProductFlavor>) {
|
|
||||||
namedDomainObjectContainer.create(this)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseVersionNameFromUrlOrUsePattern(url: String, pattern: String) =
|
fun createDynamically(
|
||||||
url.substringAfterLast("_")
|
srcFolder: File,
|
||||||
.substringBeforeLast(".")
|
productFlavors: NamedDomainObjectContainer<ProductFlavor>
|
||||||
.takeIf {
|
) {
|
||||||
try {
|
productFlavors.create(
|
||||||
SimpleDateFormat(pattern, Locale.ROOT).parse(it) != null
|
srcFolder.walk()
|
||||||
} catch (parseException: ParseException) {
|
.filter { it.name == "info.json" }
|
||||||
false
|
.map {
|
||||||
}
|
val parsedJson = JSONParser().parse(it.readText()) as JSONObject
|
||||||
}
|
createCustomAppFromJson(
|
||||||
?: formatDate(pattern)
|
it.parentFile.name,
|
||||||
|
parsedJson.getAndCast("zim_url"),
|
||||||
private fun formatDate(pattern: String) =
|
parsedJson.getAndCast("enforced_lang"),
|
||||||
Date().let(SimpleDateFormat(pattern, Locale.ROOT)::format)
|
parsedJson.getAndCast("app_name"),
|
||||||
|
parsedJson.getAndCast("version_name")
|
||||||
|
)
|
||||||
|
}.toList()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun NamedDomainObjectContainer<ProductFlavor>.create(customApps: List<CustomApp>) {
|
fun NamedDomainObjectContainer<ProductFlavor>.create(customApps: List<CustomApp>) {
|
||||||
customApps.forEach(this::create)
|
customApps.forEach(this::create)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createCustomAppFromJson(
|
||||||
|
name: String,
|
||||||
|
url: String,
|
||||||
|
enforcedLanguage: String,
|
||||||
|
displayName: String,
|
||||||
|
versionName: String?
|
||||||
|
) = if (versionName == null) CustomApp(name, url, enforcedLanguage, displayName)
|
||||||
|
else CustomApp(name, url, enforcedLanguage, displayName, versionName)
|
||||||
|
|
||||||
|
fun <T> JSONObject.getAndCast(columnName: String): T =
|
||||||
|
getOrDefault(columnName, null) as T
|
||||||
|
|
||||||
private fun NamedDomainObjectContainer<ProductFlavor>.create(
|
private fun NamedDomainObjectContainer<ProductFlavor>.create(
|
||||||
customApp: CustomApp
|
customApp: CustomApp
|
||||||
) {
|
) {
|
||||||
|
@ -8,28 +8,26 @@ buildscript {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath Libs.objectbox_gradle_plugin
|
classpath(Libs.objectbox_gradle_plugin)
|
||||||
classpath Libs.butterknife_gradle_plugin
|
classpath(Libs.butterknife_gradle_plugin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
plugins {
|
||||||
apply plugin: 'com.android.library'
|
`android-library`
|
||||||
apply plugin: KiwixConfigurationPlugin
|
}
|
||||||
apply plugin: 'io.objectbox'
|
plugins.apply(KiwixConfigurationPlugin::class)
|
||||||
apply plugin: 'com.jakewharton.butterknife'
|
apply(plugin = "io.objectbox")
|
||||||
|
apply(plugin = "com.jakewharton.butterknife")
|
||||||
|
|
||||||
android {
|
android {
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
getByName("release") {
|
||||||
minifyEnabled false
|
isMinifyEnabled = false
|
||||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldUseLocalVersion() {
|
fun shouldUseLocalVersion() = File(projectDir, "libs").exists()
|
||||||
file("./libs").exists()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
@ -40,24 +38,23 @@ dependencies {
|
|||||||
if (!shouldUseLocalVersion()) {
|
if (!shouldUseLocalVersion()) {
|
||||||
api(Libs.kiwixlib)
|
api(Libs.kiwixlib)
|
||||||
} else {
|
} else {
|
||||||
implementation 'com.getkeepsafe.relinker:relinker:1.3.1'
|
implementation("com.getkeepsafe.relinker:relinker:1.3.1")
|
||||||
implementation fileTree(include: ['*.aar'], dir: 'libs')
|
implementation(fileTree(mapOf("include" to "*.aar", "dir" to "libs")))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Android Support
|
// Android Support
|
||||||
implementation(Libs.cardview)
|
implementation(Libs.cardview)
|
||||||
|
|
||||||
|
|
||||||
// SquiDB
|
// SquiDB
|
||||||
implementation(Libs.squidb)
|
implementation(Libs.squidb)
|
||||||
implementation(Libs.squidb_annotations)
|
implementation(Libs.squidb_annotations)
|
||||||
kapt(Libs.squidb_processor)
|
add("kapt", Libs.squidb_processor)
|
||||||
|
|
||||||
// Square
|
// Square
|
||||||
implementation(Libs.converter_simplexml) {
|
implementation(Libs.converter_simplexml) {
|
||||||
exclude group: "xpp3", module: "xpp3"
|
exclude(group = "xpp3", module = "xpp3")
|
||||||
exclude group: "stax", module: "stax-api"
|
exclude(group = "stax", module = "stax-api")
|
||||||
exclude group: "stax", module: "stax"
|
exclude(group = "stax", module = "stax")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Leak canary
|
// Leak canary
|
@ -1,6 +1,7 @@
|
|||||||
import com.android.build.gradle.api.ApkVariantOutput
|
import com.android.build.gradle.api.ApkVariantOutput
|
||||||
import com.android.build.gradle.api.ApplicationVariant
|
import com.android.build.gradle.api.ApplicationVariant
|
||||||
import com.android.build.gradle.internal.dsl.ProductFlavor
|
import com.android.build.gradle.internal.dsl.ProductFlavor
|
||||||
|
import custom.CustomApps
|
||||||
import custom.createPublisher
|
import custom.createPublisher
|
||||||
import custom.transactionWithCommit
|
import custom.transactionWithCommit
|
||||||
import plugin.KiwixConfigurationPlugin
|
import plugin.KiwixConfigurationPlugin
|
||||||
@ -22,8 +23,8 @@ android {
|
|||||||
productFlavors {
|
productFlavors {
|
||||||
|
|
||||||
// Uncomment for static productFlavors
|
// Uncomment for static productFlavors
|
||||||
// create(CustomApps.all)
|
// CustomApps.createStatically(this)
|
||||||
apply(from = "dynamic_flavors.gradle")
|
CustomApps.createDynamically(project.file("src"), this)
|
||||||
all {
|
all {
|
||||||
File("$projectDir/src", "$name/$name.zim").let {
|
File("$projectDir/src", "$name/$name.zim").let {
|
||||||
createDownloadTask(it)
|
createDownloadTask(it)
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
import custom.CustomApps
|
|
||||||
import groovy.json.JsonSlurper
|
|
||||||
|
|
||||||
apply plugin: 'com.android.application'
|
|
||||||
|
|
||||||
// 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 {
|
|
||||||
productFlavors {
|
|
||||||
// Custom apps built from a json file
|
|
||||||
map.each { name, directory ->
|
|
||||||
def jsonFile = file(directory + "/info.json")
|
|
||||||
if (jsonFile.exists()) {
|
|
||||||
def parsedJson = new JsonSlurper().parseText(jsonFile.text)
|
|
||||||
CustomApps.INSTANCE.createCustomAppFromJson(
|
|
||||||
name,
|
|
||||||
parsedJson.zim_url,
|
|
||||||
parsedJson.enforced_lang,
|
|
||||||
parsedJson.app_name,
|
|
||||||
parsedJson.version_name
|
|
||||||
).createFlavor(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
include ':core'
|
|
||||||
include ':app'
|
|
||||||
include ':custom'
|
|
||||||
rootProject.name='kiwix-android'
|
|
6
settings.gradle.kts
Normal file
6
settings.gradle.kts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
include(
|
||||||
|
":core",
|
||||||
|
":app",
|
||||||
|
":custom"
|
||||||
|
)
|
||||||
|
rootProject.name = "kiwix-android"
|
Loading…
x
Reference in New Issue
Block a user