Home > Software design >  Error when building Flutter project Android with VSCode on M1 Macbook
Error when building Flutter project Android with VSCode on M1 Macbook

Time:01-04

I'm using M1 Mackbook air.

This is the result of installing Flutter-related extensions, Android Studio, and Android SDK and running Flutter Doctor.

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.3.10, on macOS 12.1 21C52 darwin-arm, locale
    ko-KR)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✗] Xcode - develop for iOS and macOS
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS
      development.
      Download at: https://developer.apple.com/xcode/download/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
        sudo xcodebuild -runFirstLaunch
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin
        code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To install see
      https://guides.cocoapods.org/using/getting-started.html#installation for
      instructions.
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.74.2)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

When executing Debug in the lib/main.dart file of the project created using flutter create, the following error appears. (the Android emulator specs are: Pixel 4, Android 10)

Launching lib/main.dart on Android SDK built for arm64 in debug mode...                                                                    lib/main.dart:1

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':app:processDebugResources' (type 'LinkApplicationAndroidResourcesTask').
  - In plugin 'com.android.internal.version-check' type 'com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask' property 'androidJarIn 
put.androidJar' specifies file '/Users/gimmingi/Library/Android/sdk/platforms/android-31/android.jar' which doesn't exist.

    Reason: An input file was expected to be present but it doesn't exist.

    Possible solutions:
      1. Make sure the file exists before the task is called.
      2. Make sure that the task which produces the file is declared as an input.
 
    Please refer to https://docs.gradle.org/7.4/userguide/validation_problems.html#input_file_does_not_exist for more details about this problem.

* 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 1s
Exception: Gradle task assemble Debug failed with exit code 1 
Exited

Flutter default project should work in Android emulator.

CodePudding user response:

Please check following items

  1. As your build is trying to access android version 31 here android-31/android.jar. Check if android 31 is installed on your machine.

  2. Check the compileSdkVersion and targetSdkVersion in your android/app/build.gradle file.

android {
  ...
  compileSdkVersion 31

  defaultConfig{
    ...
      targetSdkVersion 31
    ...
  }
}

Then you can either download the version 31 or change your sdk versions matching your installed sdk versions.

  • Related