wurensen / gradle_plugin_android_aspectjx

A Android gradle plugin that effects AspectJ on Android project and can hook methods in Kotlin, aar and jar file.
Apache License 2.0
365 stars 51 forks source link

支持Kotlin使用协程吗 #14

Closed leeyushi closed 2 years ago

leeyushi commented 2 years ago

原作者的库在编译时没有问题,运行时会报找不到协程: Didn't find class "kotlinx.coroutines.Dispatchers" on path: DexPathList 用了该库后,编译时会报以下错误:

java.util.concurrent.ExecutionException: org.gradle.api.GradleException: Mismatch when building parameterization map. For type 'Pkotlin/jvm/functions/Function3<Pkotlinx/coroutines/flow/FlowCollector<-Ljava/lang/Object;>;Ljava/lang/Object;Lkotlin/Unit;>;' expecting 4:[P1 P2 P3 R] type parameters but found 3:[Pkotlinx/coroutines/flow/FlowCollector<-Ljava/lang/Object;>; Ljava/lang/Object; Lkotlin/Unit;]

leeyushi commented 2 years ago

我在添加这句后解决了问题,但不知你是否会有更好的优化方案: exclude 'FlowCollector' 我帮你点了start,要不是你的错误提示,我找不到FlowCollector有关的线索

wurensen commented 2 years ago

@leeyushi 目前在织入的时候,对于kotlin依赖和协程库本身会出错,我这边在实际使用的时候都是exlcude掉的,exclude规则建议用比较细粒度的,防止期望之外的代码也被exclude掉。

aspectjx {
    // 移除kotlin相关,编译错误和提升速度
    exclude 'kotlin.jvm', 'kotlin.internal'
    exclude 'kotlinx.coroutines.internal', 'kotlinx.coroutines.android'
}