Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: agp is unable to handle the classes under the default package co… #28

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/src/main/java/CustomDialog.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import android.view.View

class CustomDialog {
private var view: View? = null

public fun setListener() {
view?.setOnClickListener {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.growingio.android.plugin.hook.TargetMethod
import com.growingio.android.plugin.util.ClassContextCompat
import com.growingio.android.plugin.util.info
import com.growingio.android.plugin.util.unNormalize
import com.growingio.android.plugin.util.normalize
import org.objectweb.asm.ClassVisitor
import org.objectweb.asm.Handle
import org.objectweb.asm.MethodVisitor
Expand Down Expand Up @@ -52,6 +53,7 @@ class DesugarClassVisitor(
interfaces: Array<out String>?
) {
super.visit(version, access, name, signature, superName, interfaces)
if (!name.isNullOrBlank()) className = normalize(name)
}

override fun visitMethod(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package com.growingio.android.plugin.util
* @author cpacm 2023/8/18
*/
interface ClassContextCompat {
val className: String
var className: String

fun isAssignable(subClazz: String, superClazz: String): Boolean

Expand Down
4 changes: 2 additions & 2 deletions autotracker-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ buildscript {
set("kotlin_version", "1.8.20")
set("agp_version", "8.1.0")
set("low_agp_version", "4.2.2")
set("releaseVersion", "4.3.0")
set("releaseVersionCode", 40300)
set("releaseVersion", "4.3.1-SNAPSHOT")
set("releaseVersionCode", 40301)
}
}

Expand Down
4 changes: 2 additions & 2 deletions autotracker-gradle-plugin/saas-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
extra.apply {
set("saasVersion", "2.10.2")
set("saasVersionCode", "21002")
set("saasVersion", "2.10.3-SNAPSHOT")
set("saasVersionCode", "21003")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal abstract class SaasAutoTrackerFactory :

override fun createClassVisitor(classContext: ClassContext, nextClassVisitor: ClassVisitor): ClassVisitor {
val classContextCompat = object : ClassContextCompat {
override val className = classContext.currentClassData.className
override var className = classContext.currentClassData.className

override fun isAssignable(subClazz: String, superClazz: String): Boolean {
return classContext.loadClassData(normalize(subClazz))?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal class SaasAutoTrackerTransform(
val apiVersion = autoTrackerWriter.getApi()

val classContextCompat = object : ClassContextCompat {
override val className = classReader.className
override var className = classReader.className
override fun isAssignable(subClazz: String, superClazz: String): Boolean {
return context.klassPool.get(superClazz).isAssignableFrom(subClazz)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ internal class GioKitCodeVisitor(
interfaces: Array<out String>?
) {
super.visit(version, access, name, signature, superName, interfaces)
if (!name.isNullOrBlank()) context.className = normalize(name)
}

override fun visitMethod(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.growingio.android.plugin.giokit

import com.growingio.android.plugin.util.ClassContextCompat
import com.growingio.android.plugin.util.normalize
import org.objectweb.asm.ClassVisitor
import org.objectweb.asm.MethodVisitor

Expand All @@ -16,6 +17,18 @@ internal class GioKitInjectVisitor(
private val giokitParams: GioKitParams
) : ClassVisitor(api, ncv), ClassContextCompat by classContext {

override fun visit(
version: Int,
access: Int,
name: String?,
signature: String?,
superName: String?,
interfaces: Array<out String>?
) {
super.visit(version, access, name, signature, superName, interfaces)
if (!name.isNullOrBlank()) classContext.className = normalize(name)
}

override fun visitMethod(
access: Int,
methodName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ internal abstract class AutoTrackerFactory :

override fun createClassVisitor(classContext: ClassContext, nextClassVisitor: ClassVisitor): ClassVisitor {
val classContextCompat = object : ClassContextCompat {
override val className = classContext.currentClassData.className
// AsmInstrumentationManager#instrumentClassesFromDirectoryToDirectory 移除文件名方法无包名(相对路径为当前路径)时不生效
// 非日志输出时,尽可能使用visit方法参数中返回的name
override var className = classContext.currentClassData.className

override fun isAssignable(subClazz: String, superClazz: String): Boolean {
return classContext.loadClassData(normalize(subClazz))?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ internal class AutoTrackerTransform(
val apiVersion = autoTrackerWriter.getApi()

val classContextCompat = object : ClassContextCompat {
override val className = classReader.className
override var className = classReader.className
override fun isAssignable(subClazz: String, superClazz: String): Boolean {
return context.klassPool.get(superClazz).isAssignableFrom(subClazz)
}
Expand Down
5 changes: 3 additions & 2 deletions autotracker-gradle-plugin/src/test/kotlin/GradleTestRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class GradleTestRunner(val tempFolder: TemporaryFolder) {
tempFolder.newFolder("src", "main", "java", "growingio")
tempFolder.newFolder("src", "test", "java", "growingio")
tempFolder.newFolder("src", "main", "res")
addDependencies("implementation 'com.growingio.android:autotracker:4.0.0-SNAPSHOT'")
addDependencies("implementation 'com.growingio.android:autotracker:4.3.0'")
}

// Adds project dependencies, e.g. "implementation <group>:<id>:<version>"
Expand Down Expand Up @@ -223,7 +223,8 @@ class GradleTestRunner(val tempFolder: TemporaryFolder) {
.withArguments(listOf("--stacktrace", "assembleDebug") + additionalTasks)
.withPluginClasspath()
.withDebug(true) // Add this line to enable attaching a debugger to the gradle test invocation
.forwardOutput()
.forwardStdError(System.err.writer())
.forwardStdOutput(System.out.writer())

// Data class representing a Gradle Test run result.
data class Result(
Expand Down
Loading