androidandroid-layoutandroid-drawable

Custom made drawable with own png file leads to OpenGLRenderer errors in Android


I am having big problems when trying to create own Android drawables based on custom bade png files. The issue is similar to a previous one that I posted some days before (and that has not been resolved: Rendering error in Android's image view by using custom made png file).

I have the following custom made drawable:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <corners android:radius="5dp" />
            <solid android:color="#c07313" />
        </shape>
    </item>
    <item
        android:drawable="@drawable/coal_icon"
        android:width="29dp"
        android:height="29dp"
        android:right="1dp"
        android:left="1dp"
        android:bottom="1dp"
        android:top
            ="1dp"
        android:gravity="left|center_vertical" />
</layer-list>

with the custom made png file "coal_icon"

enter image description here

that I made with Inscape as a vector graphic file and I saved it into the drawable folder of my Android app. However, when an ImageView which should use the custom made drawable as the background should be displayed in my app, I get an unspecific OpernGLRender error and the app crashes (here is just a part of it as the message is quite long):

023-08-25 11:31:57.801 12546-12571 OpenGLRenderer          com.example.game                     E  GL error:  GL_INVALID_OPERATION
2023-08-25 11:31:57.801 12546-12571 OpenGLRenderer          com.example.game                     A  GL errors! frameworks/base/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp:127
2023-08-25 11:31:57.855 12546-12571 om.example.gam          com.example.game                     A  runtime.cc:655] Runtime aborting...
                                                                                                    runtime.cc:655] Dumping all threads without mutator lock held
                                                                                                    runtime.cc:655] All threads:
                                                                                                    runtime.cc:655] DALVIK THREADS (14):
                                                                                                    runtime.cc:655] "RenderThread" prio=10 tid=18 Runnable
                                                                                                    runtime.cc:655]   | group="" sCount=0 dsCount=0 flags=0 obj=0x13340718 self=0xe4a91810
                                                                                                    runtime.cc:655]   | sysTid=12571 nice=-10 cgrp=top-app sched=0/0 handle=0xc33251e0
                                                                                                    runtime.cc:655]   | state=R schedstat=( 8290970061 745199188 7990 ) utm=33 stm=795 core=1 HZ=100
                                                                                                    runtime.cc:655]   | stack=0xc322a000-0xc322c000 stackSize=1008KB
                                                                                                    runtime.cc:655]   | held mutexes= "abort lock" "mutator lock"(shared held)
                                                                                                    runtime.cc:655]   native: #00 pc 00542d9e  /apex/com.android.art/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, BacktraceMap*, char const*, art::ArtMethod*, void*, bool)+110)
                                                                                                    runtime.cc:655]   native: #01 pc 006a0897  /apex/com.android.art/lib/libart.so (art::Thread::DumpStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, bool, BacktraceMap*, bool) const+1015)
                                                                                                    runtime.cc:655]   native: #02 pc 0069a171  /apex/com.android.art/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, bool, BacktraceMap*, bool) const+65)
                                                                                                    runtime.cc:655]   native: #03 pc 006c61b4  /apex/com.android.art/lib/libart.so (art::DumpCheckpoint::Run(art::Thread*)+1172)
                                                                                                    runtime.cc:655]   native: #04 pc 006bf266  /apex/com.android.art/lib/libart.so (art::ThreadList::RunCheckpoint(art::Closure*, art::Closure*)+630)
                                                                                                    runtime.cc:655]   native: #05 pc 006be1ce  /apex/com.android.art/lib/libart.so (art::ThreadList::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, bool)+2446)
                                                                                                    runtime.cc:655]   native: #06 pc 0065227d  /apex/com.android.art/lib/libart.so (art::AbortState::DumpAllThreads(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, art::Thread*) const+445)
                                                                                                    runtime.cc:655]   native: #07 pc 0063984f  /apex/com.android.art/lib/libart.so (art::Runtime::Abort(char const*)+1967)
                                                                                                    runtime.cc:655]   native: #08 pc 00025a23  /apex/com.android.art/lib/libartbase.so (std::__1::__function::__func<void (*)(char const*), std::__1::allocator<void (*)(char const*)>, void (char const*)>::operator()(char const*&&)+35)
                                                                                                    runtime.cc:655]   native: #09 pc 0001588f  /system/lib/libbase.so (android::base::SetAborter(std::__1::function<void (char const*)>&&)::$_3::__invoke(char const*)+79)
                                                                                                    runtime.cc:655]   native: #10 pc 00006dbd  /system/lib/liblog.so (__android_log_assert+285)
                                                                                                    runtime.cc:655]   native: #11 pc 0024dd11  /system/lib/libhwui.so (android::uirenderer::skiapipeline::SkiaOpenGLPipeline::swapBuffers(android::uirenderer::renderthread::Frame const&, bool, SkRect const&, android::uirenderer::FrameInfo*, bool*)+145)
                                                                                                    runtime.cc:655]   native: #12 pc 00257e78  /system/lib/libhwui.so (android::uirenderer::renderthread::CanvasContext::draw()+1112)
                                                                                                    runtime.cc:655]   native: #13 pc 0025ab5f  /system/lib/libhwui.so (_ZNSt3__110__function6__funcIZN7android10uirenderer12renderthread13DrawFrameTask11postAndWaitEvE3$_0NS_9allocatorIS6_EEFvvEEclEv$c303f2d2360db58ed70a2d0ac7ed911b+767)
                                                                                                    runtime.cc:655]   native: #14 pc 0024542d  /system/lib/libhwui.so (android::uirenderer::WorkQueue::process()+285)
                                                                                                    runtime.cc:655]   native: #15 pc 0026cabf  /system/lib/libhwui.so (android::uirenderer::renderthread::RenderThread::threadLoop()+127)
                                                                                                    runtime.cc:655]   native: #16 pc 00015116  /system/lib/libutils.so (android::Thread::_threadLoop(void*)+374)
                                                                                                    runtime.cc:655]   native: #17 pc 000147d9  /system/lib/libutils.so (thread_data_t::trampoline(thread_data_t const*)+457)
                                                                                                    runtime.cc:655]   native: #18 pc 000e6974  /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+100)
                                                                                                    runtime.cc:655]   native: #19 pc 00078567  /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+71)
                                                                                                    runtime.cc:655]   (no managed stack frames)
                                                                                                    runtime.cc:655] 
                                                                                                    runtime.cc:655] "main" prio=10 tid=1 Native
