vmadalin / easypermissions-ktx

🔓 Kotlin version of the popular google/easypermissions wrapper library to simplify basic system permissions logic on Android M or higher.
https://firebaseopensource.com/projects/googlesamples/easypermissions/
Apache License 2.0
382 stars 38 forks source link

Cryptic error trying to instantiate TestSupportFragmentActivity #13

Open mtotschnig opened 2 years ago

mtotschnig commented 2 years ago

Basic Information

Device type: GIONEE S10L OS version: Android 9 EasyPermissions version: 1.0.0

Describe the problem

I have got one crash report from crashlytics with the following stacktrace.

Fatal Exception: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.totschnig.myexpenses/com.vmadalin.easypermissions.components.TestSupportFragmentActivity}: java.lang.ClassNotFoundException: Didn't find class "com.vmadalin.easypermissions.components.TestSupportFragmentActivity" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/org.totschnig.myexpenses-Wq04CPgZmNJUUtoxLQjTGg==/base.apk"],nativeLibraryDirectories=[/data/app/org.totschnig.myexpenses-Wq04CPgZmNJUUtoxLQjTGg==/lib/arm64, /system/lib64]]
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2881)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:193)
       at android.app.ActivityThread.main(ActivityThread.java:6718)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by java.lang.ClassNotFoundException: Didn't find class "com.vmadalin.easypermissions.components.TestSupportFragmentActivity" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/org.totschnig.myexpenses-Wq04CPgZmNJUUtoxLQjTGg==/base.apk"],nativeLibraryDirectories=[/data/app/org.totschnig.myexpenses-Wq04CPgZmNJUUtoxLQjTGg==/lib/arm64, /system/lib64]]
       at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
       at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:69)
       at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
       at android.app.Instrumentation.newActivity(Instrumentation.java:1215)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2869)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:193)
       at android.app.ActivityThread.main(ActivityThread.java:6718)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

I have no idea if the user uses some tool that inspects the APK and does some weird stuff with it, or if this is a legit use of my app and the OS screws up. In any case, it might be safer to move the references to test activities out of the main AndroidManifest into the test source set.

dabarnard commented 2 years ago

I have started seeing similar crashes on Android 8.1 devices in an app of mine. Also version 1.0.0 of the library.

@mtotschnig did you manage to find the cause of this?

mtotschnig commented 1 year ago

@dabarnard The crash is quite easy to reproduce. From adb call (with your application_id) adb shell am start -n "{application_id}/com.vmadalin.easypermissions.components.TestSupportFragmentActivity" The cause is that references to this activity along with two others that exist only for tests, are erroneously added to the AndroidManifest that gets merged into your production APK.