Missing resources for Android CardView library - android

I'm using CardView in my project and I'm getting an error on older devices:
E android.view.InflateException: Binary XML file line #25: Error inflating class android.support.v7.widget.CardView
E at android.view.LayoutInflater.createView(LayoutInflater.java:518)
E at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
E at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
E at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
E at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
E at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
Seems similar to a few questions on SO such as this one
My problem is that the solution for that questions feels very hacky and that's understandable as the answer was given last year when Lollipop just entered the public preview. Have things changed since? How do I get the resources?
I've tried a few things such as importing .aar as a module but nothing seems to work. I've followed the official documentation on how to add support libraries (https://developer.android.com/tools/support-library/setup.html#libs-with-res) but that didn't work. Also according to that link - there doesn't seem to be any difference between adding libraries with and without resources for Android Studio?
My app build.gradle includes the following dependencies:
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'
CardView layout is used here
<android.support.v7.widget.CardView
xmlns:card="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground"
card:cardCornerRadius="6dp"
card:cardUseCompatPadding="true"
tools:ignore="NewApi">
EDIT: the problem noticed on Samsung S2 2.3 - API 19+ works fine

?android:attr/selectableItemBackground is platform related, use it without android: prefix to refer to AppCompat's attribute.

Related

After migrating to androidx: Didn't find class "androidx.constraintlayout.ConstraintLayout" on path: DexPathList

I've searched for an answer to my problem, as shown in the title of this question, and found Error inflating class androidx.constraintlayout.ConstraintLayout after migration to androidx, which aligns with the official migration instructions presented in Migrating to AndroidX. I took the information as requiring me to change android.support.constraint.ConstraintLayoutto androidx.constraintlayout.widget.ConstraintLayout, but this doesn't work for me.
I haven't found anything about what dependency to put in my gradle file, so I tried this (this is a shot in the dark):
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
which is accepted but when I tried:
implementation 'androidx.constraintlayout.widget:constraintlayout:1.1.3'
I get ERROR: Failed to resolve: androidx.constraintlayout.widget:constraintlayout:1.1.3, so I used the previous implementation directive.
Here is my 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"
tools:context="com.example.jbiss.petminder.activities.MainActivity">
<!--<android.support.v7.widget.Toolbar-->
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/colorPrimaryDark"
android:elevation="4dp"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="#style/AppTheme.PopupOverlay"/>
<TextView
android:id="#+id/tvMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:accessibilityLiveRegion="assertive"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar"
tools:text="error message goes here"/>
<TextView
android:id="#+id/tvEmVet"
android:layout_width="wrap_content"
android:layout_height="44dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="20dp"
android:layout_marginTop="8dp"
android:text="#string/emergency_vet"
android:textColor="#android:color/holo_red_dark"
android:textSize="24sp"
app:layout_constraintStart_toEndOf="#+id/phoneCallEmVet"
app:layout_constraintTop_toBottomOf="#+id/recyclerview1"
tools:textSize="24sp"/>
<ImageView
android:id="#+id/phoneCallEmVet"
android:layout_width="37dp"
android:layout_height="44dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="8dp"
android:onClick="callEmVet"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/recyclerview1"
app:srcCompat="#android:drawable/sym_action_call"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview1"
android:layout_width="368dp"
android:layout_height="365dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="#string/pet_name"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Running my app produces the following error:
2019-02-18 19:43:36.031 458-458/com.example.jbiss.petminder E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.jbiss.petminder, PID: 458
android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.example.jbiss.petminder-i-ubC_oLu_y7-aFpiqALqg==/base.apk", zip file "/data/app/com.example.jbiss
Following the information doesn't work, for some reason. The migration has been tough but I've cleaned up a lot of issues and am now unable to find a reason why this is happening when it appears that I have done what is intended.
I solved my problem. I found that Androidx migration is a bit more involved than I had at first thought. Knowing that I had updated the labels of the ConstraintLayout elements in the XML files used in the initial screen, I used Windows GREP to search for "android.support.constraint.ConstraintLayout" throughout my project. Lo and behold I found instances that I had missed and so I updated the XML file reference to "androidx.constraintlayout.widget.ConstraintLayout".
This allowed my project to be successfully built and launch on the emulator. However, after trying to access another screen I got the same error as shown in my initial post, but for the AppBarLayout. So, I must proceed for this one as I did for ConstraintLayout and then any others.
If you are migrating, be prepared for a little more work than you had anticipated!
I was facing the same problem after migrating to androidX. Tried above solution. But, it didn't work. I added mavenCentral() in project level app gradle.
repositories {
jcenter()
maven { url 'https://maven.google.com' }
mavenCentral()
}
with following changes
dependencies {
implementation 'com.google.android.material:material:1.0.0'
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
}
updated "android.support.constraint.ConstraintLayout" xml tag with "androidx.constraintlayout.widget.ConstraintLayout"
finally it worked.
If you experience this issue on Android Studio 3.6.3 after using the Migrate to Androidx tool like I did, Here is what worked for me:
I was using androidx.constraintlayout.ConstraintLayout in my layout XML file instead of androidx.constraintlayout.widget.ConstraintLayout
The difference is one has widget before ConstraintLayout. The dependency in my app-level build.gradle was:
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
The latest at that time.

invalid drawable tag animated-vector

I've looked all over stackoverflow and no question was able to solve my problem.
I'm trying to play an animated vector drawable on a device with API 15 but I keep getting the following runtime exception:
com.karim.test E/AvdcInflateDelegate: Exception while inflating <animated-vector>
android.content.res.Resources$NotFoundException: File res/drawable-ldpi-v4/feedback.png from xml type xml resource ID #0x7f020066
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2152)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2107)
at android.content.res.Resources.getXml(Resources.java:906)
at android.support.graphics.drawable.VectorDrawableCompat.create(VectorDrawableCompat.java:408)
at android.support.graphics.drawable.AnimatedVectorDrawableCompat.inflate(AnimatedVectorDrawableCompat.java:356)
at android.support.graphics.drawable.AnimatedVectorDrawableCompat.createFromXmlInner(AnimatedVectorDrawableCompat.java:162)
at android.support.v7.widget.AppCompatDrawableManager$AvdcInflateDelegate.createFromXmlInner(AppCompatDrawableManager.java:905)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:356)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:192)
at android.support.v7.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:66)
at android.support.v7.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:71)
at com.karim.test.MainActivity.initialize(MainActivity.java:428)
at com.karim.test.MainActivity.onCreate(MainActivity.java:210)
Caused by: java.io.FileNotFoundException: Corrupt XML binary file
at android.content.res.AssetManager.openXmlAssetNative(Native Method)
at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:487)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2134)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2107)
at android.content.res.Resources.getXml(Resources.java:906)
at android.support.graphics.drawable.VectorDrawableCompat.create(VectorDrawableCompat.java:408)
at android.support.graphics.drawable.AnimatedVectorDrawableCompat.inflate(AnimatedVectorDrawableCompat.java:356)
at android.support.graphics.drawable.AnimatedVectorDrawableCompat.createFromXmlInner(AnimatedVectorDrawableCompat.java:162)
at android.support.v7.widget.AppCompatDrawableManager$AvdcInflateDelegate.createFromXmlInner(AppCompatDrawableManager.java:905)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:356)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:192)
at android.support.v7.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:66)
at android.support.v7.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:71)
at com.karim.test.MainActivity.initialize(MainActivity.java:428)
at com.karim.test.MainActivity.onCreate(MainActivity.java:210)
android.content.res.Resources$NotFoundException: File res/drawable/animated_feedback_left.xml from drawable resource ID #0x7f020065
at android.content.res.Resources.loadDrawable(Resources.java:1923)
at android.content.res.Resources.getDrawable(Resources.java:664)
at android.support.v7.widget.ResourcesWrapper.getDrawable(ResourcesWrapper.java:128)
at android.support.v7.widget.TintResources.getDrawable(TintResources.java:45)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:201)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191)
at android.support.v7.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:66)
at android.support.v7.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:71)
at com.karim.test.MainActivity.initialize(MainActivity.java:422)
at com.karim.test.MainActivity.onCreate(MainActivity.java:204)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag animated-vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:863)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:804)
at android.content.res.Resources.loadDrawable(Resources.java:1920)
at android.content.res.Resources.getDrawable(Resources.java:664)
at android.support.v7.widget.ResourcesWrapper.getDrawable(ResourcesWrapper.java:128)
at android.support.v7.widget.TintResources.getDrawable(TintResources.java:45)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:201)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191)
at android.support.v7.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:66)
at android.support.v7.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:71)
at com.karim.test.MainActivity.initialize(MainActivity.java:422)
at com.karim.test.MainActivity.onCreate(MainActivity.java:204)
I'm using the same resources from my previous question that you can find over here Animated Vector Drawable not working with API 15
Also I've tested instead of using ImageView to use AppCompatImageView but still same error.
I've been debugging this error and it fails on the following statement:
final XmlPullParser parser = res.getXml(resId);
inside:
public static VectorDrawableCompat create(#NonNull Resources res, #DrawableRes int resId, #Nullable Theme theme)
method of VectorDrawableCompat verion 23.3.0.
It seems that I'm having an issue with compatibility. At some point Android decides to use the XML parsing of API 15 instead of using the compat version. Any ideas on how I can solve this annoying problem?
Update:
I followed Chris Banes blog and still no luck. Basically I've updated the compat libraries to 23.4.0 and I used the following in my activity:
static {
AppCompatDelegate.setCompatVectorFromSourcesEnabled(true);
}
Inflating Drawable's
`VectorDrawable` and `AnimatedVectorDrawable` in this support library can be inflated in this way:
Calling static getDrawable() methods:
//This will only inflate a drawable with <vector> as the root element
VectorDrawable.getDrawable(context, R.drawable.ic_arrow_vector);
//This will only inflate a drawable with <animated-vector> as the root element
AnimatedVectorDrawable.getDrawable(context, R.drawable.ic_arrow_to_menu_animated_vector);
// This will inflate any drawable and will auto-fallback to the lollipop implementation on api 21+ devices
ResourcesCompat.getDrawable(context, R.drawable.any_drawable);
If inflating the Drawable in java code, it is recommended to always use ResourcesCompat.getDrawable() as this handles Lollipop fallback when applicable. This allows the system to cache Drawable ConstantState and hence is more efficient.
The library has the following morph (bi-directional) animations :
Play-Pause morph animation
Play-Stop morph animation
Arrow-Hamburger menu morph animation
As you can see, I produced the above image on my API 16 phone:
import com.wnafee.vector.compat.AnimatedVectorDrawable;
mdrawable = (AnimatedVectorDrawable) AnimatedVectorDrawable.getDrawable(this.getApplicationContext(), R.drawable.consolidated_animated_vector);
Look at the github README for vector-compat here: https://github.com/wnafee/vector-compat
This will fix your problem (down to API 14) if you merge it with your app module's build.gradle dependencies (usually at the end of file):
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//Trying to FIX Binary XML file line #2: invalid drawable tag animated-vector
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'
//not needed
// compile 'com.android.support:support-vector-drawable:25.0.0'
compile 'com.wnafee:vector-compat:1.0.5'//*******holy grail *******https://github.com/wnafee/vector-compat
// Failed to resolve: com.android.support:support-animated-vector-drawable:25.0.0
//not needed
// compile 'com.android.support:support-animated-vector-drawable:25.0.0'
}
There is support library 25.4.0 and it's intended to solve all our problems. For example it finally supports path morphing!
To use it add:
allprojects {
repositories {
maven {
url "https://maven.google.com"
}
}
}
inside your project gradle file, and accordingly dependency itself:
compile 'com.android.support:support-v4:25.4.0'
After that you can use vector drawable animation with path morphing (which is often the culprit behind "invalid drawable tag animated-vector") in below manner (a little Kotlin code):
val drawable = AnimatedVectorDrawableCompat.create(this, R.drawable.vector_drawable)
imageView.setImageDrawable(drawable) // You may use usual ImageView class, no Compat necessary.
drawable.start()

