如何修复错误:“找不到资源 mipmap/ic_launcher(又名 com.example.MyAppName:mipmap/ic_launcher)。” 在 vs 代码上

Mat*_*ail 2 android visual-studio-code flutter

我需要一些帮助来解决我在聊天应用程序中遇到的问题。一切都工作得很好,但我把这个项目搁置了几个月。当我再次开始工作时,我必须升级所有的软件包和 flutter 本身,以便希望它能工作。但我不知道为什么会发生这个错误,这里是完整的错误:

任务 ':app:processDebugResources' 执行失败。> 执行 com.android.build.gradle.internal.tasks.Workers$ActionFacade Android 资源链接失败 D:\MyAppName 2.0\myappname\build\app\intermediates\ 时发生故障packaged_manifests\debug\AndroidManifest.xml:19: AAPT: 错误:找不到资源 mipmap/ic_launcher (又名 com.example.MyAppName:mipmap/ic_launcher)。

我没有尝试更改图标的任何名称或其他任何内容,因此如果有人可以帮助我,那就太好了。这是我的 pubspec.yaml 文件和 AndroidManifest.xml :

   name: MyAppName
    description: A new Flutter project.

    environment:
      sdk: ">=2.12.0 <3.0.0"

    dependencies:
      flutter:
       sdk: flutter
  
    cupertino_icons: ^1.0.4
    flutter_svg: ^1.0.3
    emoji_picker: ^0.1.0
    shared_preferences: ^0.5.4+1
    camera: ^0.9.4+10
    path_provider: ^2.0.2
    path: 
    video_player: ^2.1.6
    socket_io_client: ^1.0.1


    dev_dependencies:
      flutter_test:
        sdk: flutter



    uses-material-design: true

  
    fonts:
     - family: OpenSans
      fonts:
        - asset: fonts/OpenSans-Bold.ttf
        - asset: fonts/OpenSans-Regular.ttf
        - asset: fonts/OpenSans-Italic.ttf
          style: italic
Run Code Online (Sandbox Code Playgroud)

和 AndroidManifest.xml :

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

    <uses-sdk
        android:minSdkVersion="21"
        android:targetSdkVersion="31" />
    <!--
         Flutter needs it to communicate with the running application
         to allow setting breakpoints, to provide hot reload, etc.
    -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:appComponentFactory="androidx.core.app.CoreComponentFactory"
        android:debuggable="true"
        android:icon="@mipmap/ic_launcher"
        android:label="MyAppName"
        android:usesCleartextTraffic="true" >
        <activity
            android:name="com.example.MyAppName.MainActivity"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:windowSoftInputMode="adjustResize" >

            <!--
                 Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI.
            -->
            <meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme" />
            <!--
                 Displays an Android View that continues showing the launch screen
                 Drawable until Flutter paints its first frame, then this splash
                 screen fades out. A splash screen is useful to avoid any visual
                 gap between the end of Android's launch screen and the painting of
                 Flutter's first frame.
            -->
            <meta-data
                android:name="io.flutter.embedding.android.SplashScreenDrawable"
                android:resource="@drawable/launch_background" />

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <!--
             Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java
        -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />

        <uses-library
            android:name="androidx.window.extensions"
            android:required="false" />
        <uses-library
            android:name="androidx.window.sidecar"
            android:required="false" />
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

如果您需要查看其他文件,绝对没有问题!谢谢

小智 7

我遇到了同样的问题,我使用以下方式导入图标:
Android Studio -> new -> ImageAsset -> choose the image

但在保存时,我没有注意到他们给了我 3 个保存选项: debugmainrelease。我在 debug 中保存,这就是为什么当我去编译时,它没有在 debug 中搜索,而是在main中搜索。

解决方案:从 main 导入图标:
Android Studio -> new -> ImageAsset -> choose the image -> save to main