CS Electrical And Electronics
@cselectricalandelectronics

How to fix this error app:srcCompat="@mipmap/ic_launcher_foreground" in android studio?

All QuestionsCategory: Mobile Apps, Android Studio, IOS, FlutterHow to fix this error app:srcCompat="@mipmap/ic_launcher_foreground" in android studio?
chetan shidling asked 4 years ago

To use VectorDrawableCompat, you need to make two modifications to your project. First, set android.defaultConfig.vectorDrawables.useSupportLibrary = true in your build.gradle file, and second, use app:srcCompat instead of android:src to refer to vector drawables.

My Code

2 Answers
chetan shidling answered 4 years ago

This is my code
 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".Slpash">

<ImageView
android:id="@+id/imageView"
android:layout_width="221dp"
android:layout_height="186dp"
app:srcCompat="@mipmap/ic_launcher_foreground"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
tools:layout_editor_absoluteX="95dp"
tools:layout_editor_absoluteY="231dp"
android:contentDescription="TODO" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CS Electrical And Electronics"
android:textSize="28sp"
android:textStyle="bold"
android:layout_below="@+id/imageView"
android:layout_centerHorizontal="true"
tools:layout_editor_absoluteX="25dp"
tools:layout_editor_absoluteY="447dp" />

</RelativeLayout>
Krishna answered 4 years ago

It’s so simple. 
 
Copy this – android.defaultConfig.vectorDrawables.useSupportLibrary = true and paste it in GradleScripts -> build.scripts(Module:app).
 

versionCode 1
versionName "1.0"
android.defaultConfig.vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Below versionName "1.0"

and syn.

Thank You