View Background problems

This happened a couple of days ago. Still cannot find the way to fix it.
Here is a simple test project.
http://s000.tinyupload.com/index.php?file_id=03903482111052488979
Pretty simple layout:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
>
<EditText
android:id="#+id/editUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ems="10"
android:hint="#string/input_hint_email"
android:inputType="textEmailAddress"
/>
<EditText
android:id="#+id/editPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/edit_hint_password"
android:inputType="textPassword"
android:layout_gravity="center"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Enter"
/>
</LinearLayout>
Gradle important parts:
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.2.1'
}
Ple-lollipop devices (genymotion and real devices)
The background (pressed, sometimes normal) looks like something wrong with 9-patch file. Some of affected views - item in navigation view, menu item, edittext
edittext - https://gyazo.com/71f13003a46ff596514e475a72f924b7
pressed menu item - https://gyazo.com/7a5d9db29e17524e353f10a18562786e
Lollipop until 5.1
Crashes on startup (stop crashing on appcompat 23.1.1 and lower)
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ww.aeli.wtf.MainActivity}: android.view.InflateException:
Binary XML file line #11: Error inflating class EditText
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class EditText at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-v21/abc_edit_text_material.xml from drawable resource ID #0x7f020015 at android.content.res.Resources.loadDrawableForCookie(Resources.java:2428)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #24: <nine-patch> requires a valid 9-patch source image at android.graphics.drawable.NinePatchDrawable.updateStateFromTypedArray(NinePatchDrawable.java:445)
Lollipop 5.1 and marshmallow
Everything works fine
What have i tried
Problem also was reproduced on other developer machine.
Downgrading appcompat till the version 23.0.0. Lollipop do not crashes on 23.1.1 and lower, but background problem persists.
Disabling vector support (the main 23.2.0 feature, that theoretically could affect).
Similar recent problems - https://code.google.com/p/android/issues/detail?id=210467 (the discussion went on the strange way), https://github.com/afollestad/material-dialogs/issues/1081, https://code.google.com/p/android/issues/detail?id=210547
older one:
https://code.google.com/p/android/issues/detail?id=198457
Well, i find the way to "fix" all the issues as always just after posting a question.
Downgrading the gradle version from 2.2.0-alpha1 to 2.1.+ will solve all the problems.
And again note to myself - never use "+" in library versions.

