#947 convert build.gradle to build.gradle.kts

This commit is contained in:
Sean Mac Gillicuddy 2019-11-29 13:54:28 +00:00
parent 43f5f9bf63
commit 7d74969dd9
10 changed files with 193 additions and 194 deletions

View File

@ -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
View 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)
}

View File

@ -31,7 +31,7 @@ import org.gradle.plugin.use.PluginDependencySpec
object Versions {
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"

View 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)

View File

@ -19,12 +19,10 @@
package custom
import com.android.build.gradle.internal.dsl.ProductFlavor
import custom.CustomApps.CustomApp
import org.gradle.api.NamedDomainObjectContainer
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import org.json.simple.JSONObject
import org.json.simple.parser.JSONParser
import java.io.File
object CustomApps {
private val example = CustomApp(
@ -143,7 +141,7 @@ object CustomApps {
enforcedLanguage = "de",
displayName = "Wikivoyage auf Deutsch"
)
val all = listOf(
private val all = listOf(
example,
phet,
tunisie,
@ -165,49 +163,47 @@ object CustomApps {
wikivoyagede
)
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)
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)
}
fun createStatically(productFlavors: NamedDomainObjectContainer<ProductFlavor>) {
productFlavors.create(all)
}
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)
fun createDynamically(
srcFolder: File,
productFlavors: NamedDomainObjectContainer<ProductFlavor>
) {
productFlavors.create(
srcFolder.walk()
.filter { it.name == "info.json" }
.map {
val parsedJson = JSONParser().parse(it.readText()) as JSONObject
createCustomAppFromJson(
it.parentFile.name,
parsedJson.getAndCast("zim_url"),
parsedJson.getAndCast("enforced_lang"),
parsedJson.getAndCast("app_name"),
parsedJson.getAndCast("version_name")
)
}.toList()
)
}
}
fun NamedDomainObjectContainer<ProductFlavor>.create(customApps: List<CustomApp>) {
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(
customApp: CustomApp
) {

View File

@ -8,28 +8,26 @@ buildscript {
}
dependencies {
classpath Libs.objectbox_gradle_plugin
classpath Libs.butterknife_gradle_plugin
classpath(Libs.objectbox_gradle_plugin)
classpath(Libs.butterknife_gradle_plugin)
}
}
apply plugin: 'com.android.library'
apply plugin: KiwixConfigurationPlugin
apply plugin: 'io.objectbox'
apply plugin: 'com.jakewharton.butterknife'
plugins {
`android-library`
}
plugins.apply(KiwixConfigurationPlugin::class)
apply(plugin = "io.objectbox")
apply(plugin = "com.jakewharton.butterknife")
android {
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
getByName("release") {
isMinifyEnabled = false
}
}
}
private boolean shouldUseLocalVersion() {
file("./libs").exists()
}
fun shouldUseLocalVersion() = File(projectDir, "libs").exists()
dependencies {
@ -40,24 +38,23 @@ dependencies {
if (!shouldUseLocalVersion()) {
api(Libs.kiwixlib)
} else {
implementation 'com.getkeepsafe.relinker:relinker:1.3.1'
implementation fileTree(include: ['*.aar'], dir: 'libs')
implementation("com.getkeepsafe.relinker:relinker:1.3.1")
implementation(fileTree(mapOf("include" to "*.aar", "dir" to "libs")))
}
// Android Support
implementation(Libs.cardview)
// SquiDB
implementation(Libs.squidb)
implementation(Libs.squidb_annotations)
kapt(Libs.squidb_processor)
add("kapt", Libs.squidb_processor)
// Square
implementation(Libs.converter_simplexml) {
exclude group: "xpp3", module: "xpp3"
exclude group: "stax", module: "stax-api"
exclude group: "stax", module: "stax"
exclude(group = "xpp3", module = "xpp3")
exclude(group = "stax", module = "stax-api")
exclude(group = "stax", module = "stax")
}
// Leak canary

View File

@ -1,6 +1,7 @@
import com.android.build.gradle.api.ApkVariantOutput
import com.android.build.gradle.api.ApplicationVariant
import com.android.build.gradle.internal.dsl.ProductFlavor
import custom.CustomApps
import custom.createPublisher
import custom.transactionWithCommit
import plugin.KiwixConfigurationPlugin
@ -22,8 +23,8 @@ android {
productFlavors {
// Uncomment for static productFlavors
// create(CustomApps.all)
apply(from = "dynamic_flavors.gradle")
// CustomApps.createStatically(this)
CustomApps.createDynamically(project.file("src"), this)
all {
File("$projectDir/src", "$name/$name.zim").let {
createDownloadTask(it)

View File

@ -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)
}
}
}
}

View File

@ -1,4 +0,0 @@
include ':core'
include ':app'
include ':custom'
rootProject.name='kiwix-android'

6
settings.gradle.kts Normal file
View File

@ -0,0 +1,6 @@
include(
":core",
":app",
":custom"
)
rootProject.name = "kiwix-android"