Skip to content

Commit 6febc0d

Browse files
jaredsburrowsbenjamin-bader
authored andcommitted
Remove SdkResolver (#232)
* remove sdkresolver, use android dsl * use local.properties or ANDROID_HOME for the Android sdk for tests
1 parent 5a0f4c5 commit 6febc0d

File tree

5 files changed

+21
-224
lines changed

5 files changed

+21
-224
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
build/
55
*.log
66
local.properties
7+
out/

src/main/kotlin/com/getkeepsafe/dexcount/Plugin.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import com.android.build.gradle.api.BaseVariantOutput
2727
import com.android.build.gradle.api.LibraryVariant
2828
import com.android.build.gradle.api.TestVariant
2929
import com.android.repository.Revision
30-
import com.getkeepsafe.dexcount.sdkresolver.SdkResolver
3130
import org.gradle.api.DomainObjectCollection
3231
import org.gradle.api.Plugin
3332
import org.gradle.api.Project
@@ -38,10 +37,13 @@ import kotlin.reflect.KClass
3837

3938
open class DexMethodCountPlugin: Plugin<Project> {
4039
companion object {
41-
var sdkLocation: File? = SdkResolver.resolve(null)
42-
const val VERSION_3_ZERO_FIELD: String = "com.android.builder.Version" // <= 3.0
43-
const val VERSION_3_ONE_FIELD: String = "com.android.builder.model.Version" // > 3.1
44-
const val AGP_VERSION_FIELD: String = "ANDROID_GRADLE_PLUGIN_VERSION"
40+
var sdkLocation: File? = null
41+
private const val VERSION_3_ZERO_FIELD: String = "com.android.builder.Version" // <= 3.0
42+
private const val VERSION_3_ONE_FIELD: String = "com.android.builder.model.Version" // > 3.1
43+
private const val AGP_VERSION_FIELD: String = "ANDROID_GRADLE_PLUGIN_VERSION"
44+
private const val AGP_VERSION_3: String = "3.0.0"
45+
private const val ANDROID_EXTENSION_NAME = "android"
46+
private const val SDK_DIRECTORY_METHOD = "getSdkDirectory"
4547
}
4648

4749
override fun apply(project: Project) {
@@ -64,18 +66,17 @@ open class DexMethodCountPlugin: Plugin<Project> {
6466
exception = e
6567
}
6668

67-
println(gradlePluginVersion)
68-
6969
if (gradlePluginVersion == null && exception != null) {
7070
throw IllegalStateException("dexcount requires the Android plugin to be configured", exception)
7171
} else if (gradlePluginVersion == null) {
7272
throw IllegalStateException("dexcount requires the Android plugin to be configured")
7373
}
7474

75-
sdkLocation = SdkResolver.resolve(project)
75+
val android = project.extensions.findByName(ANDROID_EXTENSION_NAME)
76+
sdkLocation = android?.javaClass?.getMethod(SDK_DIRECTORY_METHOD)?.invoke(android) as File?
7677

7778
val gradlePluginRevision = Revision.parseRevision(gradlePluginVersion, Revision.Precision.PREVIEW)
78-
val threeOhRevision = Revision.parseRevision("3.0.0")
79+
val threeOhRevision = Revision.parseRevision(AGP_VERSION_3)
7980

8081
val isBuildTools3 = gradlePluginRevision.compareTo(threeOhRevision, Revision.PreviewComparison.IGNORE) >= 0
8182

src/main/kotlin/com/getkeepsafe/dexcount/sdkresolver/SdkResolver.kt

Lines changed: 0 additions & 174 deletions
This file was deleted.

src/main/kotlin/com/getkeepsafe/dexcount/sdkresolver/System.kt

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/test/groovy/com/getkeepsafe/dexcount/DexFileSpec.groovy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ final class DexFileSpec extends Specification {
2525

2626
def "test AAR dexcount"() {
2727
given:
28+
if (new File("local.properties").exists()) {
29+
Properties properties = new Properties()
30+
InputStream inputStream = new FileInputStream("local.properties")
31+
properties.load(inputStream)
32+
inputStream.close()
33+
DexMethodCountPlugin.sdkLocation = new File(properties.getProperty("sdk.dir"))
34+
} else {
35+
DexMethodCountPlugin.sdkLocation = new File(System.getenv("ANDROID_HOME"))
36+
}
37+
2838
def aarFile = temporaryFolder.newFile("test.aar")
2939

3040
getClass().getResourceAsStream('/android-beacon-library-2.7.aar').withStream { input ->

0 commit comments

Comments
 (0)