2023-08-25 11:31:57.855 12546-12571 om.example.gam          com.example.game                     A  runtime.cc:655]   | group="" sCount=1 dsCount=0 flags=1 obj=0x71401c28 self=0xe4a80e10
                                                                                                    runtime.cc:655]   | sysTid=12546 nice=-10 cgrp=top-app sched=0/0 handle=0xf2ed1478
                                                                                                    runtime.cc:655]   | state=S schedstat=( 2688356931 656401896 5291 ) utm=144 stm=124 core=0 HZ=100
                                                                                                    runtime.cc:655]   | stack=0xff484000-0xff486000 stackSize=8192KB
                                                                                                    runtime.cc:655]   | held mutexes=
                                                                                                    runtime.cc:655]   native: #00 pc 00000b97  [vdso] (__kernel_vsyscall+7)
                                                                                                    runtime.cc:655]   native: #01 pc 0005ad68  /apex/com.android.runtime/lib/bionic/libc.so (syscall+40)
                                                                                                    runtime.cc:655]   native: #02 pc 0007725e  /apex/com.android.runtime/lib/bionic/libc.so (__futex_wait_ex(void volatile*, bool, int, bool, timespec const*)+142)
                                                                                                    runtime.cc:655]   native: #03 pc 000e5b2e  /apex/com.android.runtime/lib/bionic/libc.so (pthread_cond_wait+62)
                                                                                                    runtime.cc:655]   native: #04 pc 0025a146  /system/lib/libhwui.so (android::uirenderer::renderthread::DrawFrameTask::postAndWait()+182)
                                                                                                    runtime.cc:655]   native: #05 pc 0023922d  /system/lib/libhwui.so (android::android_view_ThreadedRenderer_syncAndDrawFrame(_JNIEnv*, _jobject*, long long, _jlongArray*, int)+109)
                                                                                                    runtime.cc:655]   at android.graphics.HardwareRenderer.nSyncAndDrawFrame(Native method)
                                                                                                    runtime.cc:655]   at android.graphics.HardwareRenderer.syncAndDrawFrame(HardwareRenderer.java:433)
                                                                                                    runtime.cc:655]   at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:658)
                                                                                                    runtime.cc:655]   at android.view.ViewRootImpl.draw(ViewRootImpl.java:4101)
                                                                                                    runtime.cc:655]   at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3828)
                                                                                                    runtime.cc:655]   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3099)
                                                                                                    runtime.cc:655]   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1952)
                                                                                                    runtime.cc:655]   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8171)
                                                                                                    runtime.cc:655]   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:972)
                                                                                                    runtime.cc:655]   at android.view.Choreographer.doCallbacks(Choreographer.java:796)
                                                                                                    runtime.cc:655]   at android.view.Choreographer.doFrame(Choreographer.java:731)
                                                                                                    runtime.cc:655]   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
                                                                                                    runtime.cc:655]   at android.os.Handler.handleCallback(Handler.java:938)
                                                                                                    runtime.cc:655]   at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                    runtime.cc:655]   at android.os.Looper.loop(Looper.java:223)
                                                                                                    runtime.cc:655]   at android.app.ActivityThread.main(ActivityThread.java:7656)
                                                                                                    runtime.cc:655]   at java.lang.reflect.Method.invoke(Native method)
                                                                                                    runtime.cc:655]   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
                                                                                                    runtime.cc:655]   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
                                                                                                    runtime.cc:655] 
                                                                                                    runtime.cc:655] "Signal Catcher" prio=10 tid=6 WaitingInMainSignalCatcherLoop
                                                                                                    runtime.cc:655]   | group="" sCount=1 dsCount=0 flags=1 obj=0x13340268 self=0xe4a80010
                                                                                                    runtime.cc:655]   | sysTid=12556 nice=-20 cgrp=top-app sched=0/0 handle=0xd9cd21e0
                                                                                                    runtime.cc:655]   | state=S schedstat=( 688585 0 1 ) utm=0 stm=0 core=0 HZ=100
                                                                                                    runtime.cc:655]   | stack=0xd9bd7000-0xd9bd9000 stackSize=1008KB
                                                                                                    runtime.cc:655]   | held mutexes=
                                                                                                    runtime.cc:655]   native: #00 pc 00000b99  [vdso] (__kernel_vsyscall+9)
                                                                                                    runtime.cc:655]   native: #01 pc 000ce821  /apex/com.android.runtime/lib/bionic/libc.so (__rt_sigtimedwait+33)
                                                                                                    runtime.cc:655]   native: #02 pc 00086c55  /apex/com.android.runtime/lib/bionic/libc.so (sigwait+69)
                                                                                                    runtime.cc:655]   native: #03 pc 00665f1d  /apex/com.android.art/lib/libart.so (art::SignalCatcher::WaitForSignal(art::Thread*, art::SignalSet&)+461)
                                                                                                    runtime.cc:655]   native: #04 pc 006648ff  /apex/com.android.art/lib/libart.so (art::SignalCatcher::Run(void*)+479)
                                                                                                    runtime.cc:655]   native: #05 pc 000e6974  /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+100)
                                                                                                    runtime.cc:655]   native: #06 pc 00078567  /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+71)
                                                                                                    runtime.cc:655]   (no managed stack frames)
                                                                                                    runtime.cc:655] 
