Issue
Introduction: I am running my instrumented tests of my SDK on AWS Device Farm, but I see that it crashes when I try to get the pixel color of a Bitmap (bitmap.getColor(x, y)).
Problem: I test the color of different view objects, as image views, and I found a way to do it converting the view to a Bitmap and then extracting one certain pixel color. Works well on all my emulators and physical devices. Not in all AWS Device Farm devices with API 28 and below, I have tested it in a API 28 local emulator and indeed, the test crashes.
Exception Stacktrace:
----- begin exception -----
06-21 06:19:52.542 30511 30551 E TestRunner: java.lang.NoSuchMethodError: No virtual method getColor(II)Landroid/graphics/Color; in class Landroid/graphics/Bitmap; or its super classes (declaration of 'android.graphics.Bitmap' appears in /system/framework/framework.jar)
06-21 06:19:52.542 30511 30551 E TestRunner: at com.mopinion.ignition.ui.fragments.FormsFragmentTest$withImageViewColorFilter$1.matchesSafely(FormsFragmentTest.kt:273)
06-21 06:19:52.542 30511 30551 E TestRunner: at com.mopinion.ignition.ui.fragments.FormsFragmentTest$withImageViewColorFilter$1.matchesSafely(FormsFragmentTest.kt:268)
06-21 06:19:52.542 30511 30551 E TestRunner: at androidx.test.espresso.matcher.BoundedMatcher.matches(BoundedMatcher.java:7)
06-21 06:19:52.542 30511 30551 E TestRunner: at androidx.test.espresso.matcher.ViewMatchers.assertThat(ViewMatchers.java:3)
06-21 06:19:52.542 30511 30551 E TestRunner: at androidx.test.espresso.assertion.ViewAssertions$MatchesViewAssertion.check(ViewAssertions.java:11)
06-21 06:19:52.542 30511 30551 E TestRunner: at androidx.test.espresso.ViewInteraction$SingleExecutionViewAssertion.check(ViewInteraction.java:2)
06-21 06:19:52.542 30511 30551 E TestRunner: at androidx.test.espresso.ViewInteraction$2.call(ViewInteraction.java:12)
06-21 06:19:52.542 30511 30551 E TestRunner: at androidx.test.espresso.ViewInteraction$2.call(ViewInteraction.java:1)
06-21 06:19:52.542 30511 30551 E TestRunner: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
06-21 06:19:52.542 30511 30551 E TestRunner: at android.os.Handler.handleCallback(Handler.java:789)
06-21 06:19:52.542 30511 30551 E TestRunner: at android.os.Handler.dispatchMessage(Handler.java:98)
06-21 06:19:52.542 30511 30551 E TestRunner: at android.os.Looper.loop(Looper.java:164)
06-21 06:19:52.542 30511 30551 E TestRunner: at android.app.ActivityThread.main(ActivityThread.java:6944)
06-21 06:19:52.542 30511 30551 E TestRunner: at java.lang.reflect.Method.invoke(Native Method)
06-21 06:19:52.542 30511 30551 E TestRunner: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
06-21 06:19:52.542 30511 30551 E TestRunner: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
06-21 06:19:52.542 30511 30551 E TestRunner:
----- end exception -----
Is there any better way to test the color of a view? or to test the bitmap color on APIs <= 28? of course I have different cases where I set a background drawable, or a ColorFilter or a ColorStateList, so its a bit tricky.
Thank you in advance!
Solution
Solution:
After reading the documentation, the function:
Bitmap.getColor(x, y)
was added on API 29, meaning on lower versions < 29 won't work as I could prove.
Better implement:
Bitmap.getPixel(x, y)
this function returns the pixel color as well and was added in API 1 so will work an all API levels.
Answered By - MACROSystems
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.