其他分享
首页 > 其他分享> > Using Flutter 2 on M1 MacOS Apple Silicon

Using Flutter 2 on M1 MacOS Apple Silicon

作者:互联网

What I want?

Building universal apps for iOS, Android, Windows, MacOS, Linux using Flutter on a M1 Mac.

 

This is very new and latest. I can't guarantee you can make it at 100%.

There's no official support since Apple silicon is still new in coding world.

 

Their full tutorial is here: https://flutter.dev/docs/get-started/install/macos

 

Here i only address some issues i met.

TL;DR

 

what we need?

1. Android studio preview 2021.1.1 Canery 3 (latest which supports m1)

2. flutter 2 SDK (latest stable version)

3. java sdk ( openjdk 11 from zulu built for macos arm64)

4. cocoapods ( Open your Terminal.app with Rosetta 2 )

 

Step 1 is very easy. 

go https://developer.android.com/studio/archive

and download the one for m1 mac.

 

 

when you open the android studio, don't forget to install all the SDK you need. Here is one important tool. Android SDK command-line Tools 

 

Install the Flutter 2.

go here: https://flutter.dev/docs/get-started/install/macos

Very easy just follow the steps.

 

I need to build apps for desktop so i enabled this(you don't have to, this is optional if you only want to build apps for iOS and Android): https://flutter.dev/desktop

 

Then use commands 

flutter doctor -v

to check your system

 

I had this issue with my Android Studio Preview

 

 

Solve it 

Android Toolchains. Install all the SDK that you need when you open the Android Studio Preview for the first time. 

Xcode. Install Xcode from Apps Store and install xcode command lines. Just wait by several clicks.

cocoapods. Copy and paste a new Terminal.app to desktop and open it using Rosetta 2 like this.

Then in the rosetta 2 terminal, install cocoapods by commands

sudo gem install cocoapods

Ruby 2 is installed on MacOS 11 by default but its fii lib is still built on top of x86_64 architecture though Apple claimed Ruby 2 on MacOS 11 is for 2 architectures such as x86_64 and ARM64, which is a lie.

If you simply install cocoapods using the ARM64 version of ruby 2 on MacOS 11, you will fail to load the fii libs. fii is a lib which can talk to native c libs on macos, we need it so much.

 

Android studio: Unable to find bundled java version.

Solution: https://github.com/flutter/flutter/issues/76215#issuecomment-864407892

in source codes,

flutter/packages/flutter_tools/lib/src/android/android_studio.dart

Line 465 in 3c72ef3

 globals.fs.path.join(directory, 'jre', 'jdk', 'Contents', 'Home') : 

There should be check for
join(directory, 'jre', 'Contents', 'Home') instead of
join(directory, 'jre', 'jdk', 'Contents', 'Home')

for newest android studio previews (at least on macos).
Workaround for such people: copy folder

/Applications/Android Studio Preview.app/Contents/jre/Contents to
/Applications/Android Studio Preview.app/Contents/jre/jdk/Contents

Just copy the folder Contents to a new folder jdk inside of the main app. (This is a bug which would be fixed in the future)

 

 

Then go back to my normal terminal which is ARM64 native and do the doctor check.

标签:MacOS,Apple,Silicon,studio,install,Android,flutter,Contents
来源: https://www.cnblogs.com/spaceship9/p/15012451.html