Bad CPU type in executable —Error: Unable to 'pub upgrade' flutter tool
Overview
It might be the cache
Assuming you are on Flutter 3.0 on a Mac computer with Apple silicon, this error might mean you downgraded and or have a cache folder containing the older dart executables which are for Intel and won't run on Mac computers with Apple silicon. If that is the case you can
TL:DR — Delete the cache folder located in flutter/bin
. and rerun flutter doctor
Contents
- Bad CPU type in executable —Error: Unable to 'pub upgrade' flutter tool
- Overview
- It might be the cache
- Bad CPU type in executable
- Error: Unable to 'pub upgrade' flutter tool.
- Contents
- Overview
- Bad CPU type in executable Error: Unable to 'pub upgrade' flutter tool.
- Contents
- References
- AAPT still throws an error
- Its not the cache - Daemon startup failed
- Fixing the dependencies in my FlutterFlow based Flutter app
References
Bad CPU type in executable
Error: Unable to 'pub upgrade' flutter tool.
Contents
-
Overview
-
Bad CPU type in executable Error: Unable to 'pub upgrade' flutter tool.
-
Contents
-
References
AAPT still throws an error
Its not the cache - Daemon startup failed
My download from FlutterFlow still produces an error. There are some toolchain components that are causing an error - AAPT
, a tool which is bundled with android build tools and AAPT2
(Android Asset Packaging Tool), a build tool the Android Gradle Plugin use to compile and package your app’s resources. AAPT2 parses, indexes, and compiles the resources into a binary format that is optimized for the Android platform. Flutter uses Gradle so we better fix it without going down the Gradle rabbit hole.
A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> AAPT2 aapt2-4.1.2-6503028-osx Daemon #0: Daemon startup failed
This should not happen under normal circumstances, please file an issue if it does.
If you see this kind of failure try to run the tool directly in the terminal and you get a better error message
% ./aapt2
zsh: bad CPU type in executable: ./aapt2
So, this tells us that the aapt2
binary is an Intel executable. With the latest ndk release, and with the latest platform-tools and build-tools packages all these tools should be capable of running on a Mac computer with Apple silicon. So lets check our tools to make sure everything is where we need it to be.
Fixing the dependencies in my FlutterFlow based Flutter app
- Flutter reuqires the Android Gradle Plugin with support for Apple Silicon. In your project, adjust the
android/build.gradle
to setclasspath 'com.android.tools.build:gradle:7.2.0'
The android build system is based on Gradle, and the Android Gradle plugin adds several features that are specific to building Android apps. Android Studio 'Chipmunk' (2021.2.1) Supports a maximum plugin version of 7.2 which supports Apple Silicon. - In
android/gradle/wrapper/gradle-wrapper.properties
adjust the distributionURLdistributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
. This was necessary to avoid thebad CPU type in executable
errors. - It runs! My flutter APK is synced to my Google device, and runs there. It also runs in the arm based Google device emulators and is super fast! Unlike the old Intel emulators which were truly awful. I can use the hot reload and observatory debugger tools on my Apple Mac Mini M1, 2020 with Apple Silicon, without Rosetta.
References
See also: