失败:构建失败,出现Flutter异常

r3i60tvu  于 2023-02-09  发布在  Flutter
关注(0)|答案(5)|浏览(190)

我的flutter应用程序突然出现了问题。由于某种原因,我无法运行任何flutter文件。每次我尝试运行任何flutter项目时,它总是给我一个错误消息。

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':flutter_appavailability:androidApis'.
> Failed to transform file 'android.jar' to match attributes {artifactType=android-platform-attr} using transform PlatformAttrTransform
   > java.io.FileNotFoundException: /Users/wooyoung/Library/Android/sdk/platforms/android-27/android.jar (No such file or directory)

* Try:
Run with --stacktrace option to get the stack trace. Run with the -the-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 3s
Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

所以,我做了一个新的flutter应用程序来测试它是否只是我项目中的一个问题。但是它又给了我一个错误。

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Android resource linking failed
 Output:  W/ziparchive(29306): Unable to open '/Users/wooyoung/Library/Android/sdk/platforms/android-27/android.jar': No such file or directory
 error: failed to open APK: I/O error.

 Command:
/Users/wooyoung/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.1-4818971-osx.jar/7624077eb86a2607fdc7dac1f332a5dd/aapt2-3.2.1-4818971-osx/aapt2 link -I\
         /Users/wooyoung/Library/Android/sdk/platforms/android-27/android.jar\
         --manifest\
         /Users/wooyoung/Flutter/FlutterProjects/Experiment/j/build/app/intermediates/merged_manifests/debug/processDebugManifest/merged/AndroidManifest.xml\
  -o\
         /Users/wooyoung/Flutter/FlutterProjects/Experiment/j/build/app/intermediates/processed_res/debug/processDebugResources/out/resources-debug.ap_\
         -R\
         @/Users/wooyoung/Flutter/FlutterProjects/Experiment/j/build/app/intermediates/incremental/processDebugResources/resources-list-for-resources-debug.ap_.txt\
         --auto-add-overlay\
         --java\
         /Users/wooyoung/Flutter/FlutterProjects/Experiment/j/build/app/generated/not_namespaced_r_class_sources/debug/processDebugResources/r\
         --custom-package\
         com.example.j\
         -0\
         apk\
         --no-version-vectors
    Daemon:  AAPT2 aapt2-3.2.1-4818971-osx Daemon #0

* 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 2s
Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

我该怎么补救呢?

wsewodh2

wsewodh21#

您的Android sdk目录中似乎缺少必需的Android 27 API。请转到~/library/android/sdk/tools/bin并运行sdkmanager --list以检查您是否安装了platform-toolsplatforms;android-27。如果没有,则可以通过运行sdkmanager "platform-tools" "platforms;android-27"来安装它们
如果你有Android Studio,那么你也可以通过Android Studio的GUI安装它们。

fruv7luv

fruv7luv2#

打开文件菜单---〉项目结构---〉项目设置---〉项目
检查您的项目SDK
另外,检查〉〉〉项目结构---〉平台设置---〉sdks
给予相同的SDK并单击“确定”
尝试运行项目

ddhy6vgd

ddhy6vgd3#

尝试运行此命令:

flutter pub cache repair
bn31dyow

bn31dyow4#

无需进行更改,除了您的主.dart页面代码加载新项目在Android工作室(如果您配置正确)复制粘贴https://www.tutorialspoint.com/flutter/flutter_creating_simple_application_in_android_studio.htm从提供的网址和运行主.dart所有问题都会得到解决

u3r8eeie

u3r8eeie5#

你应该离开默认的启动画面,因为它需要时间来加载程序!

<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:drawable="@android:color/black"/>

   <!-- You can insert your own image assets here -->
<!--     <item>
       <bitmap
           android:gravity="center"
           android:src="@mipmap/launch_image"/>
   </item> -->
</layer-list>

相关问题