Skip to content

Commit 2bcf014

Browse files
author
Chao Zhang
committed
Upgrade to AGP 4.2 and use the new transform API
1 parent 7f9d080 commit 2bcf014

File tree

5 files changed

+31
-128
lines changed

5 files changed

+31
-128
lines changed

build.gradle

+5-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
plugins {
2-
id 'org.jetbrains.kotlin.jvm' version '1.4.31'
3-
id 'org.jetbrains.dokka' version '1.4.30'
2+
id 'org.jetbrains.kotlin.jvm' version '1.4.32'
3+
id 'org.jetbrains.dokka' version '1.4.32'
44
id 'java-gradle-plugin'
55
id 'com.vanniktech.maven.publish' version '0.14.2'
66
}
77

88
repositories {
99
google()
1010
mavenCentral()
11-
jcenter {
12-
content {
13-
includeGroup "org.jetbrains.trove4j"
14-
includeGroup "org.jetbrains.kotlinx"
15-
}
16-
}
1711
}
1812

1913

@@ -35,16 +29,8 @@ compileJava {
3529
}
3630

3731
dependencies {
38-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.31"
39-
constraints {
40-
implementation("org.jetbrains.kotlin:kotlin-reflect:1.4.31") {
41-
because("Android Gradle Plugin 4.1 depends on Kotlin 1.3.72 but we should not mix 1.3 and 1.4.")
42-
}
43-
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.31") {
44-
because("Android Gradle Plugin 4.1 depends on Kotlin 1.3.72 but we should not mix 1.3 and 1.4.")
45-
}
46-
}
47-
implementation 'com.android.tools.build:gradle-api:4.1.3'
32+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.32"
33+
implementation 'com.android.tools.build:gradle-api:4.2.1'
4834
implementation 'org.ow2.asm:asm:9.1'
49-
compileOnly 'com.android.tools.build:gradle:4.1.3'
35+
compileOnly 'com.android.tools.build:gradle:4.2.1'
5036
}

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ kotlin.code.style=official
22

33
GROUP=io.github.chao2zhang.livedatadebugger
44
POM_ARTIFACT_ID=livedatadebugger
5-
VERSION_NAME=0.0.3
5+
VERSION_NAME=0.1.0
66

77
POM_NAME=LiveDataDebugger
88
POM_DESCRIPTION=The gradle plugin to make LiveData universally debuggable
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.github.chao2zhang
2+
3+
import com.android.build.api.instrumentation.*
4+
import org.objectweb.asm.ClassVisitor
5+
6+
@Suppress("UnstableApiUsage")
7+
abstract class LiveDataClassVisitorFactory : AsmClassVisitorFactory<InstrumentationParameters> {
8+
9+
override fun createClassVisitor(classContext: ClassContext, nextClassVisitor: ClassVisitor) =
10+
LiveDataClassVisitor(nextClassVisitor)
11+
12+
override fun isInstrumentable(classData: ClassData) =
13+
classData.className == "androidx.lifecycle.LiveData"
14+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.github.chao2zhang
22

3+
import com.android.build.api.extension.AndroidComponentsExtension
4+
import com.android.build.api.instrumentation.FramesComputationMode
5+
import com.android.build.api.instrumentation.InstrumentationScope
36
import com.android.build.gradle.AppExtension
47
import com.android.build.gradle.AppPlugin
58
import org.gradle.api.Plugin
@@ -8,10 +11,14 @@ import org.gradle.api.Project
811
class LiveDataDebuggerPlugin : Plugin<Project> {
912

1013
override fun apply(project: Project) {
11-
project.plugins.withType(AppPlugin::class.java) { plugin ->
12-
project.extensions.configure(AppExtension::class.java) { appExtension ->
13-
appExtension.registerTransform(LiveDataTransform(project.logger))
14-
}
14+
val androidComponents = project.extensions.getByType(AndroidComponentsExtension::class.java)
15+
androidComponents.onVariants {
16+
it.transformClassesWith(
17+
classVisitorFactoryImplClass = LiveDataClassVisitorFactory::class.java,
18+
scope = InstrumentationScope.ALL,
19+
instrumentationParamsConfig = { }
20+
)
21+
it.setAsmFramesComputationMode(FramesComputationMode.COMPUTE_FRAMES_FOR_INSTRUMENTED_METHODS)
1522
}
1623
}
1724
}

src/main/kotlin/io/github/chao2zhang/LiveDataTransform.kt

-104
This file was deleted.

0 commit comments

Comments
 (0)