didi / booster

🚀Optimizer for mobile applications
https://booster.johnsonlee.io
Apache License 2.0
4.83k stars 576 forks source link

transformClassesWithBoosterForXXXDebug报错 #401

Closed livelitoday closed 1 year ago

livelitoday commented 1 year ago

Please provide the following informations.

kotlin.collections.CollectionsKt.maxOrNull(Ljava/lang/Iterable;)Ljava/lang/Comparable;

Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

geekzxiang commented 1 year ago

有解决么?

yfyh20231002 commented 1 year ago

has a same issure

yfyh20231002 commented 1 year ago

将Booster version 4.14.0改为成功了

CodeIdeal commented 1 year ago

@johnsonlee

我最近用一个新项目集成booster也遇到了这个问题。

分析了下,发现应该是因为booster前段时间升级gradle之后,embeddedKotlinVersion从原来的1.3.61(gradle 6.2)升级到了1.5.31(gradle 7.4).然后在源码中大量使用了被@SinceKotlin("xxx") (其中xxx大于1.4)注释的api方法.

比如这个issue提到的Iterable.maxOrNull方法:

@SinceKotlin("1.4")
public fun <T : Comparable<T>> Iterable<T>.maxOrNull(): T? {
    val iterator = iterator()
    if (!iterator.hasNext()) return null
    var max = iterator.next()
    while (iterator.hasNext()) {
        val e = iterator.next()
        if (max < e) max = e
    }
    return max
}

gradle embeddedKotlinVersion参见: https://docs.gradle.org/current/userguide/compatibility.html#kotlin

这样会导致仍在使用小于等于6.7的gradle版本(对应embeddedKotlinVersion为1.3.72)的人,在编译时使用的仍是低版本的kotlin,从而找不到在源码中使用的高版本的kotlin api.

不知道直接把build.gradle中这里的kotlin version: https://github.com/didi/booster/blob/cd35577df987e2151bdf423d2473622e0f007552/build.gradle#L4 直接替换为: ext.kotlin_version = "1.5.31" 能不能解决这个问题,同时也不影响兼容性?

johnsonlee commented 1 year ago

参考:https://johnsonlee.io/2022/12/07/do-you-really-know-kotlin-compatibility/