kanyun-inc / Kace

Kace: Kotlin Android Compatible Extensions, a framework for assisting in the seamless migration from kotlin-android-extensions
Apache License 2.0
261 stars 11 forks source link

Android7.1平台中生成的代码不适配 #39

Closed cfy137000 closed 1 year ago

cfy137000 commented 1 year ago

项目环境:

  1. Android7.1平台, 系统应用, 使用源码中编译出的android.jar,
  2. 插件version = "1.7.0-1.0.4"

问题描述: KACE在编译时会生成类似于如下代码:

internal inline val View.webContainer
    get() = findViewById<ScrollWebFrameLayout>(R.id.webContainer)

通过findViewById方法来确定View, 但是在Android7.1平台中, findViewById方法并没有添加带泛型的实现, 只有返回View的实现, 所以在编译时, 上述的方法会报错

在Android7.1中, 应该将生成的代码修改为类似下面这种形式:

internal inline val View.webContainer
    get() = findViewById(R.id.webContainer) as ScrollWebFrameLayout

综上, 希望增加一个开关能够开启针对低版本Android的适配

RicardoJiang commented 1 year ago
internal inline val View.webContainer
    get() = findViewById(R.id.webContainer) as ScrollWebFrameLayout

直接修改成这样,当findViewById返回为 null 的时候会抛出异常,修改为as?又会导致返回类型强制变为可空

在低版本上有问题本质上因为 compileSdkVersion 过低且你们是系统应用无法修改,应该是个比较小众的需求,抱歉本库暂不支持,如果有需要可以 fork 代码修改