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>
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.
Related
I am trying to test a fragment, following these instructions: https://developer.android.com/training/basics/fragments/testing
However I am getting the following crash when calling launchFragmentInContainer from my test.
Stacktrace:
android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...
at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$createView(LayoutInflater.java:647)
...
at com.myapp.poll.PollHomeFragment.onCreateView(PollHomeFragment.kt:31)
...
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 13: TypedValue{t=0x2/d=0x7f0301b1 a=-1}
at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:946)
at android.content.res.TypedArray.getDrawable(TypedArray.java:930)
at android.view.View.__constructor__(View.java:5010)
at android.view.View.<init>(View.java)
at android.widget.TextView.<init>(TextView.java)
...
at com.myapp.poll.PollHomeFragment.onCreateView(PollHomeFragment.kt:31)
Here's the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".poll.PollActivity">
<TextView
android:id="#+id/tvEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="asdf#asdf.com" />
<TextView <!-- This is line 16 -->
android:id="#+id/tvViewPoll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:minHeight="48dp"
android:text="View Poll" />
<TextView
android:id="#+id/tvCreatePoll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:minHeight="48dp"
android:text="Create Poll" />
OK, from an educated guess based on the stacktrace, I tried removing android:background="?attr/selectableItemBackground" and this resolves the issue.
It appears that ?attr/selectableItemBackground is perhaps not compatible with FragmentScenario or this is a framework bug.
I submitted a bug on the issue tracker: https://issuetracker.google.com/issues/144629519
Update from Google:
Status: Won't Fix (Intended Behavior) The default theme does not have
an app defined attribute ?attr/selectableItemBackground (as Fragment
has no dependency on AppCompat, MDC, etc)
It sounds like you should be passing the correct theme to
FragmentScenario:
launchFragmentInContainer<PollHomeFragment>(themeResId = R.style.Theme_YourTheme)
In Java one also has to pass the theme to the FragmentScenario. Else the Fragment will not know about the current theme and will eventually complain that one should set an AppCompat theme ...
FragmentScenario<SomeFragment> scenario = FragmentScenario.launchInContainer(
SomeFragment.class,
Bundle.EMPTY,
R.style.Theme_Custom,
null
);
For me, using "android:?attr/selectableItemBackground" instead, solved the problem
I'm trying to shrink/obfuscate my release build with R8 (AS 3.3) but it's crashing trying to inflate an XML file, specifically on a TextView with a fontFamily. Removing the fontFamily attribute fixes the issue.
XML file:
<?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"
android:background="#drawable/blue_linear_gradient"
tools:context=".login.LoginFragment">
<ImageView
android:id="#+id/familyIcon"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginTop="32dp"
app:srcCompat="#drawable/auth_login_icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView <!-- This is line 20 -->
android:id="#+id/title"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:lineHeight="24dp"
android:maxWidth="168dp"
android:text="#string/login_title"
android:textAlignment="center"
android:fontFamily="#font/gotham_bold" <!-- Removing this line fixes it -->
android:textColor="#color/kineduWhite"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="#+id/authForm"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/familyIcon" />
<include
android:id="#+id/authForm"
layout="#layout/auth_form"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:maxWidth="324dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/familyIcon" />
<!-- More views... -->
</androidx.constraintlayout.widget.ConstraintLayout>
This is the stacktrace:
2019-01-17 17:37:26.496 24514-24514/? E/AndroidRuntime: FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class TextView
Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class TextView
Caused by: java.lang.NullPointerException: Attempt to read from field 'long android.content.res.XmlBlock$Parser.mParseState' on a null object reference
at android.content.res.XmlBlock$Parser.getAttributeListValue(XmlBlock.java:320)
at androidx.core.content.res.FontResourcesParserCompat.androidx.core.content.res.FontResourcesParserCompat$FamilyResourceEntry parse(org.xmlpull.v1.XmlPullParser,android.content.res.Resources)(SourceFile:1)
at androidx.core.content.res.ResourcesCompat.android.graphics.Typeface loadFont(android.content.Context,android.content.res.Resources,android.util.TypedValue,int,int,androidx.core.content.res.ResourcesCompat$FontCallback,android.os.Handler,boolean)(SourceFile:14)
at androidx.core.content.res.ResourcesCompat.android.graphics.Typeface loadFont(android.content.Context,int,android.util.TypedValue,int,androidx.core.content.res.ResourcesCompat$FontCallback,android.os.Handler,boolean)(SourceFile:3)
at androidx.core.content.res.ResourcesCompat.android.graphics.Typeface getFont(android.content.Context,int,android.util.TypedValue,int,androidx.core.content.res.ResourcesCompat$FontCallback)(SourceFile:8)
at androidx.appcompat.widget.TintTypedArray.android.graphics.Typeface getFont(int,int,androidx.core.content.res.ResourcesCompat$FontCallback)(SourceFile:8)
at androidx.appcompat.widget.AppCompatTextHelper.void updateTypefaceAndStyle(android.content.Context,androidx.appcompat.widget.TintTypedArray)(SourceFile:102)
at androidx.appcompat.widget.AppCompatTextHelper.void loadFromAttributes(android.util.AttributeSet,int)(SourceFile:59)
at androidx.appcompat.widget.AppCompatTextView.void <init>(android.content.Context,android.util.AttributeSet,int)(SourceFile:7)
at androidx.appcompat.widget.AppCompatTextView.void <init>(android.content.Context,android.util.AttributeSet)(SourceFile:2)
at androidx.appcompat.app.AppCompatViewInflater.androidx.appcompat.widget.AppCompatTextView createTextView(android.content.Context,android.util.AttributeSet)(SourceFile:1)
at androidx.appcompat.app.AppCompatViewInflater.android.view.View createView(android.view.View,java.lang.String,android.content.Context,android.util.AttributeSet,boolean,boolean,boolean,boolean)(SourceFile:30)
at androidx.appcompat.app.AppCompatDelegateImpl.void onSubDecorInstalled(android.view.ViewGroup)(SourceFile:89)
android.view.View createView(android.view.View,java.lang.String,android.content.Context,android.util.AttributeSet)
at androidx.appcompat.app.AppCompatDelegateImpl.android.view.View onCreateView(android.view.View,java.lang.String,android.content.Context,android.util.AttributeSet)(SourceFile:1)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:189)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:772)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.company.auth.login.LoginFragment.android.view.View onCreateView(android.view.LayoutInflater,android.view.ViewGroup,android.os.Bundle)(SourceFile:7)
My font lives in a separate library module.
Font family xml file "res/font/gotham-bold.xml" in :core
<font-family xmlns:app="http://schemas.android.com/apk/res-auto">
<font
app:fontStyle="normal"
app:fontWeight="400"
app:font="#font/gotham_rnd_bold"/>
<font
app:fontStyle="italic"
app:fontWeight="400"
app:font="#font/gotham_rnd_bold_italic"/>
</font-family>
And the actual font "gotham_rnd_bold.otf" is also in this :core module under "res/font/
I post here the reason why provided by R8 developers (from your issue) for better indexing and reference.
This happens because you are including program classes in your app
that is already in the Android framework. The Proguard configuration
rule -dontwarn org.xmlpull.v1.** explicitly disables these warnings
from the compiler.
Ideally, you should not include any classes in your app that is also
in the Android framework. You should be able to identify the
dependency that includes org.xmlpull.* and then exclude that module
from the dependency. It seems that others have successfully done this,
see for example https://stackoverflow.com/a/34486112. If you manage to
do this, then you shouldn't get any warnings even if you remove the
rule -dontwarn org.xmlpull.v1.**.
Alternatively, you can use the rule -keep class org.xmlpull.** { *;}.
This trick appears to be used by others
(https://github.com/search?q=org.xmlpull.v1+extension=pro&type=Code),
but it can be error-prone since your version of org.xmlpull.* may be
different from the one in the Android framework.
Note that we are working on changing the behavior of R8 such that it
deals with duplicate classes in a way such that Android framework
classes always take precedence of program classes (b/120884788). In
principle, none of the above changes should be needed with that fix.
You can set custom font programatically such as;
customText.typeface = ResourcesCompat.getFont(this,
R.font.your_font)
I see a lot of these errors described at StackOverflow but none of the solutions work for me. It seems this Exception is thrown at many possible mistakes and does not really tell you anything. Steps to reproduce
Create a MvvmCross application with Visual Studio 2017
Open the FirstView.axml
Add a DropDownListView from the toolbox into the Designer
Run the application on a Samsun Galaxy S6 (Android 6.0.1)
Here's the View that fails:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/toolbar_layout">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"
local:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/content_frame"
android:layout_below="#id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="40dp"
local:MvxBind="Text Hello" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="40dp"
local:MvxBind="Text Hello" />
<android.support.v7.widget.DropDownListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/dropDownListView1" />
</LinearLayout>
</FrameLayout>
</RelativeLayout>
I immediatly get the InflateException.
Here are a few snippets from the logcat which might give an indication:
03-16 14:50:35.621 20884 20884 I MonoDroid: UNHANDLED EXCEPTION:
03-16 14:50:35.641 20884 20884 I MonoDroid: Android.Views.InflateException: Binary XML file line #1: Error inflating class android.support.v7.widget.DropDownListView ---> Java.Lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
03-16 14:50:35.641 20884 20884 I MonoDroid: --- End of inner exception stack trace ---
And:
03-16 14:50:35.641 20884 20884 I MonoDroid: --- End of managed Android.Views.InflateException stack trace ---
03-16 14:50:35.641 20884 20884 I MonoDroid: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.v7.widget.DropDownListView
03-16 14:50:35.641 20884 20884 I MonoDroid: at android.view.LayoutInflater.createView(LayoutInflater.java:640)
03-16 14:50:35.641 20884 20884 I MonoDroid: at mvvmcross.binding.droid.views.MvxLayoutInflater_PrivateFactoryWrapper2.n_onCreateView(Native Method)
and:
03-16 14:50:35.651 20884 20884 I MonoDroid: UNHANDLED EXCEPTION:
03-16 14:50:35.651 20884 20884 I MonoDroid: Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class android.support.v7.widget.DropDownListView ---> Android.Views.InflateException: Binary XML file line #1: Error inflating class android.support.v7.widget.DropDownListView ---> Java.Lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
03-16 14:50:35.651 20884 20884 I MonoDroid: --- End of inner exception stack trace ---
03-16 14:50:35.651 20884 20884 I MonoDroid: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <8c304e4006094a46a7950338a3b3cb5d>:0
I also see these lines frequently:
03-16 14:50:35.601 20884 20884 I AppCompatViewInflater: app:theme is now deprecated. Please move to using android:theme instead.
03-16 14:50:35.611 20884 20884 W art : Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
I've searched the project for app:theme but none found.
As seen in the error stacktrace:
Java.Lang.NoSuchMethodException: [class android.content.Context, interface android.util.AttributeSet]
Which means, that after parsing your xml framework tries to create a java object for class android.support.v7.widget.DropDownListView with constructor that accepts Context and AttributeSet, which, apparently, doesn't exist.
As long as it has one constructor with signature public DropDownListView(Context context, boolean hijackFocus), I believe you have to create it through Java code in runtime.
I decided to switch from having library projects to having JARs in my libs directory. This worked fine for every library except the DragSortListView library i'm using. When i run my application i get an InflateException on the DragSortListView class that has to be inflated. I had to change the XML layout so i could use the attributes for the DragSortListView (the only change I made is to the xmlns:dslv line). It's also worth noting that i can use the DragSortListView class in java files
XML layout (library as project):
<com.mobeta.android.dslv.DragSortListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dslv="http://schemas.android.com/apk/res/com.package.myprojectpackage"
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"
dslv:collapsed_height="2dp"
dslv:drag_enabled="true"
dslv:drag_scroll_start="1"
dslv:float_alpha="1.0"
dslv:float_background_color="#color/Transparent"
dslv:max_drag_scroll_speed="0.5"
dslv:slide_shuffle_speed="0.3"
dslv:drag_handle_id="#+id/sabnzbd_queue_drag_handle"
dslv:track_drag_sort="false"
dslv:use_default_controller="true" />
XML layout (library as JAR):
<com.mobeta.android.dslv.DragSortListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dslv="http://schemas.android.com/apk/lib/com.mobeta.android.dslv"
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"
dslv:collapsed_height="2dp"
dslv:drag_enabled="true"
dslv:drag_scroll_start="1"
dslv:float_alpha="1.0"
dslv:float_background_color="#color/Transparent"
dslv:max_drag_scroll_speed="0.5"
dslv:slide_shuffle_speed="0.3"
dslv:drag_handle_id="#+id/sabnzbd_queue_drag_handle"
dslv:track_drag_sort="false"
dslv:use_default_controller="true" />
InflateException (Library as JAR):
07-06 15:25:33.376: E/AndroidRuntime(22907): FATAL EXCEPTION: main
07-06 15:25:33.376: E/AndroidRuntime(22907): android.view.InflateException: Binary XML file line #32: Error inflating class com.mobeta.android.dslv.DragSortListView
07-06 15:25:33.376: E/AndroidRuntime(22907): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
07-06 15:25:33.376: E/AndroidRuntime(22907): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
07-06 15:25:33.376: E/AndroidRuntime(22907): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
07-06 15:25:33.376: E/AndroidRuntime(22907): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
07-06 15:25:33.376: E/AndroidRuntime(22907): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-06 15:25:33.376: E/AndroidRuntime(22907): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
If anyone can explain why the class can't be found in XML files and possibly give a solution on how to fix that it would be greatly appreciated!
any Android project that has resources and uses the resource reference system cannot be packaged as a jar. It has to be an Android Library for the R.java file to be generated correctly and the resources to be resolved. i.e. #color/Transparent
Reference:
http://developer.android.com/tools/projects/index.html#considerations
Ok, that's weird.
I've received this error for one of my activities, the weird thing is that the bitmap is used in every Activity! I don't even know how to reproduce the exception, it's working fine for me (and others I think).
This is the whole stacktrace:
java.lang.RuntimeException: Unable to start activity ComponentInfo{it.enrichman.bolloauto/it.enrichman.bolloauto.activities.ArchivioActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class android.widget.ListView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1872)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4385)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class android.widget.ListView
at android.view.LayoutInflater.createView(LayoutInflater.java:518)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:250)
at android.app.Activity.setContentView(Activity.java:1742)
at it.enrichman.bolloauto.activities.ArchivioActivity.onCreate(ArchivioActivity.java:36)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
at android.view.LayoutInflater.createView(LayoutInflater.java:505)
... 22 more
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/backrepeat.xml from color state list resource ID #0x7f020075
at android.content.res.Resources.loadColorStateList(Resources.java:1855)
at android.content.res.TypedArray.getColor(TypedArray.java:319)
at android.widget.AbsListView.<init>(AbsListView.java:632)
at android.widget.ListView.<init>(ListView.java:164)
at android.widget.ListView.<init>(ListView.java:160)
... 25 more
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag bitmap
at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:146)
at android.content.res.ColorStateList.createFromXml(ColorStateList.java:129)
at android.content.res.Resources.loadColorStateList(Resources.java:1852)
... 29 more
The "missing" resource is this one (inside drawable folder):
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/bg"
android:tileMode="repeat" />
The "bg" drawable is inside drawable-hdpi (could be that a problem?), but as I said it's used in every activity as background!
The error is called during the setting of the layout:
setContentView(R.layout.archivio);
The xml layout is this one:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BLABLABLA"
android:id="#+id/archivioTextView" android:layout_gravity="center_horizontal"
android:gravity="center_horizontal" android:textIsSelectable="false" android:layout_marginTop="10dp"
android:layout_marginBottom="10dp" android:layout_marginRight="30dp" android:layout_marginLeft="30dp"/>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/listaVeicoli" android:layout_gravity="center" android:drawSelectorOnTop="false"/>
</LinearLayout>
(Some of the useless statements are put by the Designer of IntelliJ!)
I've looked for similar problems but I don't have "strange" id like #+id/list or other problems that other users encuntered..
Any help on this? What am I missing?
Thanks
In the end I've found FINALLY the solution.
I've tried with different emulator and I was having this crash only with API 10 (2.3.3) or less. Looking around the xmls and trying to do different stuff (also copying the bg drawable everywhere, or changing id to my list) I've found this weird stuff in my custom theme:
<item name="android:windowBackground">#drawable/backrepeat</item>
<item name="android:colorBackground">#drawable/backrepeat</item>
This seems to be not a problem for newer android version but for older one yes.
Just remove the colorBackground definition (that maybe should be only a color) and that's it!
I hope this will help someone else!
Create a drawable folder inside res folder.
Try keeping your bg inside "res/drawable/".
Hope this will help you.
Put your selector into the res/drawable folder and also give the Listview id as android:id="#+android:id/list".
I hope it will help you out.
Thanks.