feature TI-186: [Android] Настройка проекта

This commit is contained in:
Evgeny Dubravin 2024-03-22 20:25:18 +07:00
parent b99dec674c
commit 80681356fa
36 changed files with 455 additions and 358 deletions

View File

@ -1,9 +1,8 @@
plugins {
// id(Plugins.ANDROID_APP_PLUGIN_WITH_DEFAULT_CONFIG)
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.kapt)
id(Plugins.ANDROID_APP_PLUGIN_WITH_DEFAULT_CONFIG)
id(libs.plugins.android.application.get().pluginId)
id(libs.plugins.kotlin.android.get().pluginId)
id(libs.plugins.kotlin.kapt.get().pluginId)
alias(libs.plugins.google.services)
alias(libs.plugins.firebase.crashlytics)
alias(libs.plugins.firebase.perf)
@ -16,23 +15,23 @@ android {
namespace = "ru.touchin.template"
compileSdk = AndroidConfig.COMPILE_SDK_VERSION
defaultConfig {
applicationId = Environment.APP_ID.getenv() ?: AndroidConfig.TEST_APP_ID
versionCode = libs.versions.versionCode.get().toInt()
versionName = libs.versions.versionName.get()
compileSdk = libs.versions.compileSdk.get().toInt()
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.targetSdk.get().toInt()
}
// configureSigningConfig(this@Build_gradle::file)
// with(defaultConfig) {
// defaultConfig {
// applicationId = Environment.APP_ID.getenv() ?: AndroidConfig.TEST_APP_ID
// signingConfig = signingConfigs.getByName("debug")
// versionCode = libs.versions.versionCode.get().toInt()
// versionName = libs.versions.versionName.get()
//
// compileSdk = libs.versions.compileSdk.get().toInt()
// minSdk = libs.versions.minSdk.get().toInt()
// targetSdk = libs.versions.targetSdk.get().toInt()
// }
// configureSigningConfig(this@Build_gradle::file)
// with(defaultConfig) {
// applicationId = Environment.APP_ID.getenv() ?: AndroidConfig.TEST_APP_ID
// signingConfig = signingConfigs.getByName("debug")
// }
buildTypes {
getByName("debug") {
isMinifyEnabled = false

View File

@ -6,21 +6,25 @@ buildscript {
}
dependencies {
// classpath("com.vanniktech:gradle-dependency-graph-generator-plugin:0.5.0")
classpath(libs.google.oss.licenses.plugin)
// classpath("com.vanniktech:gradle-dependency-graph-generator-plugin:0.5.0")
classpath(libs.android.gradle.plugin)
classpath(libs.kotlin.gradle.plugin)
classpath(libs.google.oss.licenses.plugin) {
exclude(group = "com.google.protobuf")
}
}
}
plugins {
// id(Plugins.DEPENDENCY_GRAPH).version("0.5.0")
// id("static-analysis-android")
// id(Plugins.DEPENDENCY_GRAPH).version("0.5.0")
// id("static-analysis-android")
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.kapt) apply false
alias(libs.plugins.google.services) apply false
alias(libs.plugins.firebase.crashlytics) apply false
alias(libs.plugins.firebase.perf) apply false
// alias(libs.plugins.android.application) apply false
// alias(libs.plugins.kotlin.android) apply false
// alias(libs.plugins.kotlin.kapt) apply false
// alias(libs.plugins.google.services) apply false
// alias(libs.plugins.firebase.crashlytics) apply false
// alias(libs.plugins.firebase.perf) apply false
}
val buildScriptsDir = "${rootProject.projectDir}/BuildScripts"

View File

@ -1,10 +1,19 @@
plugins {
`kotlin-dsl`
// `kotlin-dsl-precompiled-script-plugins`
// kotlin("jvm") version embeddedKotlinVersion
`kotlin-dsl-precompiled-script-plugins`
}
// The kotlin-dsl plugin requires a repository to be declared
repositories {
mavenCentral()
google()
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
dependencies {
implementation(libs.android.gradle.plugin)
implementation(libs.kotlin.gradle.plugin)
}

View File

@ -0,0 +1,10 @@
dependencyResolutionManagement {
repositories {
mavenCentral()
}
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}

View File

@ -1,16 +1,16 @@
import com.android.build.gradle.BaseExtension
object AndroidConfig {
const val COMPILE_SDK_VERSION = 29
const val COMPILE_SDK_VERSION = 34
const val MIN_SDK_VERSION = 23
const val TARGET_SDK_VERSION = 29
const val BUILD_TOOLS_VERSION = "29.0.2"
const val TARGET_SDK_VERSION = 34
const val BUILD_TOOLS_VERSION = "30.0.3"
val VERSION_CODE: Int = Environment.BUILD_NUMBER.getenv()?.toIntOrNull() ?: 10000
const val VERSION_NAME = "1.0.0"
// TODO: change test package name
const val TEST_APP_ID = "com.touchin.template"
const val TEST_APP_ID = "ru.touchin.template"
// TODO: change common file folder
const val COMMON_FOLDER = "Template-common"

View File

@ -0,0 +1,89 @@
import com.android.build.gradle.BaseExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.extra
fun BaseExtension.addBuildType(
type: BuildType,
project: Project
) {
buildTypes {
maybeCreate(type.name)
getByName(type.name) {
isDebuggable = !type.optimizeAndObfuscate
isMinifyEnabled = type.optimizeAndObfuscate
isShrinkResources = type.optimizeAndObfuscate
setMatchingFallbacks(type.matchingFallbacks)
if (listOf(BuildType.Develop, BuildType.Debug).contains(type)) {
applicationIdSuffix = ".${type.name}"
}
if (type.optimizeAndObfuscate) {
setProguardFiles(
project.file("proguard").listFiles().toList() +
getDefaultProguardFile("proguard-android-optimize.txt")
)
}
extra.set("enableCrashlytics", type.enableCrashlytics)
buildConfigField("Boolean", "ENABLE_SSL_PINNING", type.enableSslPinning.toString())
buildConfigField("Boolean", "ENABLE_LOGS", type.enabledLogs.toString())
buildConfigField("Boolean", "ENABLE_DEBUG_PANEL", type.enabledDebugPanel.toString())
}
}
}
sealed class BuildType(
val name: String,
val optimizeAndObfuscate: Boolean,
val enableSslPinning: Boolean,
val enabledLogs: Boolean,
val enabledDebugPanel: Boolean,
val enableCrashlytics: Boolean = true,
val defaultServer: String = "com.redmadrobot.data.network.ServerUrl.CUSTOMER_TEST",
val serverType: String,
val matchingFallbacks: String = "debug"
) {
object Develop : BuildType(
name = "develop",
optimizeAndObfuscate = false,
enableSslPinning = false,
enabledLogs = true,
enabledDebugPanel = true,
enableCrashlytics = false,
serverType = "Test",
)
object Debug : BuildType(
name = "debug",
optimizeAndObfuscate = false,
enableSslPinning = false,
enabledLogs = true,
enabledDebugPanel = true,
serverType = "Test",
)
object Customer : BuildType(
name = "customer",
optimizeAndObfuscate = true,
enableSslPinning = true,
enabledLogs = false,
enabledDebugPanel = false,
defaultServer = "com.redmadrobot.data.network.ServerUrl.CUSTOMER_PROD",
serverType = "Prod",
matchingFallbacks = "release"
)
object Release : BuildType(
name = "release",
optimizeAndObfuscate = true,
enableSslPinning = true,
enabledLogs = false,
enabledDebugPanel = false,
defaultServer = "com.redmadrobot.data.network.ServerUrl.CUSTOMER_PROD",
serverType = "Prod",
matchingFallbacks = "release"
)
}

View File

@ -1,145 +0,0 @@
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.dsl.DependencyHandler
fun DependencyHandler.fragment() {
implementation(Library.ANDROIDX_FRAGMENT)
implementation(Library.ANDROIDX_FRAGMENT_KTX)
implementationModule(Module.RoboSwag.NAVIGATION_BASE)
}
fun DependencyHandler.materialDesign() {
implementation(Library.ANDROID_MATERIAL)
implementation(Library.SWIPE_TO_REFRESH)
}
fun DependencyHandler.permissionDispatcher() {
implementation(Library.PERMISSION_DISPATCHER)
kapt(Library.PERMISSION_DISPATCHER_ANNOTATION_PROCESSOR)
}
fun DependencyHandler.constraintLayout() {
implementation(Library.ANDROIDX_CONSTRAINT)
}
fun DependencyHandler.androidX() {
implementation(Library.ANDROIDX_CORE)
implementation(Library.ANDROIDX_APPCOMPAT)
implementationModule(Module.RoboSwag.KOTLIN_EXTENSIONS)
}
fun DependencyHandler.recyclerView() {
implementation(Library.ANDROIDX_RECYCLER)
implementationModule(Module.RoboSwag.RECYCLER_VIEW_ADAPTERS)
}
fun DependencyHandler.kotlinStd() {
implementation(Library.KOTLIN_STDLIB)
}
fun DependencyHandler.navigation() {
implementation(Library.CICERONE)
implementationModule(Module.RoboSwag.NAVIGATION_CICERONE)
}
fun DependencyHandler.featureModules() {
Module.Feature.ALL.forEach(this::implementationModule)
}
fun DependencyHandler.mvi() {
implementationModule(Module.RoboSwag.MVI_ARCH)
fragment()
lifecycle()
}
fun DependencyHandler.coreNetwork() {
implementationModule(Module.Core.NETWORK)
}
fun DependencyHandler.coreStrings() {
implementationModule(Module.Core.STRINGS)
}
fun DependencyHandler.retrofit() {
implementation(Library.RETROFIT)
implementation(Library.OKHTTP_LOGGING_INTERCEPTOR)
implementation(Library.OKHTTP)
implementation(Library.MOSHI_RETROFIT)
}
fun DependencyHandler.dagger(withAssistedInject: Boolean = true) {
implementation(Library.DAGGER)
kapt(Library.DAGGER_COMPILER)
implementation(Library.DAGGER_COMPONENT_MANAGER)
if (withAssistedInject) {
compileOnly(Library.DAGGER_INJECT_ASSISTED_ANNOTATIONS)
kapt(Library.DAGGER_INJECT_ASSISTED_PROCESSOR)
}
}
fun DependencyHandler.glide() {
implementation(Library.GLIDE)
implementation(Library.GLIDE_OKHTTP_INTEGRATION)
kapt(Library.GLIDE_COMPILER)
}
fun DependencyHandler.moshi() {
implementation(Library.MOSHI)
kapt(Library.MOSHI_CODEGEN)
}
fun DependencyHandler.lifecycle() {
implementation(Library.ANDROID_LIFECYCLE_EXTENSIONS)
implementation(Library.ANDROID_LIFECYCLE_VIEW_MODEL_EXTENSIONS)
implementation(Library.ANDROID_LIFECYCLE_LIVE_DATA_EXTENSIONS)
implementationModule(Module.RoboSwag.LIFECYCLE)
}
fun DependencyHandler.coroutines() {
implementation(Library.COROUTINES_CORE)
implementation(Library.COROUTINES_ANDROID)
}
fun DependencyHandler.leakCanary() {
add("withTestPanelImplementation", Library.LEAK_CANARY)
}
fun DependencyHandler.sharedPrefs() {
implementationModule(Module.RoboSwag.STORABLE)
implementationModule(Module.Core.PREFS)
}
fun DependencyHandler.chucker() {
add("withTestPanelImplementation", Library.CHUCKER)
add("withoutTestPanelImplementation", Library.CHUCKER_NO_OP)
}
fun DependencyHandler.implementationModule(moduleName: String) {
implementation(project(":$moduleName"))
}
private fun DependencyHandler.implementation(dependencyNotation: Any): Dependency? =
add("implementation", dependencyNotation)
private fun DependencyHandler.kapt(dependencyNotation: Any): Dependency? =
add("kapt", dependencyNotation)
private fun DependencyHandler.compileOnly(dependencyNotation: Any): Dependency? =
add("compileOnly", dependencyNotation)
private fun DependencyHandler.project(
path: String,
configuration: String? = null
): ProjectDependency {
val notation = if (configuration != null) {
mapOf("path" to path, "configuration" to configuration)
} else {
mapOf("path" to path)
}
return uncheckedCast(project(notation))
}
@Suppress("unchecked_cast", "nothing_to_inline", "detekt.UnsafeCast")
private inline fun <T> uncheckedCast(obj: Any?): T = obj as T

View File

@ -1,13 +1,12 @@
object Environment {
const val APP_ID = "BUNDLE_ID"
const val STORE_PASSWORD = "STORE_PASSWORD"
const val KEY_ALIAS = "KEY_ALIAS"
const val ALIAS = "ALIAS"
const val KEY_PASSWORD = "KEY_PASSWORD"
const val ENDPOINT = "CUSTOM_ENDPOINT"
const val BUILD_NUMBER = "BUILD_NUMBER"
const val SERVER_ENVIRONMENT = "SERVER_ENVIRONMENT"
const val BUILD_TYPE = "BUILD_TYPE"
}
fun String.getenv(): String? = System.getenv(this)

View File

@ -1,60 +0,0 @@
object Library {
const val KOTLIN_STDLIB = "org.jetbrains.kotlin:kotlin-stdlib:${Version.KOTLIN}"
const val ANDROIDX_APPCOMPAT = "androidx.appcompat:appcompat:${Version.ANDROIDX_APPCOMPAT}"
const val ANDROIDX_CORE = "androidx.core:core-ktx:${Version.ANDROIDX_CORE}"
const val ANDROIDX_RECYCLER = "androidx.recyclerview:recyclerview:${Version.ANDROIDX}"
const val ANDROIDX_CONSTRAINT = "androidx.constraintlayout:constraintlayout:${Version.ANDROIDX_CONSTRAINT}"
const val ANDROIDX_FRAGMENT = "androidx.fragment:fragment:${Version.ANDROIDX_FRAGMENT}"
const val ANDROIDX_FRAGMENT_KTX = "androidx.fragment:fragment-ktx:${Version.ANDROIDX_FRAGMENT}"
const val ANDROID_MATERIAL = "com.google.android.material:material:${Version.ANDROID_MATERIAL}"
const val SWIPE_TO_REFRESH = "androidx.swiperefreshlayout:swiperefreshlayout:${Version.SWIPE_TO_REFRESH}"
const val PERMISSION_DISPATCHER = "org.permissionsdispatcher:permissionsdispatcher:${Version.PERMISSION_DISPATCHER}"
const val PERMISSION_DISPATCHER_ANNOTATION_PROCESSOR = "org.permissionsdispatcher:permissionsdispatcher-processor:${Version.PERMISSION_DISPATCHER}"
const val ANDROID_LIFECYCLE_EXTENSIONS = "androidx.lifecycle:lifecycle-extensions:${Version.ANDROID_LIFECYCLE}"
const val ANDROID_LIFECYCLE_VIEW_MODEL_EXTENSIONS = "androidx.lifecycle:lifecycle-viewmodel-ktx:${Version.ANDROID_LIFECYCLE}"
const val ANDROID_LIFECYCLE_LIVE_DATA_EXTENSIONS = "androidx.lifecycle:lifecycle-livedata-ktx:${Version.ANDROID_LIFECYCLE}"
const val DAGGER = "com.google.dagger:dagger:${Version.DAGGER}"
const val DAGGER_COMPILER = "com.google.dagger:dagger-compiler:${Version.DAGGER}"
const val DAGGER_INJECT_ASSISTED_ANNOTATIONS = "com.squareup.inject:assisted-inject-annotations-dagger2:${Version.DAGGER_INJECT_ASSISTED}"
const val DAGGER_INJECT_ASSISTED_PROCESSOR = "com.squareup.inject:assisted-inject-processor-dagger2:${Version.DAGGER_INJECT_ASSISTED}"
const val DAGGER_COMPONENT_MANAGER = "com.github.valeryponomarenko.componentsmanager:androidx:${Version.DAGGER_COMPONENT_MANAGER}"
const val GLIDE = "com.github.bumptech.glide:glide:${Version.GLIDE}"
const val GLIDE_COMPILER = "com.github.bumptech.glide:compiler:${Version.GLIDE}"
const val GLIDE_OKHTTP_INTEGRATION = "com.github.bumptech.glide:okhttp3-integration:${Version.GLIDE}"
const val RETROFIT = "com.squareup.retrofit2:retrofit:${Version.RETROFIT}"
const val OKHTTP_LOGGING_INTERCEPTOR = "com.squareup.okhttp3:logging-interceptor:${Version.OKHTTP}"
const val OKHTTP = "com.squareup.okhttp3:okhttp-urlconnection:${Version.OKHTTP}"
const val MOSHI = "com.squareup.moshi:moshi:${Version.MOSHI}"
const val MOSHI_CODEGEN = "com.squareup.moshi:moshi-kotlin-codegen:${Version.MOSHI}"
const val MOSHI_RETROFIT = "com.squareup.retrofit2:converter-moshi:${Version.RETROFIT}"
const val COROUTINES_CORE = "org.jetbrains.kotlinx:kotlinx-coroutines-core:${Version.COROUTINES}"
const val COROUTINES_ANDROID = "org.jetbrains.kotlinx:kotlinx-coroutines-android:${Version.COROUTINES}"
const val CICERONE = "ru.terrakok.cicerone:cicerone:${Version.CICERONE}"
const val LEAK_CANARY = "com.squareup.leakcanary:leakcanary-android:${Version.LEAK_CANARY}"
const val CHUCKER = "com.github.chuckerteam.chucker:library:${Version.CHUCKER}"
const val CHUCKER_NO_OP = "com.github.chuckerteam.chucker:library-no-op:${Version.CHUCKER}"
const val FIREBASE_ANAL = "com.google.firebase:firebase-analytics-ktx:${Version.FIREBASE_ANAL}"
const val FIREBASE_PERF = "com.google.firebase:firebase-perf:${Version.FIREBASE_PERF}"
const val FIREBASE_CRASH = "com.google.firebase:firebase-crashlytics:${Version.FIREBASE_CRASH}"
const val ANDROIDX_SECURE = "androidx.security:security-crypto:${Version.ANDROIDX_SECURE}"
const val ANDROIDX_BIOMETRIC = "androidx.biometric:biometric:${Version.ANDROIDX_BIOMETRIC}"
const val LICENCE_LIBRARY = "com.google.android.gms:play-services-oss-licenses:${Version.LICENCE_LIBRARY}"
}

View File

@ -6,7 +6,6 @@ object Plugins {
const val ANDROID_LIB_PLUGIN_WITH_DEFAULT_CONFIG = "android_lib"
const val KOTLIN_ANDROID = "kotlin-android"
const val KOTLIN_ANDROID_EXTENSIONS = "kotlin-android-extensions"
const val KOTLIN_KAPT = "kotlin-kapt"
const val LICENCE_PLUGIN = "com.google.android.gms.oss-licenses-plugin"

View File

@ -1,47 +0,0 @@
object Version {
const val ANDROID_PLUGIN = "4.0.0"
const val KOTLIN = "1.3.72"
const val ANDROIDX = "1.1.0"
const val ANDROIDX_CORE = "1.2.0"
const val ANDROIDX_APPCOMPAT = "1.0.2"
const val ANDROIDX_CONSTRAINT = "2.0.0-beta4"
const val ANDROIDX_FRAGMENT = "1.2.1"
const val ANDROIDX_SECURE = "1.0.0-rc02"
const val ANDROIDX_BIOMETRIC = "1.0.1"
const val ANDROID_MATERIAL = "1.2.0-rc01"
const val SWIPE_TO_REFRESH = "1.0.0"
const val ANDROID_LIFECYCLE = "2.2.0"
const val PERMISSION_DISPATCHER = "4.8.0"
const val DAGGER = "2.27"
const val DAGGER_INJECT_ASSISTED = "0.5.2"
const val DAGGER_COMPONENT_MANAGER = "2.1.0"
const val GLIDE = "4.10.0"
const val RETROFIT = "2.8.1"
const val OKHTTP = "3.14.1"
const val MOSHI = "1.9.2"
const val COROUTINES = "1.3.7"
const val CICERONE = "5.1.0"
const val FIREBASE_ANAL = "17.4.3"
const val FIREBASE_CRASH = "17.1.0"
const val FIREBASE_PERF = "19.0.7"
const val GOOGLE_SERVICES_PLUGIN = "4.3.3"
const val FIREBASE_CRASH_PLUGIN = "2.2.0"
const val LEAK_CANARY = "2.4"
const val CHUCKER = "3.2.0"
const val LICENCE_LIBRARY = "17.0.0"
}

View File

@ -0,0 +1,10 @@
import org.gradle.api.artifacts.MinimalExternalModuleDependency
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.provider.Provider
internal val VersionCatalog.stdlib: Provider<MinimalExternalModuleDependency>
get() = getLibrary("stdLib")
private fun VersionCatalog.getLibrary(library: String) = findLibrary(library).get()

View File

@ -0,0 +1,7 @@
import org.gradle.api.artifacts.VersionCatalog
val VersionCatalog.sdkCompile: String
get() = findVersion("compileSdk").get().requiredVersion
val VersionCatalog.sdkMin: String
get() = findVersion("minSdk").get().requiredVersion

View File

@ -1,41 +0,0 @@
import com.android.build.gradle.BaseExtension
fun BaseExtension.addBuildType(
type: BuildType,
buildScriptDir: String
) {
buildTypes {
getByName(type.name) {
isMinifyEnabled = type.optimizeAndObfuscate
isShrinkResources = type.optimizeAndObfuscate
if (type.optimizeAndObfuscate) {
val proguardFile = if (AndroidConfig.RELEASE_DEBUGGABLE) "noObfuscate.pro" else "obfuscate.pro"
setProguardFiles(listOfNotNull(
getDefaultProguardFile("proguard-android-optimize.txt"),
"$buildScriptDir/proguard/$proguardFile",
"proguard/projectConfig.pro"
))
}
}
}
}
sealed class BuildType(
val name: String,
val optimizeAndObfuscate: Boolean
) {
object Debug : BuildType(
name = "debug",
optimizeAndObfuscate = false
)
object Release : BuildType(
name = "release",
optimizeAndObfuscate = true
)
}

View File

@ -15,7 +15,7 @@ fun BaseExtension.configureSigningConfig(getRelativeFile: (String) -> File) {
create(SigningConfig.CONFIG_NAME) {
storeFile = getRelativeFile(SigningConfig.PATH_TO_KEYSTORE_FILE)
storePassword = Environment.STORE_PASSWORD.getenv() ?: SigningConfig.DEFAULT_STORE_PASSWORD
keyAlias = Environment.KEY_ALIAS.getenv() ?: SigningConfig.DEFAULT_KEY_ALIAS
keyAlias = Environment.ALIAS.getenv() ?: SigningConfig.DEFAULT_KEY_ALIAS
keyPassword = Environment.KEY_PASSWORD.getenv() ?: SigningConfig.DEFAULT_KEY_PASSWORD
}
}

View File

@ -2,6 +2,9 @@ package plugins
import Plugins
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.getByType
class AndroidAppPlugin : BaseAndroidPlugin() {

View File

@ -6,7 +6,7 @@ import org.gradle.api.Project
class AndroidLibPlugin : BaseAndroidPlugin() {
override fun apply(target: Project) {
target.plugins.apply(Plugins.ANDROID_LIBRARY)
// target.plugins.apply(Plugins.ANDROID_LIBRARY)
super.apply(target)
}

View File

@ -4,15 +4,18 @@ import AndroidConfig
import BuildType
import Plugins
import com.android.build.gradle.BaseExtension
import kotlinStd
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.internal.impldep.junit.runner.Version.id
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import sdkMin
abstract class BaseAndroidPlugin : Plugin<Project> {
override fun apply(target: Project) {
@ -22,9 +25,9 @@ abstract class BaseAndroidPlugin : Plugin<Project> {
}
private fun Project.configurePlugins() {
plugins.apply(Plugins.KOTLIN_ANDROID)
plugins.apply(Plugins.KOTLIN_ANDROID_EXTENSIONS)
plugins.apply(Plugins.KOTLIN_KAPT)
// plugins.apply(Plugins.KOTLIN_KAPT)
// plugins.apply("com.android.library")
plugins.apply("org.jetbrains.kotlin.android")
}
private fun Project.configureAndroid() = extensions.getByType<BaseExtension>().run {
@ -32,41 +35,35 @@ abstract class BaseAndroidPlugin : Plugin<Project> {
buildToolsVersion = AndroidConfig.BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion(AndroidConfig.MIN_SDK_VERSION)
targetSdkVersion(AndroidConfig.TARGET_SDK_VERSION)
minSdk = libs.sdkMin.toIntOrNull() ?: 24
targetSdk = AndroidConfig.TARGET_SDK_VERSION
versionCode = AndroidConfig.VERSION_CODE
versionName = AndroidConfig.VERSION_NAME
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
coreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
isCoreLibraryDesugaringEnabled = true
}
buildFeatures.viewBinding = true
tasks.withType(KotlinCompile::class.java) {
kotlinOptions {
jvmTarget = "1.8"
}
}
if (AndroidConfig.RELEASE_DEBUGGABLE) {
buildTypes {
getByName(BuildType.Release.name) {
isDebuggable = true
}
jvmTarget = "17"
}
}
}
private fun Project.configureDependencies() = dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
kotlinStd()
add("coreLibraryDesugaring", "com.android.tools:desugar_jdk_libs:1.0.5")
add("coreLibraryDesugaring", "com.android.tools:desugar_jdk_libs:2.0.4")
}
private fun DependencyHandler.implementation(dependencyNotation: Any): Dependency? =
add("implementation", dependencyNotation)
}
internal val Project.libs: VersionCatalog
get() = extensions.getByType<VersionCatalogsExtension>().named("libs")

1
data/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

38
data/build.gradle.kts Normal file
View File

@ -0,0 +1,38 @@
plugins {
id(Plugins.ANDROID_APP_PLUGIN_WITH_DEFAULT_CONFIG)
}
android {
namespace = "ru.template.data"
compileSdk = 34
defaultConfig {
minSdk = 24
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation(libs.androidx.core)
implementation(libs.androidx.compat)
implementation(libs.material)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.espresso.core)
}

View File

@ -0,0 +1,24 @@
package ru.template.data
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("ru.template.data.test", appContext.packageName)
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>

View File

@ -0,0 +1,17 @@
package ru.template.data
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}

1
domain/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

38
domain/build.gradle.kts Normal file
View File

@ -0,0 +1,38 @@
plugins {
id(Plugins.ANDROID_APP_PLUGIN_WITH_DEFAULT_CONFIG)
}
android {
namespace = "ru.template.domain"
compileSdk = 34
defaultConfig {
minSdk = 24
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation(libs.androidx.core)
implementation(libs.androidx.compat)
implementation(libs.material)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.espresso.core)
}

View File

@ -0,0 +1,24 @@
package ru.template.domain
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("ru.template.domain.test", appContext.packageName)
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>

View File

@ -0,0 +1,17 @@
package ru.template.domain
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}

View File

@ -6,6 +6,7 @@ versionName = "1.0.0"
compileSdk = "34"
targetSdk = "34"
minSdk = "23"
jvmBytecode = "17"
kotlin = "1.8.22"
androidGradlePlugin = "8.1.4"
@ -63,6 +64,9 @@ firebasePerf = "1.4.2"
# Groupie
groupie = "2.10.1"
junit = "4.13.2"
androidx-test-ext-junit = "1.1.5"
espresso-core = "3.5.1"
[libraries]
@ -71,6 +75,8 @@ androidx-compat = { group = "androidx.appcompat", name = "appcompat", version.re
androidx-constraint = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "androidxConstraint" }
androidx-core = { group = "androidx.core", name = "core-ktx", version.ref = "androidxCore" }
androidx-recycler = { group = "androidx.recyclerview", name = "recyclerview", version.ref = "androidxRecycler" }
android-gradle-plugin = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" }
kotlin-gradle-plugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
# KotlinX
coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "coroutines" }
@ -144,6 +150,9 @@ groupie = { group = "com.github.lisawray.groupie", name = "groupie", version.ref
groupie-viewbinding = { group = "com.github.lisawray.groupie", name = "groupie-viewbinding", version.ref = "groupie" }
javapoet = { module = "com.squareup:javapoet", version = "javapoet" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-test-ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-ext-junit" }
espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espresso-core" }
[plugins]

View File

@ -1,6 +1,6 @@
#Tue Mar 19 16:59:59 GMT+07:00 2024
#Fri Mar 22 17:00:19 GMT+07:00 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

1
mobile_services/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

View File

@ -0,0 +1,38 @@
plugins {
id(Plugins.ANDROID_APP_PLUGIN_WITH_DEFAULT_CONFIG)
}
android {
namespace = "ru.template.mobile.services"
compileSdk = 34
defaultConfig {
minSdk = 24
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation(libs.androidx.core)
implementation(libs.androidx.compat)
implementation(libs.material)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.espresso.core)
}

View File

@ -0,0 +1,24 @@
package ru.template.mobile.services
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("ru.template.mobile.services.test", appContext.packageName)
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>

View File

@ -0,0 +1,17 @@
package ru.template.mobile.services
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}

View File

@ -17,4 +17,4 @@ dependencyResolutionManagement {
}
}
include(":app")
include(":app", ":data", ":domain", ":mobile_services")