2023-08-25 11:31:57.855 12546-12571 om.example.gam          com.example.game                     A  runtime.cc:655] "perfetto_hprof_listener" prio=10 tid=7 Native (still starting up)
                                                                                                    runtime.cc:655]   | group="" sCount=1 dsCount=0 flags=1 obj=0x0 self=0xe4a83810
                                                                                                    runtime.cc:655]   | sysTid=12557 nice=-20 cgrp=top-app sched=0/0 handle=0xd9bd11e0
                                                                                                    runtime.cc:655]   | state=S schedstat=( 686318 100287 8 ) utm=0 stm=0 core=1 HZ=100
                                                                                                    runtime.cc:655]   | stack=0xd9ad6000-0xd9ad8000 stackSize=1008KB
                                                                                                    runtime.cc:655]   | held mutexes=
                                                                                                    runtime.cc:655]   native: #00 pc 00000b97  [vdso] (__kernel_vsyscall+7)
                                                                                                    runtime.cc:655]   native: #01 pc 000ccf9c  /apex/com.android.runtime/lib/bionic/libc.so (read+28)
                                                                                                    runtime.cc:655]   native: #02 pc 0001aca2  /apex/com.android.art/lib/libperfetto_hprof.so (void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, ArtPlugin_Initialize::$_29> >(void*)+306)
                                                                                                    runtime.cc:655]   native: #03 pc 000e6974  /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+100)
                                                                                                    runtime.cc:655]   native: #04 pc 00078567  /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+71)
                                                                                                    runtime.cc:655]   (no managed stack frames)
                                                                                                    runtime.cc:655] 
                                                                                                    runtime.cc:655] "ADB-JDWP Connection Control Thread" prio=10 tid=8 WaitingInMainDebuggerLoop
                                                                                                    runtime.cc:655]   | group="" sCount=1 dsCount=0 flags=1 obj=0x133402e0 self=0xe4a87e10
                                                                                                    runtime.cc:655]   | sysTid=12558 nice=-20 cgrp=top-app sched=0/0 handle=0xd9ad01e0
                                                                                                    runtime.cc:655]   | state=S schedstat=( 1594143 693720 6 ) utm=0 stm=0 core=3 HZ=100
                                                                                                    runtime.cc:655]   | stack=0xd99d5000-0xd99d7000 stackSize=1008KB
                                                                                                    runtime.cc:655]   | held mutexes=
                                                                                                    runtime.cc:655]   native: #00 pc 00000b99  [vdso] (__kernel_vsyscall+9)
                                                                                                    runtime.cc:655]   native: #01 pc 000cf496  /apex/com.android.runtime/lib/bionic/libc.so (__ppoll+38)
                                                                                                    runtime.cc:655]   native: #02 pc 00083979  /apex/com.android.runtime/lib/bionic/libc.so (poll+105)
                                                                                                    runtime.cc:655]   native: #03 pc 0000a493  /apex/com.android.art/lib/libadbconnection.so (adbconnection::AdbConnectionState::RunPollLoop(art::Thread*)+1171)
                                                                                                    runtime.cc:655]   native: #04 pc 000086d2  /apex/com.android.art/lib/libadbconnection.so (adbconnection::CallbackFunction(void*)+1666)
                                                                                                    runtime.cc:655]   native: #05 pc 000e6974  /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+100)
                                                                                                    runtime.cc:655]   native: #06 pc 00078567  /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+71)
                                                                                                    runtime.cc:655]   (no managed stack frames)
                                                                                                    runtime.cc:655] 
                                                                                                    runtime.cc:655] "Jit thread pool worker thread 0" prio=5 tid=9 Native
                                                                                                    runtime.cc:655]   | group="" sCount=1 dsCount=0 flags=1 obj=0x13340358 self=0xe4a8d210
                                                                                                    runtime.cc:655]   | sysTid=12559 nice=0 cgrp=top-app sched=0/0 handle=0xc4d74d60
                                                                                                    runtime.cc:655]   | state=S schedstat=( 933177212 340822158 1157 ) utm=32 stm=60 core=0 HZ=100
                                                                                                    runtime.cc:655]   | stack=0xc4c76000-0xc4c78000 stackSize=1023KB
                                                                                                    runtime.cc:655]   | held mutexes=
                                                                                                    runtime.cc:655]   native: #00 pc 00000b97  [vdso] (__kernel_vsyscall+7)
                                                                                                    runtime.cc:655]   native: #01 pc 0005ad68  /apex/com.android.runtime/lib/bionic/libc.so (syscall+40)
                                                                                                    runtime.cc:655]   native: #02 pc 001d82ec  /apex/com.android.art/lib/libart.so (art::ConditionVariable::WaitHoldingLocks(art::Thread*)+108)
                                                                                                    runtime.cc:655]   native: #03 pc 001d8273  /apex/com.android.art/lib/libart.so (art::ConditionVariable::Wait(art::Thread*)+35)
                                                                                                    runtime.cc:655]   native: #04 pc 006c838f  /apex/com.android.art/lib/libart.so (art::ThreadPool::GetTask(art::Thread*)+143)
                                                                                                    runtime.cc:655]   native: #05 pc 006c73e5  /apex/com.android.art/lib/libart.so (art::ThreadPoolWorker::Run()+133)
                                                                                                    runtime.cc:655]   native: #06 pc 006c6e9d  /apex/com.android.art/lib/libart.so (art::ThreadPoolWorker::Callback(void*)+269)
                                                                                                    runtime.cc:655]   native: #07 pc 000e6974  /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+100)
                                                                                                    runtime.cc:655]   native: #08 pc 00078567  /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+71)
                                                                                                    runtime.cc:655]   (no managed stack frames)
                                                                                                    runtime.cc:655] 

The Java code for the backend itself is correct as I don't get this error at all (tested it 1000 times) when using just an Android Studio internal vector asset in the custom made drawable for android:drawable="@drawable/vector_asset_from_android_studio"

Can someone explain why I get this error when using custom made drawables with custom made png files?

Reminder: Does anyone have an idea why this error occurs and what ot do to solve this issue? As I want to use my own custom made icons in my apps, I don't want to look for other icons in the internet.


Solution

  • Try to export your file as SVG file as follow:

    the import it into Android studio as follow: enter image description here

    Old answer:

    Try Bitmap for png files:

        <?xml version="1.0" encoding="utf-8"?>
        <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
            <item>
                <shape android:shape="rectangle">
                    <corners android:radius="5dp" />
                    <solid android:color="#c07313" />
                </shape>
            </item>
            <item
                android:width="29dp"
                android:height="29dp"
                android:right="1dp"
                android:left="1dp"
                android:bottom="1dp"
                android:top
                    ="1dp"
                android:gravity="left|center_vertical" >
                <bitmap android:src="@drawable/coal_icon"/> <!-- this -->
            </item>
        </layer-list>