Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: migrate to room gradle plugin #1627

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 10 additions & 65 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,15 @@ plugins {
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.ksp)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.room)
}

sealed class Version(
open val versionMajor: Int,
val versionMinor: Int,
val versionPatch: Int,
val versionBuild: Int = 0
) {
abstract fun toVersionName(): String
class Alpha(versionMajor: Int, versionMinor: Int, versionPatch: Int, versionBuild: Int) :
Version(versionMajor, versionMinor, versionPatch, versionBuild) {
override fun toVersionName(): String =
"${versionMajor}.${versionMinor}.${versionPatch}-alpha.$versionBuild"
}

class Beta(versionMajor: Int, versionMinor: Int, versionPatch: Int, versionBuild: Int) :
Version(versionMajor, versionMinor, versionPatch, versionBuild) {
override fun toVersionName(): String =
"${versionMajor}.${versionMinor}.${versionPatch}-beta.$versionBuild"
}

class Stable(versionMajor: Int, versionMinor: Int, versionPatch: Int) :
Version(versionMajor, versionMinor, versionPatch) {
override fun toVersionName(): String =
"${versionMajor}.${versionMinor}.${versionPatch}"
}

class ReleaseCandidate(
versionMajor: Int,
versionMinor: Int,
versionPatch: Int,
versionBuild: Int
) :
Version(versionMajor, versionMinor, versionPatch, versionBuild) {
override fun toVersionName(): String =
"${versionMajor}.${versionMinor}.${versionPatch}-rc.$versionBuild"
}
}

val currentVersion: Version = Version.Alpha(
versionMajor = 2,
versionMinor = 0,
versionPatch = 0,
versionBuild = 2
)

val keystorePropertiesFile: File = rootProject.file("keystore.properties")

val splitApks = !project.hasProperty("noSplits")

val abiFilterList = (properties["ABI_FILTERS"] as String).split(';')


android {
if (keystorePropertiesFile.exists()) {
val keystoreProperties = Properties()
Expand All @@ -80,13 +36,11 @@ android {

compileSdk = 34



defaultConfig {
applicationId = "com.junkfood.seal"
minSdk = 24
targetSdk = 34
versionCode = 20000
versionCode = 20000 // (rootProject.extra["versionCode"] as Int) -- Can't be used because of F-droid

if (splitApks) {
splits {
Expand All @@ -99,24 +53,27 @@ android {
}
}

versionName = currentVersion.toVersionName().run {
versionName = (rootProject.extra["versionName"] as String).run {
if (!splitApks) "$this-(F-Droid)"
else this
}
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
ksp {
arg(RoomSchemaArgProvider(File(projectDir, "schemas")))
arg("room.incremental", "true")
}

if (!splitApks) {
ndk {
abiFilters.addAll(abiFilterList)
}
}
}
room {
schemaDirectory("$projectDir/schemas")
}
ksp {
arg("room.incremental", "true") //Still not supported by the Room plugin
}
val abiCodes = mapOf("armeabi-v7a" to 1, "arm64-v8a" to 2, "x86" to 3, "x86_64" to 4)

androidComponents {
Expand Down Expand Up @@ -246,16 +203,4 @@ dependencies {
androidTestImplementation(libs.androidx.test.ext)
androidTestImplementation(libs.androidx.test.espresso.core)
implementation(libs.androidx.compose.ui.tooling)

}

class RoomSchemaArgProvider(
@get:InputDirectory
@get:PathSensitive(PathSensitivity.RELATIVE)
val schemaDir: File
) : CommandLineArgumentProvider {

override fun asArguments(): Iterable<String> {
return listOf("room.schemaLocation=${schemaDir.path}")
}
}
77 changes: 66 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,24 +1,79 @@
@file:Suppress("UnstableApiUsage")
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.room) apply false
}

buildscript {

repositories {
mavenCentral()
google()
}
}

@Suppress("DSL_SCOPE_VIOLATION")
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.compose.compiler) apply false
sealed class Version(
open val versionMajor: Int,
val versionMinor: Int,
val versionPatch: Int,
val versionBuild: Int = 0
) {
abstract fun toVersionName(): String

fun toVersionCode(): Int {
val minor = versionMinor.toString().padStart(2, '0')
val patch = versionPatch.toString().padStart(2, '0')

// Combining the version components, ensuring the result is 5 digits
// We suppose that the major version won't be greater than 9
return "$versionMajor$minor$patch".toInt()
}


class Alpha(versionMajor: Int, versionMinor: Int, versionPatch: Int, versionBuild: Int) :
Version(versionMajor, versionMinor, versionPatch, versionBuild) {
override fun toVersionName(): String =
"${versionMajor}.${versionMinor}.${versionPatch}-alpha.$versionBuild"
}

class Beta(versionMajor: Int, versionMinor: Int, versionPatch: Int, versionBuild: Int) :
Version(versionMajor, versionMinor, versionPatch, versionBuild) {
override fun toVersionName(): String =
"${versionMajor}.${versionMinor}.${versionPatch}-beta.$versionBuild"
}

class Stable(versionMajor: Int, versionMinor: Int, versionPatch: Int) :
Version(versionMajor, versionMinor, versionPatch) {
override fun toVersionName(): String =
"${versionMajor}.${versionMinor}.${versionPatch}"
}

class ReleaseCandidate(
versionMajor: Int,
versionMinor: Int,
versionPatch: Int,
versionBuild: Int
) :
Version(versionMajor, versionMinor, versionPatch, versionBuild) {
override fun toVersionName(): String =
"${versionMajor}.${versionMinor}.${versionPatch}-rc.$versionBuild"
}
}

val currentVersion: Version = Version.Alpha(
versionMajor = 2,
versionMinor = 0,
versionPatch = 0,
versionBuild = 2
)

val versionCode by extra(currentVersion.toVersionCode())
val versionName by extra(currentVersion.toVersionName())

tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
delete(rootProject.layout.buildDirectory)
}

1 change: 0 additions & 1 deletion color/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ dependencies {
api(libs.androidx.core.ktx)
api(libs.androidx.compose.foundation)
api(libs.androidx.compose.material3)

}
5 changes: 3 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ androidxSplashscreen = "1.0.1"
androidxLifecycle = "2.8.4"
androidxNavigation = "2.7.7"
androidxFoundation = "1.6.0-beta03"
androidxComposeMaterial3 = "1.2.0-beta01"
androidxComposeMaterial3 = "1.3.0-alpha06"
androidxComposeAnimation = "1.5.0-beta01"

androidxEspresso = "3.5.0"
Expand Down Expand Up @@ -62,7 +62,7 @@ androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" }

androidx-compose-material = { group = "androidx.compose.material", name = "material" }

androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3", version = "1.3.0-alpha06" }
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "androidxComposeMaterial3" }
androidx-compose-material3-windowSizeClass = { group = "androidx.compose.material3", name = "material3-window-size-class" }

okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttp" }
Expand Down Expand Up @@ -110,6 +110,7 @@ kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", versi
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
room = { id = "androidx.room", version.ref = "room" }

[bundles]
accompanist = [
Expand Down
Loading