File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020016 [duplicate]

This question already has answers here:
Update Android Support Library to 23.2.0 cause error: XmlPullParserException Binary XML file line #17<vector> tag requires viewportWidth > 0
(31 answers)
Closed 6 years ago.
Recently android support library was updated to 23.2.0. After downloading android sdk and updating android design support library into 23.2.0, this error happens repeatedly. My project can't even be compiled. The complete error log says:
03-02 12:00:04.945 9324-9324/com.creditease.zhiwang.debug E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.creditease.zhiwang.debug/com.creditease.zhiwang.activity.TabContainerActivity}: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020016
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2309)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$700(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1330)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5528)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020016
at android.content.res.Resources.loadDrawable(Resources.java:2974)
at android.content.res.Resources.getDrawable(Resources.java:1558)
at android.support.v7.widget.TintResources.superGetDrawable(TintResources.java:48)
at android.support.v7.widget.AppCompatDrawableManager.onDrawableLoadedFromResources(AppCompatDrawableManager.java:374)
at android.support.v7.widget.TintResources.getDrawable(TintResources.java:44)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:180)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
at android.support.v7.widget.ToolbarWidgetWrapper.<init>(ToolbarWidgetWrapper.java:184)
at android.support.v7.widget.ToolbarWidgetWrapper.<init>(ToolbarWidgetWrapper.java:91)
at android.support.v7.app.ToolbarActionBar.<init>(ToolbarActionBar.java:74)
at android.support.v7.app.AppCompatDelegateImplV7.setSupportActionBar(AppCompatDelegateImplV7.java:210)
at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:119)
at com.creditease.zhiwang.activity.BaseActivity.initToolBar(BaseActivity.java:300)
at com.creditease.zhiwang.activity.BaseActivity.initToolBar(BaseActivity.java:265)
at com.creditease.zhiwang.activity.TabContainerActivity.onCreate(TabContainerActivity.java:107)
at android.app.Activity.performCreate(Activity.java:5372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2271)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$700(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1330)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5528)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:873)
at android.content.res.Resources.loadDrawable(Resources.java:2970)
at android.content.res.Resources.getDrawable(Resources.java:1558)
at android.support.v7.widget.TintResources.superGetDrawable(TintResources.java:48)
at android.support.v7.widget.AppCompatDrawableManager.onDrawableLoadedFromResources(AppCompatDrawableManager.java:374)
at android.support.v7.widget.TintResources.getDrawable(TintResources.java:44)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:180)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
at android.support.v7.widget.ToolbarWidgetWrapper.<init>(ToolbarWidgetWrapper.java:184)
at android.support.v7.widget.ToolbarWidgetWrapper.<init>(ToolbarWidgetWrapper.java:91)
at android.support.v7.app.ToolbarActionBar.<init>(ToolbarActionBar.java:74)
at android.support.v7.app.AppCompatDelegateImplV7.setSupportActionBar(AppCompatDelegateImplV7.java:210)
at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:119)
at com.creditease.zhiwang.activity.BaseActivity.initToolBar(BaseActivity.java:300)
at com.creditease.zhiwang.activity.BaseActivity.initToolBar(BaseActivity.java:265)
at com.creditease.zhiwang.activity.TabContainerActivity.onCreate(TabContainerActivity.java:107)
at android.app.Activity.performCreate(Activity.java:5372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2271)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$700(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1330)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5528)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
at dalvik.system.NativeStart.main(Native Method)
This error was thrown by setSupportActionBar(toolbar); whereas it didn't happen at 23.0.1 of android design library 23.2.0. Meanwhile according this log, I guessed this drawable was removed since android design library 23.2.0.
So, could someone told me why is this happening?
I think you need to make changes in your gradle.
// Gradle Plugin 2.0+
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
You’ll note this new attribute only exists in the version 2.0 of the Gradle Plugin. If you are using Gradle 1.5 you’ll instead use
// Gradle Plugin 1.5
android {
defaultConfig {
// Stops the Gradle plugin's automatic rasterization of vectors
generatedDensities = []
}
// Flag to tell aapt to keep the attribute ids around
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
I found similar question here.
See Support Vector Drawables and Animated Vector Drawables in Android Support Library update.
I hope its help you.
As per as the documentation of Google's support library for 24.0.0, they have changed the vector drawable library to what it was before:
Added AppCompatDelegate.setCompatVectorFromResourcesEnabled() method to re-enable usage of vector drawables in DrawableContainer objects on devices running Android 4.4 (API level 19) and lower. See AppCompat v23.2 — Age of the vectors! for more information.
I faced the same issue and my SVG statelist drawables used in my project were working just fine till Marshmallow devices.
Later when I got the crash for the same in Android N, I realized that the svgs were a bit corrupted and contained characters like: � and this caused the crash.
But these were not reflected in Android Marshmallow and prior devices.
Make sure your vector drawable doesn't contain any of those characters as the way of parsing has been changed from the library 24.0.0. So vector drawables working fine till Marshmallow might not work in Nougat devices.
Hope this helps :)
I solve this problem by updating my support library from
'com.android.support:appcompat-v7:23.2.0'
'com.android.support:design:23.2.0'
to the same dependencies of 23.2.1.
When I met the problem, I had not made any changes in my module built by Android Studio.
So I was so confused then I tried to update android support library.
After updating, please remember to sync your build.gradle
I solved the issue as follows:
Try with changing styles.xml to
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
This is because if style requires ActionBar there are chances of not finding abc_back button but with no action bar problem is solved
This worked for me: Replace the com.android.support:design version in build.gradle with one that works. Find which version works by creating a new project from scratch in Android Studio and using the version from that.
I had this problem when I added a Navigation Drawer Activity from the File->New->Activity menu to an older project with Android Studio.
Android Studio added a dependency like so:
compile 'com.android.support:design:24.0.0-alpha1'
(I'm not sure of the exact version but it had '24' and 'alpha').
I then created a new dummy project, specifying a Navigation Drawer Activity in the new project wizard. I noticed that the new project had a different dependency: compile 'com.android.support:design:23.2.1'
So I took this dependency and put it in the first project, and the problem was solved.
Source - http://android-developers.blogspot.in/2016/02/android-support-library-232.html
when using AppCompat with ImageView (or subclasses such as ImageButton
and FloatingActionButton), you’ll be able to use the new app:srcCompat
attribute to reference vector drawables (as well as any other drawable
available to android:src):
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_add" />
where you can define your app in your root element as
xmlns:app="http://schemas.android.com/apk/res-auto"
I've had this issue because my Manifest file had style that was defined only in v21 style. Not sure why it was pointing at this type of error but someone may find this helpful.

Way to avoid layout file naming conflict among multiple Android projects

Currently, I have an Android project, consists of 1 main project, and multiple library projects.
Just that recently, I realize that if there is same layout filename among main project and library project, bad thing can happen.
third-party-library-project
- res
- layout
- actionbar_custom_view_done_discard.xml
main-project
- res
- layout
- actionbar_custom_view_done_discard.xml
So, if in third-party-library-project, if you are having line of code in its activity,
final View customActionBarView = inflater.inflate(
R.layout.actionbar_custom_view_done_discard, null);
Error stack trace caused by layout file naming conflict
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.yccheok.jstock.gui/group.pals.android.lib.ui.lockpattern.LockPatternActivity}: android.view.InflateException: Binary XML file line #24: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at group.pals.android.lib.ui.lockpattern.LockPatternActivity.initActionBar(LockPatternActivity.java:356)
at group.pals.android.lib.ui.lockpattern.LockPatternActivity.onCreate(LockPatternActivity.java:347)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
... 25 more
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f010137 a=-1}
at android.content.res.Resources.loadDrawable(Resources.java:1892)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.widget.TextView.<init>(TextView.java:614)
at android.widget.TextView.<init>(TextView.java:442)
... 28 more
If I change the layout XML file in third-party-library-project to actionbar_custom_view_done_discard1.xml, the runtime error will gone.
This is not an issues, if the number of library projects is small. Conflict can be solved easily with simple renaming. However, when comes across huge number of library projects, what is a robust way, or strategy to overcome this problem?
Library projects need to ensure that their resource names will be distinctive and not collide with other library projects, such as by applying a prefix to those resource names.
Note that apparently the new Gradle-based build system supports resource subdirectories. I have not yet experimented with this, but if the subdirectory names form part of the resource ID, then putting your resources in a distinctive subdirectory would help to keep the resource IDs distinct (at least for non-values resources).
First I would suggest renaming your project resource file and not the 3rd party file in your first example since you may want to pull changes from the 3rd party library project again. Secondly I would suggest not using too many 3rd party library projects to begin with. From my experience the Android build system still has lots of hiccups with library projects. Things like BuildConfig.DEBUG do not work and I've had issues with library projects that contain jar file dependencies breaking the ability to run unit tests through Android instrumentation. There are tons of other bugs as well, most of them probably fairly obscure but enough of an issue that I don't suggest using library projects any more than absolutely necessary.

Categories

Resources