Skip to content

Commit

Permalink
修复多线程bug
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyJingFish committed Dec 6, 2024
1 parent d2cb57b commit a3d8a15
Show file tree
Hide file tree
Showing 14 changed files with 434 additions and 211 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
plugins {
//必须项 👇 apply 设置为 true 自动为所有module“预”配置debugMode,false则按下边步骤五的方式二
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.3.1" apply true
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.3.2" apply true
}
```
<details>
Expand All @@ -136,7 +136,7 @@
buildscript {
dependencies {
//必须项 👇
classpath 'io.github.FlyJingFish.AndroidAop:android-aop-plugin:2.3.1'
classpath 'io.github.FlyJingFish.AndroidAop:android-aop-plugin:2.3.2'
}
}
// 👇加上这句自动为所有module“预”配置debugMode,不加则按下边步骤五的方式二
Expand Down Expand Up @@ -191,7 +191,7 @@
//必须项 👇
plugins {
...
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.3.1"//最好放在最后一行
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.3.2"//最好放在最后一行
}
```

Expand All @@ -217,18 +217,18 @@ plugins {
dependencies {
//必须项 👇
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-core:2.3.1'
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-core:2.3.2'
//非必须项 👇这个包提供了一些常见的注解切面
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-extra:2.3.1'
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-extra:2.3.2'
//必须项 👇如果您项目内已经有了这项不用加也可以
implementation 'androidx.appcompat:appcompat:1.3.0' // 至少在1.3.0及以上
//非必须项 👇,如果你想自定义切面需要用到,⚠️支持Java和Kotlin代码写的切面
ksp 'io.github.FlyJingFish.AndroidAop:android-aop-ksp:2.3.1'
ksp 'io.github.FlyJingFish.AndroidAop:android-aop-ksp:2.3.2'
//非必须项 👇,如果你想自定义切面需要用到,⚠️只适用于Java代码写的切面
annotationProcessor 'io.github.FlyJingFish.AndroidAop:android-aop-processor:2.3.1'
annotationProcessor 'io.github.FlyJingFish.AndroidAop:android-aop-processor:2.3.2'
//⚠️上边的 android-aop-ksp 和 android-aop-processor 二选一
}
```
Expand Down
14 changes: 7 additions & 7 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Depend on the plug-in in <code>build.gradle</code> in the <strong>project root d
plugins {
//Required item 👇 apply is set to true to automatically apply debugMode to all modules, if false, follow step 5 below.
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.3.1" apply true
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.3.2" apply true
}
```
<details>
Expand All @@ -133,7 +133,7 @@ Depend on the plug-in in <code>build.gradle</code> in the <strong>project root d
buildscript {
dependencies {
//Required items 👇
classpath 'io.github.FlyJingFish.AndroidAop:android-aop-plugin:2.3.1'
classpath 'io.github.FlyJingFish.AndroidAop:android-aop-plugin:2.3.2'
}
}
//👇Add this sentence to automatically apply debugMode to all modules. If not, follow step 5 below.
Expand Down Expand Up @@ -181,7 +181,7 @@ Depend on the plug-in in <code>build.gradle</code> in the <strong>project root d
//Required items 👇
plugins {
...
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.3.1"
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.3.2"
}
```

Expand Down Expand Up @@ -211,17 +211,17 @@ plugins {
dependencies {
//Required items 👇
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-core:2.3.1'
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-core:2.3.2'
//Optional 👇This package provides some common annotation aspects
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-extra:2.3.1'
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-extra:2.3.2'
//Required item 👇If you already have this item in your project, you don’t need to add it.
implementation 'androidx.appcompat:appcompat:1.3.0' // At least in 1.3.0 and above
//Optional 👇, if you want to customize aspects, you need to use them, ⚠️supports aspects written in Java and Kotlin code
ksp 'io.github.FlyJingFish.AndroidAop:android-aop-ksp:2.3.1'
ksp 'io.github.FlyJingFish.AndroidAop:android-aop-ksp:2.3.2'
//Optional 👇, if you want to customize aspects, you need to use them, ⚠️only applies to aspects written in Java code
annotationProcessor 'io.github.FlyJingFish.AndroidAop:android-aop-processor:2.3.1'
annotationProcessor 'io.github.FlyJingFish.AndroidAop:android-aop-processor:2.3.2'
//⚠️Choose one of the above android-aop-ksp and android-aop-processor
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ object WovenIntoCode {
val newMethodName = Utils.getTargetMethodName(oldMethodName, className, descriptor)
if (newMethodName == name && oldDescriptor == descriptor){
wovenRecord.add(value)
WovenInfoUtils.addAopMethodCutInnerClassInfoInvokeMethod(className,newMethodName,descriptor)
// WovenInfoUtils.addAopMethodCutInnerClassInfoInvokeMethod(className,newMethodName,descriptor)
}
if (value.overrideMethod && oldMethodName == name && oldDescriptor == descriptor){
overrideRecord.add(value)
Expand Down Expand Up @@ -280,7 +280,7 @@ object WovenIntoCode {
if (hasReplace && mv != null && access.isHasMethodBody()) {
mv = MethodReplaceInvokeAdapter(className,oldSuperName,name,descriptor,mv)
}
WovenInfoUtils.addAopMethodCutInnerClassInfoInvokeMethod(className,newMethodName,descriptor)
// WovenInfoUtils.addAopMethodCutInnerClassInfoInvokeMethod(className,newMethodName,descriptor)
RemoveAnnotation(mv)
} else {
null
Expand Down Expand Up @@ -537,6 +537,62 @@ object WovenIntoCode {
return wovenBytes
}


fun searchSuspendClass(
inputStreamBytes: ByteArray?,
methodRecordHashMap: HashMap<String, MethodRecord>,
) {
val cr = ClassReader(inputStreamBytes)

fun visitMethod4Record(access: Int,
name: String,
descriptor: String,
signature: String?,
exceptions: Array<String?>?,
className:String ){
methodRecordHashMap.forEach { (_: String, value: MethodRecord) ->
val oldMethodName = value.methodName
val oldDescriptor = value.descriptor
val newMethodName = Utils.getTargetMethodName(oldMethodName, className, descriptor)

WovenInfoUtils.addAopMethodCutInnerClassInfoInvokeMethod(className,newMethodName,descriptor)
}


}
cr.accept(object : ClassVisitor(ASM9) {
lateinit var clazzName:String
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)
clazzName = name
}
override fun visitMethod(
access: Int,
name: String,
descriptor: String,
signature: String?,
exceptions: Array<String?>?
): MethodVisitor? {
visitMethod4Record(access, name, descriptor, signature, exceptions, clazzName)
val mv = super.visitMethod(
access,
name,
descriptor,
signature,
exceptions
)
return mv
}
}, ClassReader.EXPAND_FRAMES)
}

private fun CtMethod.addKeepClassAnnotation(constPool: ConstPool){
val visibleTagAttribute :AttributeInfo? = methodInfo.getAttribute(AnnotationsAttribute.visibleTag)
val annotationsAttribute = if (visibleTagAttribute == null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,27 @@ abstract class AssembleAndroidAopTask : DefaultTask() {
aopTaskUtils.processJarForSearch(file.asFile, addClassMethodRecords, deleteClassMethodRecords)
}
aopTaskUtils.searchJoinPointLocationEnd(addClassMethodRecords, deleteClassMethodRecords)

for (directory in ignoreJarClassPaths) {
val directoryPath = directory.absolutePath
directory.walk().forEach { file ->
aopTaskUtils.processFileForSearchSuspend(file,directory,directoryPath)
}

}
allDirectories.get().forEach { directory ->
val directoryPath = directory.asFile.absolutePath
directory.asFile.walk().forEach { file ->
aopTaskUtils.processFileForSearchSuspend(file,directory.asFile,directoryPath)
}
}
allJars.get().forEach { file ->
if (file.asFile.absolutePath in ignoreJar){
return@forEach
}
aopTaskUtils.processJarForSearchSuspend(file.asFile)
}

}

private fun wovenIntoCode() = runBlocking{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ class CompileAndroidAopTask(
aopTaskUtils.processJarForSearch(file, addClassMethodRecords, deleteClassMethodRecords)
}
aopTaskUtils.searchJoinPointLocationEnd(addClassMethodRecords, deleteClassMethodRecords)

allDirectories.forEach { directory ->
val directoryPath = directory.absolutePath
directory.walk().forEach { file ->
aopTaskUtils.processFileForSearchSuspend(file, directory, directoryPath)
}
}
}
private fun wovenIntoCode() = runBlocking{
val invokeStaticClassName = Utils.extraPackage+".Invoke"+project.name.computeMD5()
Expand Down
Loading

0 comments on commit a3d8a15

Please sign in to comment.