buildSrc/src/main/kotlin/conventions/android.kt
author Da Risk <da_risk@geekorum.com>
Mon, 04 May 2026 18:00:16 -0400
changeset 114 ab226603d0f5
parent 85 0c23a1d2e16a
permissions -rw-r--r--
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
85
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     1
/*
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     2
 * AboutOss is a utility library to retrieve and display
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     3
 * opensource licenses in Android applications.
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     4
 *
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     5
 * Copyright (C) 2023-2025 by Frederic-Charles Barthelery.
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     6
 *
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     7
 * This file is part of AboutOss.
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     8
 *
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     9
 * AboutOss is free software: you can redistribute it and/or modify
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    10
 * it under the terms of the GNU General Public License as published by
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    11
 * the Free Software Foundation, either version 3 of the License, or
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    12
 * (at your option) any later version.
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    13
 *
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    14
 * AboutOss is distributed in the hope that it will be useful,
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    17
 * GNU General Public License for more details.
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    18
 *
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    19
 * You should have received a copy of the GNU General Public License
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    20
 * along with AboutOss.  If not, see <http://www.gnu.org/licenses/>.
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    21
 */
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    22
package com.geekorum.build.conventions
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    23
114
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    24
import com.android.build.api.dsl.CommonExtension
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    25
import com.android.build.api.dsl.KotlinMultiplatformAndroidLibraryTarget
85
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    26
import com.android.build.gradle.BaseExtension
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    27
import org.gradle.api.Project
114
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    28
import org.gradle.api.plugins.ExtensionAware
85
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    29
import org.gradle.kotlin.dsl.findByType
114
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    30
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    31
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    32
const val ANDROID_COMPILE_SDK = 37
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    33
const val ANDROID_MIN_SDK = 28
85
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    34
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    35
fun Project.conventionForAndroidProject() {
114
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    36
    // new AGP 9 built-in kotlin use these configuration
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    37
    extensions.findByType<CommonExtension>()?.apply {
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    38
        compileSdk = ANDROID_COMPILE_SDK
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    39
        defaultConfig.minSdk = ANDROID_MIN_SDK
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    40
    }
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    41
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    42
    // new androidLibrary in multiplatform project
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    43
    extensions.findByType<KotlinMultiplatformExtension>()?.apply {
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    44
        (this as ExtensionAware).extensions.findByType<KotlinMultiplatformAndroidLibraryTarget>()?.apply {
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    45
            compileSdk {
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    46
                version = release(ANDROID_COMPILE_SDK)
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    47
            }
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    48
            minSdk = ANDROID_MIN_SDK
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    49
            aarMetadata {
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    50
                minCompileSdk = ANDROID_COMPILE_SDK
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    51
            }
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    52
        }
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    53
    }
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    54
85
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    55
    extensions.findByType<BaseExtension>()?.apply {
114
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    56
        setCompileSdkVersion(ANDROID_COMPILE_SDK)
85
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    57
        defaultConfig {
114
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    58
            minSdk = ANDROID_MIN_SDK
85
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    59
            aarMetadata {
114
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents: 85
diff changeset
    60
                minCompileSdk = ANDROID_COMPILE_SDK
85
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    61
            }
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    62
        }
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    63
    }
0c23a1d2e16a build: add few conventions scripts
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    64
}