1

When I try to use Custom Keyboard got an exception on Android P Beta, everything is working fine until Android Oreo but recently got a crash. Just try to figure out which class might be responsible for the exception. Currently unable to access complete custom keyboard code so not posting the code.

java.lang.IllegalArgumentException: Invalid Region.Op - only INTERSECT and DIFFERENCE are allowed
    at android.graphics.Canvas.checkValidClipOp(Canvas.java:779)
    at android.graphics.Canvas.clipRect(Canvas.java:826)
    at android.inputmethodservice.KeyboardView.onBufferDraw(KeyboardView.java:666)
    at android.inputmethodservice.KeyboardView.onDraw(KeyboardView.java:647)
    at android.view.View.draw(View.java:20205)
    at android.view.View.updateDisplayListIfDirty(View.java:19080)
    at android.view.View.draw(View.java:19933)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.draw(View.java:20208)
    at android.view.View.updateDisplayListIfDirty(View.java:19080)
    at android.view.View.draw(View.java:19933)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.updateDisplayListIfDirty(View.java:19071)
    at android.view.View.draw(View.java:19933)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.updateDisplayListIfDirty(View.java:19071)
    at android.view.View.draw(View.java:19933)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.updateDisplayListIfDirty(View.java:19071)
    at android.view.View.draw(View.java:19933)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.updateDisplayListIfDirty(View.java:19071)
    at android.view.View.draw(View.java:19933)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.draw(View.java:20208)
    at com.android.internal.policy.DecorView.draw(DecorView.java:784)
    at android.view.View.updateDisplayListIfDirty(View.java:19080)
    at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:685)
    at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:691)
    at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:799)
    at android.view.ViewRootImpl.draw(ViewRootImpl.java:3259)
    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3075)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2455)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1443)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7125)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:935)
    at android.view.Choreographer.doCallbacks(Choreographer.java:747)
    at android.view.Choreographer.doFrame(Choreographer.java:682)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:921)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6649)
    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:826)
Nikhil
  • 1,023
  • 17
  • 35

2 Answers2

3

It actually tells you the reason:

only INTERSECT and DIFFERENCE are allowed

The reason is written here:

This method was deprecated in API level 26. Region.Op values other than INTERSECT and DIFFERENCE have the ability to expand the clip. The canvas clipping APIs are intended to only expand the clip as a result of a restore operation. This enables a view parent to clip a canvas to clearly define the maximal drawing area of its children. The recommended alternative calls are clipRect(RectF) and clipOutRect(RectF); As of API Level API level Build.VERSION_CODES.P only INTERSECT and DIFFERENCE are valid Region.Op parameters.

So you either have to use lower targetSdk version (which you shouldn't, because Google will force you to use at least 26 it by the end of the year), or you fix it by using your clipping via the canvas in a different way.

I've asked a question about it here, of what's the alternative.

android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • I am also face the same issue with different library named "Android Week view" please check this Link as well https://github.com/alamkanak/Android-Week-View/issues/511. my problem is when I compile the app with newer version it crash only in device not in the Emulator , and the same calendar functionality working fine on "P" with same library if I download the build that I submitted since 1.5 months back , any idea – nivritgupta Jul 19 '18 at 14:18
  • @nivritgupta This is the same library that I've handled. It's not being developed anymore, and the only fork I've seen that has some updates is this one: https://github.com/Quivr/Android-Week-View , but even there it has a lot of issues. So I've forked a fork of it (this: https://github.com/Quachero/Android-Week-View ) , changed it a lot, and fixed this issue on the way . Here's my fork (of a fork, of a fork) : https://github.com/AndroidDeveloperLB/Android-Week-View . Here's my pull request: https://github.com/Quivr/Android-Week-View/pull/97 , shows a lot of what I did. – android developer Jul 19 '18 at 16:18
  • you converted all this library into kotlin that is amazing currently I am checking the demo app if everything is going fine then I ll use your library in my project . I have one last question can I use your kotlin library in my java project ? – nivritgupta Jul 19 '18 at 16:59
  • @nivritgupta Of course. And please consider contributing. Currently I've noticed 2 issues that I didn't fix yet : RTL support (meaning all will be on opposite direction for languages such as Hebrew and Arabic), slow on old devices compared to Google Calendar app (maybe due to a lot of Calendar instances ). – android developer Jul 19 '18 at 20:48
0

you just need to remove this line :

.setCropShape(CropImageView.CropShape.OVAL)