buildSrc/src/main/kotlin/conventions/android.kt
changeset 114 ab226603d0f5
parent 85 0c23a1d2e16a
equal deleted inserted replaced
113:5986ef49853d 114:ab226603d0f5
    19  * You should have received a copy of the GNU General Public License
    19  * You should have received a copy of the GNU General Public License
    20  * along with AboutOss.  If not, see <http://www.gnu.org/licenses/>.
    20  * along with AboutOss.  If not, see <http://www.gnu.org/licenses/>.
    21  */
    21  */
    22 package com.geekorum.build.conventions
    22 package com.geekorum.build.conventions
    23 
    23 
       
    24 import com.android.build.api.dsl.CommonExtension
       
    25 import com.android.build.api.dsl.KotlinMultiplatformAndroidLibraryTarget
    24 import com.android.build.gradle.BaseExtension
    26 import com.android.build.gradle.BaseExtension
    25 import org.gradle.api.Project
    27 import org.gradle.api.Project
       
    28 import org.gradle.api.plugins.ExtensionAware
    26 import org.gradle.kotlin.dsl.findByType
    29 import org.gradle.kotlin.dsl.findByType
       
    30 import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
       
    31 
       
    32 const val ANDROID_COMPILE_SDK = 37
       
    33 const val ANDROID_MIN_SDK = 28
    27 
    34 
    28 fun Project.conventionForAndroidProject() {
    35 fun Project.conventionForAndroidProject() {
       
    36     // new AGP 9 built-in kotlin use these configuration
       
    37     extensions.findByType<CommonExtension>()?.apply {
       
    38         compileSdk = ANDROID_COMPILE_SDK
       
    39         defaultConfig.minSdk = ANDROID_MIN_SDK
       
    40     }
       
    41 
       
    42     // new androidLibrary in multiplatform project
       
    43     extensions.findByType<KotlinMultiplatformExtension>()?.apply {
       
    44         (this as ExtensionAware).extensions.findByType<KotlinMultiplatformAndroidLibraryTarget>()?.apply {
       
    45             compileSdk {
       
    46                 version = release(ANDROID_COMPILE_SDK)
       
    47             }
       
    48             minSdk = ANDROID_MIN_SDK
       
    49             aarMetadata {
       
    50                 minCompileSdk = ANDROID_COMPILE_SDK
       
    51             }
       
    52         }
       
    53     }
       
    54 
    29     extensions.findByType<BaseExtension>()?.apply {
    55     extensions.findByType<BaseExtension>()?.apply {
    30         setCompileSdkVersion(36)
    56         setCompileSdkVersion(ANDROID_COMPILE_SDK)
    31         defaultConfig {
    57         defaultConfig {
    32             minSdk = 28
    58             minSdk = ANDROID_MIN_SDK
    33             aarMetadata {
    59             aarMetadata {
    34                 minCompileSdk = 28
    60                 minCompileSdk = ANDROID_COMPILE_SDK
    35             }
    61             }
    36         }
    62         }
    37     }
    63     }
    38 }
    64 }