N SARATH CHAND
N SARATH CHAND

Reputation: 169

ic_launcher.png AAPT: error: file not found in Android Studio v4.1.1

I'm getting the following error.

Android resource compilation failed
C:\Users\sarat\OneDrive\Desktop\xd\app\src\main\res\mipmap-mdpi\ic_launcher.png: AAPT: error: file not found.

But .png files are present in mipmap-hdpi(mdpi)(xhdpi)(xxhdpi)(xxxhdpi) enter image description here

The complete errors in build is as follows\

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Multiple task action failures occurred:
   > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
      > Android resource compilation failed
        C:\Users\sarat\OneDrive\Desktop\xd\app\src\main\res\mipmap-mdpi\ic_launcher.png: AAPT: error: file not found.
            
   > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
      > AAPT2 aapt2-4.1.1-6503028-windows Daemon #3: Unexpected error during compile 'C:\Users\sarat\OneDrive\Desktop\xd\app\src\main\res\mipmap-mdpi\ic_launcher_round.png', attempting to stop daemon.
        This should not happen under normal circumstances, please file an issue if it does.
   > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
      > Android resource compilation failed
        C:\Users\sarat\OneDrive\Desktop\xd\app\src\main\res\mipmap-hdpi\ic_launcher.png: AAPT: error: file not found.
            
   > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
      > AAPT2 aapt2-4.1.1-6503028-windows Daemon #2: Unexpected error during compile 'C:\Users\sarat\OneDrive\Desktop\xd\app\src\main\res\mipmap-xhdpi\ic_launcher.png', attempting to stop daemon.
        This should not happen under normal circumstances, please file an issue if it does.
   > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
      > AAPT2 aapt2-4.1.1-6503028-windows Daemon #4: Daemon startup failed
        Please check if you installed the Windows Universal C Runtime.
        This should not happen under normal circumstances, please file an issue if it does.
   > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
      > Android resource compilation failed
        C:\Users\sarat\OneDrive\Desktop\xd\app\src\main\res\mipmap-xhdpi\ic_launcher_round.png: AAPT: error: file not found.
            
   > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
      > AAPT2 aapt2-4.1.1-6503028-windows Daemon #5: Daemon startup failed
        Please check if you installed the Windows Universal C Runtime.
        This should not happen under normal circumstances, please file an issue if it does.
   > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
      > Android resource compilation failed
        C:\Users\sarat\OneDrive\Desktop\xd\app\src\main\res\mipmap-xxxhdpi\ic_launcher.png: AAPT: error: file not found.
            

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 6s
20 actionable tasks: 1 executed, 19 up-to-date

I tried following things
-invalidate cache and restart Android studio
-Uninstalling and Reinstalling Android studio
-updated all files in build.gradle
-cleaned and rebuiled project
-even after changing android:icon and android:roundicon in Manisfest page\

The manifest page is as follows:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.xd">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Xd">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

I haven't made any changes in MainActivity and activity_main.xml
The classpath i'm using is classpath "com.android.tools.build:gradle:4.1.1"
The build.gradle(Module) is as follows:

plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.xd"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        vectorDrawables.useSupportLibrary = true

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.13.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

Upvotes: 7

Views: 8234

Answers (3)

Sriganesh
Sriganesh

Reputation: 31

This is probably caused due to the ic_launcher.png file being corrupted while it is copied to the project's directory by Flutter.

For me, manually replacing the ic_launcher.png file in the project's directory with the png file from the following location in the Flutter SDK directory worked. \packages\flutter_tools\templates\module\android\host_app_common\app.tmpl\src\main\res\mipmap-hdpi

To find the flutter SDK directory type the following command into the command prompt where flutter. Copy the path till before the bin folder and copy the remaining part from this answer.

Upvotes: 0

Krishna Sony
Krishna Sony

Reputation: 1369

Add maven { url 'https://jitpack.io' } to your build.gradle file. Downgrading the classpath will help but that's not the solution at all.

allprojects {
    repositories {
        google()
        jcenter()
       // add maven
        maven { url 'https://jitpack.io' }
    }
}

Upvotes: -1

N SARATH CHAND
N SARATH CHAND

Reputation: 169

Well, for me Downgrading the classpath

from "com.android.tools.build:gradle:4.1.1" to "com.android.tools.build:gradle:4.0.2" worked for me.

Thanks to everyone who helped me.

Upvotes: 2

Related Questions