1
+ package com.tencent.shadow.coding.common_aar_settings
2
+
3
+ import com.android.build.gradle.BaseExtension
4
+ import org.gradle.api.JavaVersion
5
+ import org.gradle.api.Plugin
6
+ import org.gradle.api.Project
7
+ import org.gradle.api.plugins.ExtensionAware
8
+ import org.gradle.api.plugins.ExtraPropertiesExtension
9
+ import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
10
+
11
+ class CommonAarSettingsPlugin : Plugin <Project > {
12
+
13
+ override fun apply (project : Project ) {
14
+ project.pluginManager.apply (" com.android.library" )
15
+ project.pluginManager.apply (" com.tencent.shadow.internal.aar-to-jar" )
16
+
17
+ val android = project.extensions.getByName(" android" ) as BaseExtension
18
+
19
+ configVersions(project, android)
20
+
21
+ keepOldAGPBehavior(android, project)
22
+
23
+ addCommonDependencies(project)
24
+ }
25
+
26
+ private fun addCommonDependencies (project : Project ) {
27
+ project.dependencies.add(" implementation" , " com.tencent.shadow.coding:lint" )
28
+ }
29
+
30
+ private fun keepOldAGPBehavior (
31
+ android : BaseExtension ,
32
+ project : Project
33
+ ) {
34
+ // Starting in version 4.2, AGP will use the Java 8 language level by default.
35
+ // To keep the old behavior, specify Java 7 explicitly.
36
+ // https://developer.android.com/studio/releases/gradle-plugin?hl=lt#java-8-default
37
+ android.compileOptions {
38
+ it.sourceCompatibility = JavaVersion .VERSION_1_7
39
+ it.targetCompatibility = JavaVersion .VERSION_1_7
40
+ }
41
+
42
+ // For Kotlin projects, compile to Java 6 instead of 7
43
+ project.afterEvaluate {
44
+ val kotlinOptions = (it.extensions.getByName(" android" ) as ExtensionAware ).extensions
45
+ .findByType(KotlinJvmOptions ::class .java)
46
+ kotlinOptions?.apply {
47
+ jvmTarget = " 1.6"
48
+ }
49
+ }
50
+
51
+ android.defaultConfig.buildConfigField(
52
+ " String" ,
53
+ " VERSION_NAME" ,
54
+ " \" ${android.defaultConfig.versionName} \" "
55
+ )
56
+ }
57
+
58
+ private fun configVersions (
59
+ project : Project ,
60
+ android : BaseExtension
61
+ ) {
62
+ val ext = project.extensions.getByName(" ext" ) as ExtraPropertiesExtension
63
+
64
+ android.compileSdkVersion(ext[" COMPILE_SDK_VERSION" ] as Int )
65
+
66
+ android.defaultConfig {
67
+ it.minSdk = ext[" MIN_SDK_VERSION" ] as Int
68
+ it.targetSdk = ext[" TARGET_SDK_VERSION" ] as Int
69
+ it.versionCode = ext[" VERSION_CODE" ] as Int
70
+ it.versionName = ext[" VERSION_NAME" ] as String
71
+ it.testInstrumentationRunner = " android.support.test.runner.AndroidJUnitRunner"
72
+ }
73
+ }
74
+
75
+ }
0 commit comments