Skip to content

Commit

Permalink
Implement build logic
Browse files Browse the repository at this point in the history
  • Loading branch information
SanmerDev committed Apr 23, 2023
1 parent f7f97b9 commit d2fdab8
Show file tree
Hide file tree
Showing 11 changed files with 349 additions and 144 deletions.
164 changes: 45 additions & 119 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import com.android.build.gradle.internal.api.ApkVariantOutputImpl

plugins {
id("com.android.application")
id("com.google.dagger.hilt.android")
id("com.google.devtools.ksp")
kotlin("android")
kotlin("kapt")
kotlin("plugin.parcelize")
id("mrepo.android.application")
id("mrepo.android.application.compose")
id("mrepo.android.hilt")
id("mrepo.android.room")
alias(libs.plugins.kotlin.parcelize)
alias(libs.plugins.ksp)
}

val verName = "1.2.3"
val verCode = 123
val verName = "1.2.4"
val verCode = 124

@Suppress("UnstableApiUsage")
android {
namespace = "com.sanmer.mrepo"
compileSdk = 33
buildToolsVersion = "33.0.2"
ndkVersion = "25.2.9519653"

signingConfigs {
create("release") {
Expand All @@ -26,8 +24,6 @@ android {

defaultConfig {
applicationId = namespace
minSdk = 26
targetSdk = 33
versionCode = verCode
versionName = verName
resourceConfigurations += arrayOf("en", "zh-rCN", "zh-rTW", "fr", "ro", "es", "ar")
Expand All @@ -36,12 +32,6 @@ android {
ndk {
abiFilters += arrayOf("arm64-v8a", "armeabi-v7a", "x86", "x86_64")
}

externalNativeBuild {
cmake {
arguments += "-DANDROID_STL=c++_static"
}
}
}

externalNativeBuild {
Expand Down Expand Up @@ -69,19 +59,9 @@ android {
}
}

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

buildFeatures {
aidl = true
buildConfig = true
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = "1.4.3"
}

packaging {
Expand All @@ -98,7 +78,16 @@ android {
}
}

setProperty("archivesBaseName", "mrepo-$verName")
applicationVariants.configureEach {
outputs.configureEach {
if (filters.isNotEmpty()) {
val abi = filters.toList().first().identifier
(this as ApkVariantOutputImpl).outputFileName =
"MRepo-${verName}-${verCode}-${abi}.apk"
}
}
}

splits {
abi {
isEnable = true
Expand All @@ -107,93 +96,30 @@ android {
}
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

kotlin {
jvmToolchain(17)

sourceSets.all {
languageSettings {
optIn("androidx.compose.material3.ExperimentalMaterial3Api")
optIn("androidx.compose.ui.ExperimentalComposeUiApi")
optIn("androidx.compose.animation.ExperimentalAnimationApi")
optIn("androidx.compose.foundation.ExperimentalFoundationApi")
optIn("com.google.accompanist.permissions.ExperimentalPermissionsApi")
optIn("kotlin.ExperimentalStdlibApi")
optIn("kotlinx.coroutines.FlowPreview")
}
}
}

ksp {
arg("room.incremental", "true")
arg("room.expandProjection", "true")
arg("room.schemaLocation", "$projectDir/schemas")
}

kapt {
correctErrorTypes = true
}

dependencies {
implementation("androidx.core:core-ktx:1.10.0")
implementation("androidx.work:work-runtime-ktx:2.8.1")
implementation("androidx.datastore:datastore:1.0.0")
implementation("com.google.android.material:material:1.8.0")

implementation("androidx.activity:activity-compose:1.7.0")
implementation("androidx.navigation:navigation-compose:2.5.3")
implementation("androidx.compose.material3:material3:1.1.0-beta02")
implementation("androidx.hilt:hilt-navigation-compose:1.0.0")

val vLifecycle = "2.6.1"
implementation("androidx.lifecycle:lifecycle-runtime-ktx:${vLifecycle}")
implementation("androidx.lifecycle:lifecycle-service:${vLifecycle}")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:${vLifecycle}")
implementation("androidx.lifecycle:lifecycle-viewmodel-savedstate:${vLifecycle}")

val vCompose = "1.4.0"
implementation("androidx.compose.ui:ui:${vCompose}")
implementation("androidx.compose.ui:ui-tooling-preview:${vCompose}")
debugImplementation("androidx.compose.ui:ui-tooling:${vCompose}")
debugImplementation("androidx.compose.ui:ui-test-manifest:${vCompose}")

val vAccompanist = "0.30.0"
implementation("com.google.accompanist:accompanist-systemuicontroller:${vAccompanist}")
implementation("com.google.accompanist:accompanist-navigation-animation:${vAccompanist}")
implementation("com.google.accompanist:accompanist-permissions:${vAccompanist}")

val vRoom = "2.5.1"
implementation("androidx.room:room-runtime:${vRoom}")
implementation("androidx.room:room-ktx:${vRoom}")
ksp("androidx.room:room-compiler:${vRoom}")

val vLibsu = "5.0.4"
implementation("com.github.topjohnwu.libsu:core:${vLibsu}")
implementation("com.github.topjohnwu.libsu:nio:${vLibsu}")
implementation("com.github.topjohnwu.libsu:service:${vLibsu}")

val vRetrofit = "2.9.0"
implementation("com.squareup.retrofit2:retrofit:${vRetrofit}")
implementation("com.squareup.retrofit2:converter-moshi:${vRetrofit}")

val vMoshi = "1.14.0"
implementation("com.squareup.moshi:moshi:${vMoshi}")
ksp("com.squareup.moshi:moshi-kotlin-codegen:${vMoshi}")

val vHilt = "2.45"
implementation("com.google.dagger:hilt-android:${vHilt}")
kapt("com.google.dagger:hilt-android-compiler:${vHilt}")

val vAndroidxHilt = "1.0.0"
implementation("androidx.hilt:hilt-work:${vAndroidxHilt}")
kapt("androidx.hilt:hilt-compiler:${vAndroidxHilt}")

implementation("com.jakewharton.timber:timber:5.0.1")
implementation("io.noties.markwon:core:4.6.2")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
implementation(libs.accompanist.permissions)
implementation(libs.accompanist.systemuicontroller)
implementation(libs.accompanist.navigation.animation)
implementation(libs.activity.compose)
implementation(libs.core.ktx)
implementation(libs.hilt.navigation.compose)
implementation(libs.lifecycle.runtime.compose)
implementation(libs.lifecycle.viewModel.compose)
implementation(libs.lifecycle.service)
implementation(libs.navigation.compose)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.kotlinx.datetime)
implementation(libs.libsu.core)
implementation(libs.libsu.io)
implementation(libs.libsu.service)
implementation(libs.square.retrofit)
implementation(libs.square.retrofit.moshi)

implementation(libs.square.moshi)
ksp(libs.square.moshi.kotlin)

implementation(libs.work.ktx)
implementation(libs.google.material)
implementation(libs.markwon.core)
implementation(libs.timber)
}
36 changes: 36 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
plugins {
`kotlin-dsl`
}

dependencies {
compileOnly(libs.android.gradle)
compileOnly(libs.kotlin.gradle)
compileOnly(libs.ksp.gradle)

implementation(libs.kotlin.reflect)
implementation(libs.kotlin.stdlib)
}

gradlePlugin {
plugins {
register("androidApplication") {
id = "mrepo.android.application"
implementationClass = "AndroidApplicationConventionPlugin"
}

register("androidApplicationCompose") {
id = "mrepo.android.application.compose"
implementationClass = "AndroidApplicationComposeConventionPlugin"
}

register("androidHilt") {
id = "mrepo.android.hilt"
implementationClass = "AndroidHiltConventionPlugin"
}

register("androidRoom") {
id = "mrepo.android.room"
implementationClass = "AndroidRoomConventionPlugin"
}
}
}
12 changes: 12 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}

versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

import com.android.build.api.dsl.ApplicationExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType

class AndroidApplicationComposeConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")

pluginManager.apply("com.android.application")

extensions.configure<ApplicationExtension> {
buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion =
libs.findVersion("androidxComposeCompiler").get().toString()
}

dependencies {
"implementation"(libs.findLibrary("compose.material").get())
"implementation"(libs.findLibrary("compose.material3").get())
"implementation"(libs.findLibrary("compose.ui").get())
"implementation"(libs.findLibrary("compose.ui.tooling.preview").get())
"debugImplementation"(libs.findLibrary("compose.ui.tooling").get())
"debugImplementation"(libs.findLibrary("compose.ui.test.manifest").get())
}
}
}
}
}
58 changes: 58 additions & 0 deletions build-logic/src/main/kotlin/AndroidApplicationConventionPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

import com.android.build.api.dsl.ApplicationExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.kotlin.dsl.configure
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension

class AndroidApplicationConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.android.application")
apply("org.jetbrains.kotlin.android")
}

