Toolbar: IllegalStateException - setting up your assembly for VectorDrawableCompat

I am using Android Studio 2.1.2. I started a new project with minSdkVersion as 19. My activity extends AppCompatActivity. A project begins with an empty action using a fragment.

When previewing content_main.xml with API 24, all is well. when previewing API 19, I get the following rendering problem:

The following classes could not be instantiated: - android.support.v7.widget.Toolbar java.lang.IllegalStateException: This app has been built with an incorrect configuration. Please configure your build for VectorDrawableCompat 

I added everything that I found relevant to gradle (2 files):

 classpath 'com.android.tools.build:gradle:2.1.2' **vectorDrawables.useSupportLibrary = true** buildToolsVersion "24.0.1" compile 'com.android.support:appcompat-v7:24.1.1' **compile "com.android.support:support-v4:24.1.1"** compile 'com.android.support:design:24.1.1 

But still an error appears. I have found many answers on the Internet. But no one helped. Is there a problem using the new toolbar with API 19?

+6
source share
4 answers

It worked well for me

 android { compileSdkVersion 23 buildToolsVersion "23.0.1" defaultConfig { applicationId "com.example.app" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" generatedDensities = [] } // This is handled for you by the 2.0+ Gradle Plugin aaptOptions { additionalParameters "--no-version-vectors" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } 

}

Pay attention to this in the above code:

 // This is handled for you by the 2.0+ Gradle Plugin aaptOptions { additionalParameters "--no-version-vectors" } 

and

 generatedDensities = [] 
+6
source

from this google problem

 buildscript { ... dependencies { classpath 'com.android.tools.build:gradle:2.1.0' } } 

check this issue for more help.

UPDATE

configured the build.gradle application build.gradle as follows

 android { defaultConfig { vectorDrawables.useSupportLibrary = true } } dependencies { compile 'com.android.support:appcompat-v7:23.3.0' } 

Source Age Vectors

0
source

Firstly, there are two types of gradle files.

  • build.gradle(Project: ProjectName)
  • build.gradle(Module: app)

For more information about these two files, follow this answer .

Getting to your question

I found many answers on the net, but no one helped. I use Android Studio 2.1.2, my activity extends AppCompatActivity and is added to gradle (2 files), which I found relevant: but still an error appears.

From everything you posted, it seems like you haven't added the right things to the right places.

Cannot place application dependencies in build.gradle(Project: ProjectName) - Android Studio says

//NOTE. Do not post application dependencies here; they belong

// in a separate module build.gradle files

Hence, replace your dependencies in build.gradle(Project: ProjectName) below

 dependencies { classpath 'com.android.tools.build:gradle:2.1.2' } 

Replace your dependencies in build.gradle(Module: app) below

 dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:24.1.1' compile 'com.android.support:design:24.1.1' } 

After execution, as indicated above, you will see the option "Sync now" in the upper right corner. Click on it. Android Studio will take care of other things.

Also this question is similar to yours. Go through it. This can help.

0
source

Add:

build.gradle

 defaultConfig { ... vectorDrawables.useSupportLibrary = true ... } 

And at the top of your Activity class:

 static { AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); } 

And the last thing that puts your vector drawables in any other drawings like selector , LayerList , etc. Something like below:

 <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/drawable_vector" /> </selector> 

And use it above for drawing everywhere, and not for installing vector drawings directly. This will be in other places when you want to use vector drawings on devices with a preliminary leoptype.

0
source

All Articles