goyourfly / DailyBread

No description, website, or topics provided.
3 stars 0 forks source link

Kotlin 混淆时的 Bug #32

Open goyourfly opened 5 years ago

goyourfly commented 5 years ago

混淆 Kotlin 代码时碰到一个问题,类似下面多层嵌套的写法,在编译时报错

class Error {
    fun run() {
        with(Unit) {
            runLambda {
                runLambda {
                    println("Hello, World!")
                }
            }
        }
    }
    private fun runLambda(lambda: () -> Unit) = lambda()
}

编译报错: image 有人已经给 Kotlin 团队提过这个 Bug,但是直到刚刚发布的 Kotlin: 1.3.30 版本这个 Bug 还在。

目前能绕过去的办法有两种:

  1. 在混淆文件中禁止报错 -dontwarn com.example.threadnumtest.Error$run$1$1$1,我试了一下没有问题,但这种办法一定要在打包后充分测试
  2. 把这段报错的代码转成对应的 Java 代码
QQabby commented 5 years ago

这样的嵌套看起来很糟糕啊

goyourfly commented 5 years ago

https://github.com/Kotlin/anko https://github.com/Kotlin/anko/issues/400 用 DSL 写布局不可避免的使用嵌套,这种混淆错误也不知道什么写法会出发,反正有的嵌套报错,有的没问题