Skip to content

Commit

Permalink
Upgrade to AGP 4.2 and use the new transform API
Browse files Browse the repository at this point in the history
  • Loading branch information
Chao Zhang committed Jun 20, 2021
1 parent 7f9d080 commit 2bcf014
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 128 deletions.
24 changes: 5 additions & 19 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.4.31'
id 'org.jetbrains.dokka' version '1.4.30'
id 'org.jetbrains.kotlin.jvm' version '1.4.32'
id 'org.jetbrains.dokka' version '1.4.32'
id 'java-gradle-plugin'
id 'com.vanniktech.maven.publish' version '0.14.2'
}

repositories {
google()
mavenCentral()
jcenter {
content {
includeGroup "org.jetbrains.trove4j"
includeGroup "org.jetbrains.kotlinx"
}
}
}


Expand All @@ -35,16 +29,8 @@ compileJava {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.31"
constraints {
implementation("org.jetbrains.kotlin:kotlin-reflect:1.4.31") {
because("Android Gradle Plugin 4.1 depends on Kotlin 1.3.72 but we should not mix 1.3 and 1.4.")
}
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.31") {
because("Android Gradle Plugin 4.1 depends on Kotlin 1.3.72 but we should not mix 1.3 and 1.4.")
}
}
implementation 'com.android.tools.build:gradle-api:4.1.3'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.32"
implementation 'com.android.tools.build:gradle-api:4.2.1'
implementation 'org.ow2.asm:asm:9.1'
compileOnly 'com.android.tools.build:gradle:4.1.3'
compileOnly 'com.android.tools.build:gradle:4.2.1'
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kotlin.code.style=official

GROUP=io.github.chao2zhang.livedatadebugger
POM_ARTIFACT_ID=livedatadebugger
VERSION_NAME=0.0.3
VERSION_NAME=0.1.0

POM_NAME=LiveDataDebugger
POM_DESCRIPTION=The gradle plugin to make LiveData universally debuggable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.chao2zhang

import com.android.build.api.instrumentation.*
import org.objectweb.asm.ClassVisitor

@Suppress("UnstableApiUsage")
abstract class LiveDataClassVisitorFactory : AsmClassVisitorFactory<InstrumentationParameters> {

override fun createClassVisitor(classContext: ClassContext, nextClassVisitor: ClassVisitor) =
LiveDataClassVisitor(nextClassVisitor)

override fun isInstrumentable(classData: ClassData) =
classData.className == "androidx.lifecycle.LiveData"
}
15 changes: 11 additions & 4 deletions src/main/kotlin/io/github/chao2zhang/LiveDataDebuggerPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.github.chao2zhang

import com.android.build.api.extension.AndroidComponentsExtension
import com.android.build.api.instrumentation.FramesComputationMode
import com.android.build.api.instrumentation.InstrumentationScope
import com.android.build.gradle.AppExtension
import com.android.build.gradle.AppPlugin
import org.gradle.api.Plugin
Expand All @@ -8,10 +11,14 @@ import org.gradle.api.Project
class LiveDataDebuggerPlugin : Plugin<Project> {

override fun apply(project: Project) {
project.plugins.withType(AppPlugin::class.java) { plugin ->
project.extensions.configure(AppExtension::class.java) { appExtension ->
appExtension.registerTransform(LiveDataTransform(project.logger))
}
val androidComponents = project.extensions.getByType(AndroidComponentsExtension::class.java)
androidComponents.onVariants {
it.transformClassesWith(
classVisitorFactoryImplClass = LiveDataClassVisitorFactory::class.java,
scope = InstrumentationScope.ALL,
instrumentationParamsConfig = { }
)
it.setAsmFramesComputationMode(FramesComputationMode.COMPUTE_FRAMES_FOR_INSTRUMENTED_METHODS)
}
}
}
104 changes: 0 additions & 104 deletions src/main/kotlin/io/github/chao2zhang/LiveDataTransform.kt

This file was deleted.

0 comments on commit 2bcf014

Please sign in to comment.