extensions.configure<ApplicationExtension> {
compileSdk = 33
buildToolsVersion = "33.0.2"
ndkVersion = "25.2.9519653"

defaultConfig {
minSdk = 26
targetSdk = 33
}

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

extensions.configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

extensions.configure<KotlinAndroidProjectExtension> {
jvmToolchain(17)

sourceSets.all {
languageSettings {
optIn("androidx.compose.material3.ExperimentalMaterial3Api")
optIn("androidx.compose.ui.ExperimentalComposeUiApi")
optIn("androidx.compose.animation.ExperimentalAnimationApi")
optIn("androidx.compose.foundation.ExperimentalFoundationApi")
optIn("com.google.accompanist.permissions.ExperimentalPermissionsApi")
optIn("kotlin.ExperimentalStdlibApi")
optIn("kotlinx.coroutines.FlowPreview")
}
}
}
}
}
}
32 changes: 32 additions & 0 deletions build-logic/src/main/kotlin/AndroidHiltConventionPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.plugin.KaptExtension

class AndroidHiltConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")

with(pluginManager) {
apply("dagger.hilt.android.plugin")
apply("org.jetbrains.kotlin.kapt")
}

extensions.configure<KaptExtension> {
correctErrorTypes = true
}

dependencies {
"implementation"(libs.findLibrary("hilt.android").get())
"kapt"(libs.findLibrary("hilt.compiler").get())
"implementation"(libs.findLibrary("hilt.ext.work").get())
"kapt"(libs.findLibrary("hilt.ext.compiler").get())
}
}
}
}
Loading

0 comments on commit d2fdab8

Please sign in to comment.