android-image-picker icon indicating copy to clipboard operation
android-image-picker copied to clipboard

Android 9 - usage method from dark greylist, reflection - crash

Open tasjapr opened this issue 3 years ago • 0 comments

not always reproduced!

Actual Behavior

app crashes with next stacktrace:

I/ResourcesCompat: Failed to retrieve rebase() method
    java.lang.NoSuchMethodException: rebase []
        at java.lang.Class.getMethod(Class.java:2068)
        at java.lang.Class.getDeclaredMethod(Class.java:2047)
        at androidx.core.content.res.ResourcesCompat$ThemeCompat$ImplApi23.rebase(ResourcesCompat.java:544)
        at androidx.core.content.res.ResourcesCompat$ThemeCompat.rebase(ResourcesCompat.java:520)
        at androidx.appcompat.app.AppCompatDelegateImpl.attachBaseContext2(AppCompatDelegateImpl.java:468)
        at androidx.appcompat.app.AppCompatActivity.attachBaseContext(AppCompatActivity.java:139)
        at com.esafirm.imagepicker.features.ImagePickerActivity.attachBaseContext(ImagePickerActivity.java:37)
        at android.app.Activity.attach(Activity.java:7051)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2888)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3063)
        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:1823)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:198)
        at android.app.ActivityThread.main(ActivityThread.java:6729)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

if you add the following code for debugging Non Sdk Api Usage:

StrictMode.setVmPolicy(
                VmPolicy.Builder()
                    .detectNonSdkApiUsage()
                    .penaltyLog()
                    .build()
            )

then we get the following debug information:

Accessing hidden method Landroid/content/res/Resources$Theme;->rebase()V (dark greylist, reflection)
D/StrictMode: StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: Landroid/content/res/Resources$Theme;->rebase()V
        at android.os.StrictMode.lambda$static$1(StrictMode.java:428)
        at android.os.-$$Lambda$StrictMode$lu9ekkHJ2HMz0jd3F8K8MnhenxQ.accept(Unknown Source:2)
        at java.lang.Class.getDeclaredMethodInternal(Native Method)
        at java.lang.Class.getMethod(Class.java:2064)
        at java.lang.Class.getDeclaredMethod(Class.java:2047)
        at androidx.core.content.res.ResourcesCompat$ThemeCompat$ImplApi23.rebase(ResourcesCompat.java:544)
        at androidx.core.content.res.ResourcesCompat$ThemeCompat.rebase(ResourcesCompat.java:520)
        at androidx.appcompat.app.AppCompatDelegateImpl.attachBaseContext2(AppCompatDelegateImpl.java:468)
        at androidx.appcompat.app.AppCompatActivity.attachBaseContext(AppCompatActivity.java:139)
        at com.esafirm.imagepicker.features.ImagePickerActivity.attachBaseContext(ImagePickerActivity.java:37)
        at android.app.Activity.attach(Activity.java:7051)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2888)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3063)
        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:1823)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:198)
        at android.app.ActivityThread.main(ActivityThread.java:6729)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)

as far as I can see, then the problem is in the call ImagePickerActivity.attachBaseContext(ImagePickerActivity.java:37)

Steps to Reproduce the Problem

just call ImagePicker.cameraOnly().start(this) from Fragment

Specifications

  • Image Picker Version: 2.4.5
  • Android OS: 9
  • Phone: Nokia 5

tasjapr avatar Nov 22 '21 16:11 tasjapr