21

android Button background failure

when I try to add

android:background="@drawable/roundedbutton"

into the .xml

<Button
     android:id="@+id/button_stop"
     style="@android:style/Widget.Button"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_margin="3dp"
     android:background="@drawable/roundedbutton"
     android:layout_weight="1"
     android:text="stop"
     android:textSize="18sp" />

the roundedbutton.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/colorPrimary" />
    <corners android:bottomRightRadius="8dp"
        android:bottomLeftRadius="8dp"
        android:topRightRadius="8dp"
        android:topLeftRadius="8dp"/>
</shape>

the button became blank and Android Studio 3.2.1 gives an error

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.view.ViewGroup_Delegate.drawShadow(ViewGroup_Delegate.java:86)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:58)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.draw_Original(View.java:20075)
    at android.view.View_Delegate.draw(View_Delegate.java:68)
    at android.view.View.draw(View.java:19849)
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4333)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:63)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.draw_Original(View.java:20075)
    at android.view.View_Delegate.draw(View_Delegate.java:68)
    at android.view.View.draw(View.java:19849)
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4333)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:63)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.draw_Original(View.java:20075)
    at android.view.View_Delegate.draw(View_Delegate.java:68)
    at android.view.View.draw(View.java:19849)
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4333)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:63)
    at android.view.ViewGroup.drawChild(ViewGroup.java:4333)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112)
    at android.view.View.draw_Original(View.java:20210)
    at android.view.View_Delegate.draw(View_Delegate.java:56)
    at android.view.View.draw(View.java:20177)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:405)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:552)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:426)
    at com.android.layoutlib.bridge.BridgeRenderSession.render(BridgeRenderSession.java:108)
    at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:154)
    at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:136)
    at com.android.tools.idea.rendering.RenderTask.lambda$renderInner$5(RenderTask.java:671)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Thank you.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Jack Wilson
  • 6,065
  • 12
  • 29
  • 52

8 Answers8

25

UPDATE

The fix for this will be included in Android Studio 3.5 Canary 2

enter image description here

java.lang.IllegalArgumentException: Invalid Region.Op - only INTERSECT and DIFFERENCE

The issue with targetSdkVersion 28

Looks like this started being enforced in P: https://developer.android.com/reference/android/graphics/Canvas#clipRect(android.graphics.RectF,%20android.graphics.Region.Op)

also reported here

Temporary solution for your case

Use

<corners
    android:radius="8dp"/>

instead of

<corners android:bottomRightRadius="8dp"
    android:bottomLeftRadius="8dp"
    android:topRightRadius="8dp"
    android:topLeftRadius="8dp"/>
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
  • 1
    I could not find bug report on Google's tracker, so I created the issue: https://issuetracker.google.com/issues/121235731 – Matej Drobnič Dec 19 '18 at 09:18
  • @MatejDrobnič great and thanks i have added that Google's tracker, in my answer let wait and see google response – AskNilesh Dec 19 '18 at 09:25
  • 1
    Don't know about Canary, but this is not fixed in Android Studio 3.5 Build #AI-191.8026.42.35.5791312, (built on August 9, 2019) – Orabîg Sep 29 '19 at 09:04
  • Indeed. as of today, this issue still haven't been fixed. BTW, to download a more error prone compiler (and a whole new IDE), Canary, is NOT considered a 100% valid solution so you guys should watch out – Oz Shabat Oct 16 '19 at 12:37
8

Same issue occur in my end, it was fixed now Change the targetSdkVersion 28 to 27 in build.gradle. Thanks

Praveen Kumar Verma
  • 2,988
  • 2
  • 18
  • 31
  • 1
    No need to downgrade your `targetSdkVersion` because the issue has been resolved in `Android Studio 3.5 Canary 2` – AskNilesh Jan 18 '19 at 04:41
  • 1
    Right @NileshRathod but When user is not able to upgrade Android Studio 3.5 then change the targetSdkVersion 28 to 27 – Praveen Kumar Verma Jan 23 '19 at 06:55
  • agree with you but as I said its just work around not a perfect solution – AskNilesh Jan 23 '19 at 06:57
  • @NileshRathod I know about this. Thanks – Praveen Kumar Verma Jan 23 '19 at 06:58
  • @NileshRathod i try my project in Android Studio 3.5 Canary 2 and same error remain until now. Do you know the date release of Android Studio 3.5 stable version? – Paraskevas Ntsounos Jan 24 '19 at 15:16
  • Tried 27 and 26 without luck :( – WindRider Feb 26 '19 at 20:45
  • Tried also AS 3.5 Canary 6 - no luck! – WindRider Mar 03 '19 at 01:07
  • 1
    I am getting this Exception from AFreeChart in its draw method. I would expect it needs REPLACE, which is what it uses. I have changed to AndroidX, which requires API 28 and have also implemented AppCompatActivity (because my menus in Android 9 are Black on a dark background even though they have been fine for a long time). So going back is more than just changing back to API 27. It would be nice if they get it fixed. – Kenneth Evans Apr 06 '19 at 19:58
  • On thinking about this, the Exception I am getting is in android.graphics.Canvas.checkValidClipOp(). It happens if CompatiblityVersion >= Build.VERSION_CODES.P(=28) and op is ERASE. I don't see how a new version of Android Studio is going to fix that. – Kenneth Evans Apr 07 '19 at 00:59
  • When will the Android Studio 3.5 release come out? How to develop when there are those issues without choosing the canary versions? – skm Aug 02 '19 at 05:39
  • 1
    android studio 3.6.2 and problem still exists – Alireza Farahani Apr 25 '20 at 13:07
8

This is what fixed it for me:

.setCropShape(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ? CropImageView.CropShape.RECTANGLE : CropImageView.CropShape.OVAL)
Marc Alexander
  • 761
  • 11
  • 24
4

For those of you who still haven't figured out how to solve this, just Try to read the error and understand where it stems from.

Read all the call stack, don't be afraid, line by line, and find the library which use the function clipRect().

Its probably an old library which you need to updated (in my scenario, it was Lottie, which didn't report in the build.gradle that I haven't had the most recent library).

Oz Shabat
  • 1,434
  • 17
  • 16
1

For me it got fixed up when I changed

<corners android:bottomRightRadius="8dp"
android:bottomLeftRadius="8dp"
android:topRightRadius="8dp"
android:topLeftRadius="8dp"/>

to

<corners
android:radius="8dp"/>

in my buttondesign.xml file and replaced

<Button
        android:id="@+id/btn_verify"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/yellow_btn_bg"
        android:text="Verify"
        android:textSize="16sp"
        android:layout_margin="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="20dp"
        android:layout_weight="1"
        android:textColor="@color/white"
        />

with

<Button
        android:id="@+id/btn_verify"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/yellow_btn_bg"
        android:text="Verify"
        android:textSize="16sp"
        android:layout_margin="20dp"
        android:layout_weight="1"
        android:textColor="@color/white"
        />
Nima
  • 3,309
  • 6
  • 27
  • 44
0

try removing " style="@android:style/Widget.Button"".

 <Button
            android:id="@+id/button_stop"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="3dp"
            android:background="@drawable/roundedbutton"
            android:layout_weight="1"
            android:text="stop"
            android:textSize="18sp" />
Abdul
  • 356
  • 3
  • 14
0

if you encounter this problem in an activity while you do not detect the report with the solutions proposed here, it is that you use an instatble library which generates this error .. try to change the version of this library, and your problem will be solved

0

In my case the error occurred from a library i found the fix inside the issues of the corresponding github to that library

Farido mastr
  • 464
  • 5
  • 12