【问题标题】:ic_launcher.png AAPT: error: file not found in Android Studio v4.1.1ic_launcher.png AAPT:错误:在 Android Studio v4.1.1 中找不到文件
【发布时间】:2021-01-05 07:50:28
【问题描述】:

我收到以下错误。

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

但 .png 文件存在于 mipmap-hdpi(mdpi)(xhdpi)(xxhdpi)(xxxhdpi)

构建中的完整错误如下\

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

我尝试了以下事情
-使缓存无效并重新启动 Android Studio
-卸载并重新安装 Android Studio
- 更新了 build.gradle 中的所有文件
-清理和重建项目
- 即使在 Manisfest 页面中更改了 android:icon 和 android:roundicon\

清单页面如下:

<?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>

我没有对 MainActivity 和 activity_main.xml 进行任何更改
我使用的类路径是classpath "com.android.tools.build:gradle:4.1.1"
build.gradle(Module)如下:

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'
}

【问题讨论】:

  • 检查res\mipmap-mdpi\ic_launcher.png上的文件ic_launcher.png还在吗?
  • 可能是你弄乱了应用的图标文件。尝试替换图标文件。
  • 我已经更新了显示特定文件夹中文件的问题,我可以在 Windows 中打开它们。
  • UsersOneDrive 文件夹可能受到保护,因此工具无权定位文件。尝试将项目从他们那里移出?
  • @AndrewT。在另一个驱动程序中创建新项目后。我面临这个错误。\Execution failed for task ':app:processDebugResources'. &gt; A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade &gt; AAPT2 aapt2-4.1.1-6503028-windows Daemon #0: Unexpected error during link, attempting to stop daemon. This should not happen under normal circumstances, please file an issue if it does.

标签: java android xml android-studio


【解决方案1】:

嗯,对我来说 降级类路径

来自"com.android.tools.build:gradle:4.1.1" "com.android.tools.build:gradle:4.0.2" 为我工作。

感谢所有帮助过我的人。

【讨论】:

    【解决方案2】:

    maven { url 'https://jitpack.io' } 添加到您的build.gradle 文件中。降级类路径会有所帮助,但这根本不是解决方案。

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

    【讨论】:

      猜你喜欢
      • 2013-09-26
      • 2016-03-17
      • 2022-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-21
      相关资源
      最近更新 更多