Flutter 应用程序无法在 macOS Android 模拟器上运行

发布于 2025-01-13 16:18:31 字数 2582 浏览 1 评论 0原文

我有一个运行良好的应用程序,事实上它已经在 Google Play 上发布,没有任何问题,我面临的问题是这个应用程序不能在 MacOS 模拟器上运行,该模拟器的代码相同,没有任何更改或 flutter clean等将在WindowsOS模拟器上运行!

因此,每次我想要升级或测试我的应用程序时,我都必须切换到 Windows 系统,因为它不能在 MacO 上运行。

这是我尝试使用 Android Studio/ VsCode 在 MacO 上运行我的应用程序时遇到的错误

Launching lib/main.dart on sdk gphone64 x86 64 in debug mode...
Running Gradle task 'assembleDebug'...


FAILURE: Build failed with an exception.

* Where:
Script '/Users/home/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1102

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/Users/home/flutter/bin/flutter'' finished with non-zero exit value 1

* 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
Exception: Gradle task assembleDebug failed with exit code 1

到目前为止我为解决此问题所做的工作:

  1. 删除我的项目文件夹,例如 .idea 、 .dart_tool 、 android /.gradle , build
  2. 重新运行并重新生成所有这些文件夹
  3. 清除/无效缓存
  4. Flutter clean
  5. Flutter 升级
  6. 在 flutter 的 stable 和 master 分支之间切换
  7. 完全删除并重新下载我的 flutter系统(在新目录中)
  8. 运行 flutter doctorflutter doctor -v
$ flutter doctor -v
[✓] Flutter (Channel stable, 2.10.3, on macOS 12.2.1 21D62 darwin-x64, locale
    en-ID)
    • Flutter version 2.10.3 at /Users/home/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7e9793dee1 (11 days ago), 2022-03-02 11:23:12 -0600
    • Engine revision bd539267b4
    • Dart version 2.16.1
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version
    32.1.0-rc1)
    • Android SDK at /Users/home/Library/Android/sdk
    • Platform android-32, build-tools 32.1.0-rc1
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      
              

I have an application which is working fine, in fact it's already been published on Google Play with no issue, the issue I'm facing is that this app does not run on MacOS simulator which same code without any changes or flutter clean etc. will run on WindowsOS simulator!

Therefor each time I want to upgrade or test my app I have to switch to my Windows system because it does not run on MacOs.

Here is the error that I'm getting when trying to run my app on MacOs with Android Studio/ VsCode

Launching lib/main.dart on sdk gphone64 x86 64 in debug mode...
Running Gradle task 'assembleDebug'...


FAILURE: Build failed with an exception.

* Where:
Script '/Users/home/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1102

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/Users/home/flutter/bin/flutter'' finished with non-zero exit value 1

* 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
Exception: Gradle task assembleDebug failed with exit code 1

What I've done so far to fix this issue:

  1. Delete my project folders such as .idea , .dart_tool , android/.gradle , build
  2. Re-run and re generate all those folders
  3. Clear/invalidate caches
  4. Flutter clean
  5. Flutter upgrade
  6. Switch between stable and master branches of flutter
  7. Completely remove and re-download flutter on my system (in new directory)
  8. Running flutter doctor and flutter doctor -v
$ flutter doctor -v
[✓] Flutter (Channel stable, 2.10.3, on macOS 12.2.1 21D62 darwin-x64, locale
    en-ID)
    • Flutter version 2.10.3 at /Users/home/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7e9793dee1 (11 days ago), 2022-03-02 11:23:12 -0600
    • Engine revision bd539267b4
    • Dart version 2.16.1
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version
    32.1.0-rc1)
    • Android SDK at /Users/home/Library/Android/sdk
    • Platform android-32, build-tools 32.1.0-rc1
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      ???? https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      ???? https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)

[✓] VS Code (version 1.65.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.36.0

[✓] Connected device (3 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 12
      (API 32) (emulator)
    • macOS (desktop)              • macos         • darwin-x64     • macOS
      12.2.1 21D62 darwin-x64
    • Chrome (web)                 • chrome        • web-javascript • Google
      Chrome 97.0.4692.99

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Basically whatever you can find on the net I've tried, yet there is no luck with fixing this issue.

Any idea?

Update

pubspec.yaml

environment:
  sdk: ">=2.16.1 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

  cupertino_icons: ^1.0.2
  flutter_launcher_icons: ^0.9.2
  font_awesome_flutter: ^9.2.0
  share: ^2.0.4
  video_player: ^2.2.19
  chewie: ^1.3.0
  youtube_player_flutter: ^8.0.0
  shared_preferences: ^2.0.13
  intl: ^0.17.0
  provider: ^6.0.2
  audioplayers: ^0.20.1
  change_app_package_name: ^1.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^1.0.0

flutter_icons:
  android: true
  ios: true
  remove_alpha_ios: true
  image_path: "assets/icons/logo.png"

flutter:
  uses-material-design: true

  assets:
    - assets/icons/
    - assets/db/
    - assets/videos/
    - assets/lists/

  fonts:
    - family: Roboto
      fonts:
        - asset: fonts/Roboto-Regular.ttf
          style: normal

flutter_intl:
  enabled: true

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九命猫 2025-01-20 16:18:31

在您的计算机上启用虚拟机加速。
启动 Android Studio,单击 AVD Manager 图标,然后选择创建虚拟设备...
在旧版本的 Android Studio 中,您应该启动 Android Studio >工具>安卓> AVD 管理器并选择创建虚拟设备...。 (Android 子菜单仅在 Android 项目内部出现。)
如果您没有打开项目,您可以选择“配置”>“项目”。 AVD 管理器并选择创建虚拟设备...
选择设备定义并选择下一步。
为您要模拟的 Android 版本选择一个或多个系统映像,然后选择“下一步”。建议使用 x86 或 x86_64 映像。
在“模拟性能”下,选择“硬件 - GLES 2.0”以启用硬件加速。
验证 AVD 配置是否正确,然后选择“完成”。

有关上述步骤的详细信息,请参阅管理 AVD。

在 Android Virtual Device Manager 中,单击工具栏中的“运行”。模拟器启动并显示您所选操作系统版本和设备的默认画布。

Enable VM acceleration on your machine.
Launch Android Studio, click the AVD Manager icon, and select Create Virtual Device…
In older versions of Android Studio, you should instead launch Android Studio > Tools > Android > AVD Manager and select Create Virtual Device…. (The Android submenu is only present when inside an Android project.)
If you do not have a project open, you can choose Configure > AVD Manager and select Create Virtual Device…
Choose a device definition and select Next.
Select one or more system images for the Android versions you want to emulate, and select Next. An x86 or x86_64 image is recommended.
Under Emulated Performance, select Hardware - GLES 2.0 to enable hardware acceleration.
Verify the AVD configuration is correct, and select Finish.

For details on the above steps, see Managing AVDs.

In Android Virtual Device Manager, click Run in the toolbar. The emulator starts up and displays the default canvas for your selected OS version and device.

痞味浪人 2025-01-20 16:18:31

尝试打开设备,然后运行命令 flutter run

Try to turn on the device and then run the command flutter run

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文