Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Huawei device with Android 9 throws java.lang.NoSuchFieldException while calling reflect() #4

Open
Navneet7k opened this issue Dec 9, 2019 · 12 comments
Labels
android bug Something isn't working

Comments

@Navneet7k
Copy link

try {
      reflect(editor::class, "mSelectHandleCenter").set(editor, centerDrawable)
      reflect(editor::class, "mSelectHandleLeft").set(editor, leftDrawable)
      reflect(editor::class, "mSelectHandleRight").set(editor, rightDrawable)
    } catch (e : NoSuchFieldException) {
      Log.e("Huawei",e.message)
    }

This produces the following exception :

java.lang.NoSuchFieldException: No field mSelectHandleCenter in class Lhuawei/com/android/internal/widget/HwEditor; (declaration of 'huawei.com.android.internal.widget.HwEditor' appears in /system/framework/hwEmui.jar)

@saket
Copy link
Owner

saket commented Dec 9, 2019

Oh wow! Did not expect OEMs to modify the Editor class, but then relying on reflection wasn't supposed to be foolproof. It might be a better idea to set android:colorControlActivated from a xml theme and intercept the color at runtime.

@saket saket added the bug Something isn't working label Dec 9, 2019
@saket
Copy link
Owner

saket commented Dec 9, 2019

Wanna send a PR with a fix @Navneet7k, along the lines of how the cursor color is overridden?

@saket
Copy link
Owner

saket commented Dec 10, 2019

Fixed along with #8 in a7b3c92. Thanks for reporting!

@saket saket closed this as completed Dec 10, 2019
@saket saket reopened this Dec 10, 2019
@saket
Copy link
Owner

saket commented Dec 10, 2019

Whoops my bad. Your device is running on Android 9 so this issue isn't fixed yet.

@saket saket added the android label Dec 10, 2019
@Navneet7k
Copy link
Author

hi, couldn't reply yesterday, is this fixed

@Navneet7k
Copy link
Author

Navneet7k commented Dec 10, 2019

wrapping it with a try catch gave the following result in huawei

Screenshot_20191210_110525

@saket
Copy link
Owner

saket commented Dec 10, 2019

That's… strange. How are the handles getting colored if the code fails to run? 😮

Can you share a screenshot of the cursor? This is what I see on vanilla Android:

image

@Navneet7k
Copy link
Author

maybe because the handler drawable is not getting set(which we wrapped in try) , but the drawable color is later set to accent color.

screenshot of cursor :
Screenshot_20191210_114243

@saket
Copy link
Owner

saket commented Dec 10, 2019

That sounds very suspicious 😄

It looks like there might be a way to set the handles from Xml: https://stackoverflow.com/a/15133928/2511884. Press could intercept the Resources#getDrawable() calls and tint them. I'll take a stab at this sometime.

@TheDanileron
Copy link

Look at Danil. B and Jared Rummler answers here: https://stackoverflow.com/questions/15133926/how-to-change-color-appearance-of-edittext-select-handle-anchor/63121585#63121585
It shows how to do it from the code

@saket
Copy link
Owner

saket commented Jul 27, 2020

@saket
Copy link
Owner

saket commented Jan 17, 2021

Can someone check if they're still running into this crash with Press v1.7.0?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
android bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants