Search code examples
androidvectorandroid-4.4-kitkat

update for using vectorDrawables with androidx


The solution given in this documentation page doesn't seem to be valid for androidx users(I think this because there is mention of android.support.v7.appcompat which isn't used by androidx users, right?). I might have gotten something wrong, but adding the: vectorDrawables.useSupportLibrary = true also the

static{
            AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
        }  

with the xml's app:srcCopmat:

<ImageButton
                android:id="@+id/imageButton4"
                android:layout_width="26dp"
                android:layout_height="0dp"
                android:layout_marginEnd="8dp"
                app:layout_constraintBottom_toBottomOf="@+id/imageButton5"
                app:layout_constraintEnd_toStartOf="@+id/imageButton5"
                app:layout_constraintTop_toTopOf="@+id/imageButton5"
                app:srcCompat="@drawable/sync" />

doesn't help. It simply crashes the app. The logcat reads:

file: /sys/class/power_supply/battery/hw_switch_point open error
E/dalvikvm(11099): Could not find class 'com.crashlytics.android.ndk.CrashlyticsNdk', referenced from method com.crashlytics.android.CrashlyticsInitProvider.ˊ
E/dalvikvm(11099): Could not find class 'dalvik.system.InMemoryDexClassLoader', referenced from method com.facebook.ads.internal.dynamicloading.DynamicLoaderFactory.createInMemoryClassLoader
E/dalvikvm(11099): Could not find class 'com.facebook.ads.internal.dynamicloading.DynamicLoaderImpl', referenced from method com.facebook.ads.internal.dynamicloading.DynamicLoaderFactory.doMakeLoader
E/dalvikvm(11099): Could not find class 'androidx.work.impl.background.systemjob.SystemJobService', referenced from method androidx.appcompat.view.ʖ.createBestAvailableBackgroundScheduler
E/dalvikvm(11099): Could not find class 'androidx.appcompat.view.ΐ$ˊ', referenced from method androidx.appcompat.view.ΐ.<init>
E/dalvikvm(11099): Could not find class 'android.graphics.BlendModeColorFilter', referenced from method androidx.appcompat.view.y40$if.ˊ
E/dalvikvm(11099): Could not find class 'android.graphics.BlendModeColorFilter', referenced from method androidx.appcompat.view.y40$if.ˋ
E/dalvikvm(11099): Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method androidx.appcompat.view.t40.ˊ
E/dalvikvm(11099): Could not find class 'dalvik.system.DelegateLastClassLoader', referenced from method x.a
E/dalvikvm(11099): Could not find class 'dalvik.system.DelegateLastClassLoader', referenced from method nj.a
E/dalvikvm(11099): Could not find class 'com.evozi.network.service.QSTileService', referenced from method androidx.appcompat.view.ᚁ.ˋ
E/dalvikvm(11099): Could not find class 'com.evozi.network.service.QSTileService', referenced from method androidx.appcompat.view.ᚁ.ˋ
E/dalvikvm(11099): Could not find class 'com.evozi.network.service.QSTileService', referenced from method androidx.appcompat.view.ᚁ.ᐝ
E/dalvikvm(11099): Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method com.facebook.ads.redexgen.X.OY.A09
E/dalvikvm(11099): Could not find class 'android.app.ActivityManager$AppTask', referenced from method com.facebook.ads.redexgen.X.NN.A02
E/FBAudienceNetwork(11099): You are using custom Application class and don't call AudienceNetworkAds.isInAdsProcess(). Multi-process support will be disabled. Please call AudienceNetworkAds.isInAdsProcess() if you want to support multi-process mode.
E/memtrack(11189): Couldn't load memtrack module (No such file or directory)
E/android.os.Debug(11189): failed to load memtrack module: -2
E/PackageManager(  617): parse pkg : /data/app/vmdl-410864310.tmp
E/PackageManager(  617): dexopt start
E/Finsky  (10651): [1] aabj.b(2): Package name null is not an installed package
E/PackageManager(  617): dexopt end
E/SamsungIME(  907): mOCRHelper is null
E/SamsungIME(  907): mOCRHelper is null
E/memtrack(11247): Couldn't load memtrack module (No such file or directory)
E/android.os.Debug(11247): failed to load memtrack module: -2
E/jdwp    (11287): Failed sending reply to debugger: Broken pipe
E/dalvikvm(11287): Could not find class 'androidx.core.view.ViewCompat$2', referenced from method androidx.core.view.ViewCompat.addOnUnhandledKeyEventListener
E/dalvikvm(11287): Could not find class 'android.view.WindowInsets', referenced from method androidx.core.view.ViewCompat.dispatchApplyWindowInsets
E/dalvikvm(11287): Could not find class 'android.view.WindowInsets', referenced from method androidx.core.view.ViewCompat.onApplyWindowInsets
E/dalvikvm(11287): Could not find class 'android.view.View$OnUnhandledKeyEventListener', referenced from method androidx.core.view.ViewCompat.removeOnUnhandledKeyEventListener
E/dalvikvm(11287): Could not find class 'androidx.core.view.ViewCompat$1', referenced from method androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener
E/AndroidRuntime(11287): FATAL EXCEPTION: main
E/AndroidRuntime(11287): Process: com.makeit.www, PID: 11287
E/AndroidRuntime(11287): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.makeit.www/com.makeit.www.StartupSetup.LogoAnimation}: android.view.InflateException: Binary XML file line #13: Error inflating class ImageView
E/AndroidRuntime(11287):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
E/AndroidRuntime(11287):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2378)
E/AndroidRuntime(11287):        at android.app.ActivityThread.access$800(ActivityThread.java:155)
E/AndroidRuntime(11287):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
E/AndroidRuntime(11287):        at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(11287):        at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime(11287):        at android.app.ActivityThread.main(ActivityThread.java:5433)
E/AndroidRuntime(11287):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(11287):        at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(11287):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
E/AndroidRuntime(11287):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
E/AndroidRuntime(11287):        at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(11287): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class ImageView
E/AndroidRuntime(11287):        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:720)
E/AndroidRuntime(11287):        at android.view.LayoutInflater.rInflate(LayoutInflater.java:762)
E/AndroidRuntime(11287):        at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
E/AndroidRuntime(11287):        at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
E/AndroidRuntime(11287):        at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
E/AndroidRuntime(11287):        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
E/AndroidRuntime(11287):        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
E/AndroidRuntime(11287):        at com.makeit.www.StartupSetup.LogoAnimation.onCreate(LogoAnimation.java:22)
E/AndroidRuntime(11287):        at android.app.Activity.performCreate(Activity.java:5301)
E/AndroidRuntime(11287):        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
E/AndroidRuntime(11287):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2291)
E/AndroidRuntime(11287):        ... 11 more
E/AndroidRuntime(11287): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_launcher_background.xml from drawable resource ID #0x7f060064
E/AndroidRuntime(11287):        at android.content.res.Resources.loadDrawable(Resources.java:3451)
E/AndroidRuntime(11287):        at android.content.res.TypedArray.getDrawable(TypedArray.java:614)
E/AndroidRuntime(11287):        at android.widget.ImageView.<init>(ImageView.java:134)
E/AndroidRuntime(11287):        at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:72)
E/AndroidRuntime(11287):        at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
E/AndroidRuntime(11287):        at androidx.appcompat.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:187)
E/AndroidRuntime(11287):        at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:107)
E/AndroidRuntime(11287):        at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1407)
E/AndroidRuntime(11287):        at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1457)
E/AndroidRuntime(11287):        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
E/AndroidRuntime(11287):        ... 21 more
E/AndroidRuntime(11287): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag vector
E/AndroidRuntime(11287):        at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:969)
E/AndroidRuntime(11287):        at android.graphics.drawable.Drawable.createFromXml(Drawable.java:913)
E/AndroidRuntime(11287):        at android.content.res.Resources.loadDrawable(Resources.java:3447)
E/AndroidRuntime(11287):        ... 30 more
E/android.os.Debug(  617): !@Dumpstate > sdumpstate -k -t -z -d -m 11287 -o /data/log/dumpstate_app_error
E/dalvikvm(11371): Could not find class 'android.app.job.JobScheduler', referenced from method com.sec.android.app.samsungapps.SamsungApps.b
E/dalvikvm(11371): Could not find class 'android.app.NotificationChannel', referenced from method com.sec.android.app.samsungapps.vlibrary.concreteloader.Common.getGeneralNotificationChannel
E/dalvikvm(11371): Could not find class 'android.app.NotificationChannel', referenced from method com.sec.android.app.samsungapps.vlibrary.concreteloader.Common.getPromotionNotificationChannel
E/dalvikvm(11371): Could not find class 'android.app.NotificationChannel', referenced from method com.sec.android.app.samsungapps.vlibrary.concreteloader.Common.getRewardsNotificationChannel
E/dalvikvm(11371): Could not find class 'android.app.NotificationChannel', referenced from method com.sec.android.app.samsungapps.vlibrary.concreteloader.Common.getUpdateNotificationChannel
E/Watchdog(  617): !@Sync 380
E/ActivityThread(11371): Failed to find provider info for null
E/ActivityThread(11371): Failed to find provider info for com.sec.android.app.clockpackage.celebvoice
E/[SAUI]  (11371): Firebase initialize is success
E/SPPClientService(11407): ShipBuild Binary : True
E/SPPClientService(11407): [PackageInfoChangeReceiver] android.intent.action.PACKAGE_REMOVED
E/SPPClientService(11407): [PackageInfoChangeReceiver] [handlePkgRemovedEvent] PackageName : com.makeit.www, true, false
E/SPPClientService(11407): [PackageInfoChangeReceiver] [handlePkgRemovedEvent] Ignore Replacing case

So a little run down on how to use the vectorDrawables(or simply vector images) for androidx users for versions under Lollipop would be a huge help.

EDIT: XML layout file is:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Main.MainScreenActivity">

    <LinearLayout
        android:id="@+id/Toolbar_holder"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        >


        <androidx.appcompat.widget.Toolbar
            android:id="@+id/app_toolbar"
            android:layout_width="match_parent"
            android:layout_height="@dimen/actionBarSize"
            android:textSize="@dimen/actionBarTextSize"
            android:background="@color/colorPrimary">
        </androidx.appcompat.widget.Toolbar>

        <View
            android:layout_width="match_parent"
            android:layout_height="8dp"
            android:background="@drawable/shadow_top_to_down" />


    </LinearLayout>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/C_makeControlMain"
        android:layout_width="0dp"
        android:layout_height="227dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/C_makeControlHeader"
            android:layout_width="0dp"
            android:layout_height="46dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <TextView
                android:id="@+id/fileTitle"
                android:layout_width="170dp"
                android:layout_height="21dp"
                android:layout_marginStart="8dp"
                android:layout_marginEnd="8dp"
                android:gravity="center"
                android:text="@string/fileTitle"
                app:layout_constraintEnd_toStartOf="@+id/imageButton3"
                app:layout_constraintStart_toEndOf="@+id/imageButton2"
                app:layout_constraintTop_toTopOf="parent" />

            <ImageButton
                android:id="@+id/imageButton"
                android:layout_width="34dp"
                android:layout_height="29dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/add_new_information" />

            <ImageButton
                android:id="@+id/imageButton2"
                android:layout_width="35dp"
                android:layout_height="0dp"
                android:layout_marginStart="8dp"
                app:layout_constraintBottom_toBottomOf="@+id/imageButton"
                app:layout_constraintStart_toEndOf="@+id/imageButton"
                app:layout_constraintTop_toTopOf="@+id/imageButton"
                app:srcCompat="@drawable/save_information" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                android:gravity="center"
                android:text="@string/artist_name"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="@+id/fileTitle"
                app:layout_constraintHorizontal_bias="0.513"
                app:layout_constraintStart_toStartOf="@+id/fileTitle"
                app:layout_constraintTop_toBottomOf="@+id/fileTitle" />

            <ImageButton
                android:id="@+id/imageButton3"
                android:layout_width="28dp"
                android:layout_height="0dp"
                android:layout_marginEnd="8dp"
                app:layout_constraintBottom_toBottomOf="@+id/imageButton4"
                app:layout_constraintEnd_toStartOf="@+id/imageButton4"
                app:layout_constraintTop_toTopOf="@+id/imageButton4"
                app:srcCompat="@drawable/add_normal_browser" />

            <ImageButton
                android:id="@+id/imageButton4"
                android:layout_width="26dp"
                android:layout_height="0dp"
                android:layout_marginEnd="8dp"
                app:layout_constraintBottom_toBottomOf="@+id/imageButton5"
                app:layout_constraintEnd_toStartOf="@+id/imageButton5"
                app:layout_constraintTop_toTopOf="@+id/imageButton5"
                app:srcCompat="@drawable/sync_browsers" />

            <ImageButton
                android:id="@+id/imageButton5"
                android:layout_width="29dp"
                android:layout_height="0dp"
                android:layout_marginEnd="8dp"
                app:layout_constraintBottom_toBottomOf="@+id/imageButton2"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="@+id/imageButton2"
                app:srcCompat="@drawable/add_singalong_browser" />
        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

Solution

  • The error is actually quite logical, and one who is much familiar with reading the logcat would've found it in 5 minute.

    After you enable using the vector using the vectorDrawables.useSupportLibrary = true you have to henceforth reference all the vector images using app:srcCompat= @drawable/xyz, if any of your xml files use instead android:src="@drawable/vector then the app would crash as shown above.

    Side note: The solution was as mentioned in the doc also for androidx users, just to be clear.