Skip to content

Commit

Permalink
Merge pull request #191 from JunJaBoy/main
Browse files Browse the repository at this point in the history
Migrate to Kotlin DSL (Android build script)
  • Loading branch information
sboh1214 authored Sep 7, 2024
2 parents 83e473b + 43d9238 commit 7e18694
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 156 deletions.
88 changes: 0 additions & 88 deletions android/app/build.gradle

This file was deleted.

93 changes: 93 additions & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import java.nio.charset.Charset
import java.util.Properties
import java.io.FileInputStream

val localProperties = Properties().apply {
rootProject.file("local.properties").bufferedReader(Charset.forName("UTF-8"))
.use { reader -> load(reader) }
}

val flutterVersionCode = localProperties.getProperty("flutter.versionCode") ?: "1"
val flutterVersionName = localProperties.getProperty("flutter.versionName") ?: "1.0"

val keystoreProperties = Properties().apply {
val keystorePropertiesFile = rootProject.file("key.properties")
val keystorePropertiesFileExists = keystorePropertiesFile.exists()
if (keystorePropertiesFileExists) {
this.load(FileInputStream(keystorePropertiesFile))
}
}

plugins {
id("com.android.application")
id("kotlin-android")
id("dev.flutter.flutter-gradle-plugin")
}

android {
namespace = "org.sparcs.otlplus"
compileSdk = rootProject.extra.get("compileSdkVersion")?.toString()?.toIntOrNull()

sourceSets {
kotlin.sourceSets["main"].kotlin {
srcDir("src/main/kotlin")
}
}

lint {
disable.addAll(
listOf(
"InvalidPackage",
),
)
}

defaultConfig {
applicationId = "org.sparcs.otlplus"
minSdk = 21
targetSdk = rootProject.extra.get("targetSdkVersion")?.toString()?.toIntOrNull()
versionCode = flutterVersionCode.toInt()
versionName = flutterVersionName
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

signingConfigs {
register("release") {
if (keystoreProperties.isNotEmpty()) {
keyAlias = keystoreProperties.getProperty("keyAlias")!!
keyPassword = keystoreProperties.getProperty("keyPassword")!!
storeFile = file(keystoreProperties.getProperty("storeFile")!!)
storePassword = keystoreProperties.getProperty("storePassword")!!
}
}
}

buildTypes {
release {
signingConfig = signingConfigs.getByName("release")
}
}

packaging {
jniLibs.keepDebugSymbols.add("**/*.so")
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = "17"
}
}

flutter {
source = "../.."
}

dependencies {
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test:runner:1.6.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
}
43 changes: 0 additions & 43 deletions android/build.gradle

This file was deleted.

57 changes: 57 additions & 0 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.LibraryExtension
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

allprojects {
repositories {
google()
mavenCentral()
}
}

buildscript {
extra.apply {
set("compileSdkVersion", 34)
set("targetSdkVersion", 34)
}
}

rootProject.layout.buildDirectory.set(file("../build"))
subprojects {
project.layout.buildDirectory.set(file("${rootProject.layout.buildDirectory.asFile.get().path}/${project.name}"))
}
subprojects {
// check if library extension block is available and namespace isn't set
afterEvaluate {
if (project.hasProperty("android")) {
val ext = try {
project.extensions.getByType<BaseAppModuleExtension>()
} catch (_: Exception) {
project.extensions.getByType<LibraryExtension>()
}

ext.apply {
if (namespace == null) {
namespace = project.group.toString()
}
}
}
tasks.withType(KotlinCompile::class.java).configureEach {
if (project.plugins.hasPlugin("com.android.application") || project.plugins.hasPlugin("com.android.library")) {
kotlinOptions {
kotlinOptions.jvmTarget =
project.extensions.getByType<BaseExtension>().compileOptions.sourceCompatibility.toString()
}
}
}
}

project.evaluationDependsOn(":app")
}

tasks {
register<Delete>("clean") {
delete(rootProject.layout.buildDirectory)
}
}
25 changes: 0 additions & 25 deletions android/settings.gradle

This file was deleted.

26 changes: 26 additions & 0 deletions android/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
pluginManagement {
val flutterSdkPath = run {
val properties = java.util.Properties().apply {
file("local.properties")
.bufferedReader(java.nio.charset.Charset.forName("UTF-8"))
.use { reader -> load(reader) }
}
properties.getProperty("flutter.sdk")
?: throw GradleException("flutter.sdk not set in local.properties")
}
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}

plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "8.3.0" apply false
id("org.jetbrains.kotlin.android") version "1.9.23" apply false
}

include(":app")

0 comments on commit 7e18694

Please sign in to comment.