Better-Link-Movement-Method icon indicating copy to clipboard operation
Better-Link-Movement-Method copied to clipboard

NoSuchMethodException: Couldn't find method

Open rajBopche opened this issue 2 years ago • 1 comments

Swapped usage of Linkify with BetterLinkMovementMethod and at the very next app launch, boom. The app builds perfectly however, it crashes on the Splash screen with the following trace.

W/Linkify.v16: reflect applyLink failed: 
    miui.reflect.NoSuchMethodException: Couldn't find method android/text/util/Linkify.applyLink(Ljava/lang/String;IILandroid/text/Spannable;)V
        at com.miui.internal.os.Native.getMethod(Native Method)
        at miui.reflect.Method.of(Method.java:35)
        at com.miui.internal.variable.v16.Android_Text_Util_Linkify_class.<clinit>(Android_Text_Util_Linkify_class.java:70)
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:454)
        at java.lang.Class.forName(Class.java:379)
        at com.miui.internal.variable.AbsClassFactory.create(AbsClassFactory.java:24)
        at com.miui.internal.variable.Android_Text_Util_Linkify_class$Factory.<init>(Android_Text_Util_Linkify_class.java:40)
        at com.miui.internal.variable.Android_Text_Util_Linkify_class$Factory.<init>(Android_Text_Util_Linkify_class.java:26)
        at com.miui.internal.variable.Android_Text_Util_Linkify_class$Factory$1.createInstance(Android_Text_Util_Linkify_class.java:32)
        at com.miui.internal.variable.Android_Text_Util_Linkify_class$Factory$1.createInstance(Android_Text_Util_Linkify_class.java:29)
        at miui.util.SoftReferenceSingleton.get(SoftReferenceSingleton.java:25)
        at com.miui.internal.variable.Android_Text_Util_Linkify_class$Factory.getInstance(Android_Text_Util_Linkify_class.java:44)
        at com.miui.internal.initialization.OverrideHelper.doInitialize(OverrideHelper.java:37)
        at miui.core.SdkManager.initialize(SdkManager.java:99)
        at java.lang.reflect.Method.invoke(Native Method)
        at miui.external.Application.initializeSdk(Application.java:85)
        at miui.external.Application.<init>(Application.java:55)
        at com.xiaomi.activate.Application.<init>(Application.java:9)
        at java.lang.Class.newInstance(Native Method)
        at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
        at android.app.Instrumentation.newApplication(Instrumentation.java:1155)
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1222)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6572)
        at android.app.ActivityThread.access$1500(ActivityThread.java:233)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1914)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:224)
        at android.app.ActivityThread.main(ActivityThread.java:7561)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)

Code:

BetterLinkMovementMethod
                .linkify(Linkify.ALL,textView)
                .setOnLinkClickListener { textView, url ->
                    onClick(url)
                    true
                }

In order to successfully use the app, I have to uninstall the previous build from my phone and then again reinstall the new build. Doing the new reinstall after the old uninstall, magically fixes this issue and the app runs fine.

This issue happens every time I build my app and try to install a new build. Only after uninstalling the new build, I can proceed further. After removing the BetterLinkMovementMethod dependency from gradle and rebuild, the app again behaved normally, something surely is going wrong with this lib.

This happens only when I try to install a new build on my device without uninstalling the previous build. In all the other scenarios, this works fine.

Environment Details. OS: Android 10 QP1A.190711.020 MIUI: 12.0.8 Global Stable Device: Redmi Note 9 (Xiaomi M2003J15SC)

rajBopche avatar Mar 01 '22 12:03 rajBopche

This looks like a gradle issue to me

saket avatar Mar 01 '22 15:03 saket