I want upgrade kotlin gradle plugin from 1.4.32 to 1.5.20,but some code occurred error in lower android version device,such as Xiaomi 5.1.1 & Oppo 6.0.1 & Pixel2 6.0, but it normal in Android 10 devices.
The error info:
java.lang.IncompatibleClassChangeError: Couldn't find com.example.kotlinupgradedemo.ProgressDialogKt.<clinit>[]
    at libcore.reflect.AnnotationAccess.indexToMethod(AnnotationAccess.java:608)
    at libcore.reflect.AnnotationAccess.getEnclosingMethodOrConstructor(AnnotationAccess.java:405)
    at java.lang.Class.isLocalClass(Class.java:1334)
    at java.lang.Class.getCanonicalName(Class.java:378)
    at androidx.lifecycle.Lifecycling.resolveObserverCallbackType(Lifecycling.java:153)
    at androidx.lifecycle.Lifecycling.getObserverConstructorType(Lifecycling.java:146)
    at androidx.lifecycle.Lifecycling.lifecycleEventObserver(Lifecycling.java:83)
    at androidx.lifecycle.LifecycleRegistry$ObserverWithState.<init>(LifecycleRegistry.java:347)
    at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:174)
    at com.example.kotlinupgradedemo.ProgressDialogKt.showProgress(ProgressDialog.kt:36)
    at com.example.kotlinupgradedemo.MainActivity.onCreate(MainActivity.kt:12)
My some code(ProgressDialog.kt):
private val ownerToProgressMap = mutableMapOf<LifecycleOwner, Dialog>()
private val progressCleaner = object : LifecycleObserver {
    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    fun onDestroy(owner : LifecycleOwner) {
        ownerToProgressMap.remove(owner)?.dismiss()
        owner.lifecycle.removeObserver(this)
    }
}
fun LifecycleOwner.showProgress() {
    val context = when (this) {
        is Activity -> this
        is Fragment -> this.context
        else -> null
    } ?: return
    ownerToProgressMap[this]
        ?.apply { show() }
        ?: Dialog(context).also {
            it.setTitle("Tips")
            it.show()
        }.let {
            ownerToProgressMap[this] = it
            this.lifecycle.addObserver(progressCleaner)
        }
}
fun LifecycleOwner.dismissProgress() {
    ownerToProgressMap[this]?.dismiss()
}
I just call it in MainActivity:
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        showProgress()
    }
}
For the complete code, see demo
 
    