Im trying to use vector drawables on pre lollipop devices. I did all as instructed here but i still get this crash.
build.gradle:
That's all I fond over the internet, and it's work for me. Check which one you miss.
1) Inside build.gradle
android {
...
defaultConfig {
...
vectorDrawables.useSupportLibrary = true
}
}
2) Must use buildToolsVersion '27.0.3' and compile 'com.android.support:appcompat-v7:27.0.3' similar version code.
3) Use upper then 3 gradle version
classpath 'com.android.tools.build:gradle:3.0.1'
4) For ImageView use app:srcCompat
xmlns:app="http://schemas.android.com/apk/res-auto"
app:srcCompat="@drawable/ic_logo"
5) But if you need android:drawableLeftor android:drawableRigth etc then:
ic_logo.xml (Vector xml)
ic_logo_select.xml (Vector selector)
Now you can use android:drawableLeft or android:drawableRight
6) And at the end, setCompatVectorFromResourcesEnabled = true inside static which loads before the main method.
public class MainActivity extends AppCompatActivity {
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
....
}
}