민프

[Flutter] M1 MAC에서 android Studio Flutter 개발환경 구축하기 (feat. Error installing cocoapods) 본문

[Flutter]

[Flutter] M1 MAC에서 android Studio Flutter 개발환경 구축하기 (feat. Error installing cocoapods)

민프야 2023. 8. 4. 16:35

Flutter SDK 다운로드

https://docs.flutter.dev/get-started/install

 

Install

Install Flutter and get started. Downloads available for Windows, macOS, Linux, and ChromeOS operating systems.

docs.flutter.dev

위 링크를 따라 들어가서 아래 사진과 같이 macOS를 클릭하고 Apple Sillcon .zip파일을 다운받는다. 

.zip을 받고 나면 문서에 나온 커맨드 대로 내가 원하는 경로에 이동 후 unzip을 해준 후에 PATH 변수를 설정해주면 된다. 

위 와 같이 설정하게 되면 현재 터미널 창에서만 PATH 변수가 설정 되는 것 이므로 영구적으로 PATH 설정을 유지하고 싶으면 아래 링크처럼 등록해주면 된다. 

$ vi ~/.zshrc

#Flutter
export PATH="$PATH:/Users/[USER_DIR]/development/Flutter/bin"

// .zshrc 파일 저장 후

$ source .zshrc

설치를 하고 Flutter가 잘 설치되었는지 아래 커맨드를 입력하면 사진과 같이 나오게 되는데 여기에서 모든 항목이 올바르게 설정되었는지 볼 수 있다.

flutter doctor

현재 사진을 보면 xcode, Android toolchain 쪽에서 필수적인 뭔가가 설치가 안되어있는 것을 확인 할 수 있다. 

사진에 나와있는대로 커맨드를 입력해서 부족한 부분을 설치해주도록 하자

 

ㅇ. Xcode 설치

XCODE를 설치해주고 난 후에 아래 커맨드를 입력해보자

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch

이제 라이센스에 서명만 하면 된다. (아래 커맨드 입력)

sudo xcodebuild -license

입력을 하게 되면 아래와 같이 agree를 입력해주면 서명이 완료된다. 

ㅇ. CocoaPods 설치

이번엔 설치 가이드 문서를 보면서 CocoaPods를 설치해주자 (아래 커맨드 입력)

https://guides.cocoapods.org/using/getting-started.html#installation

 

CocoaPods Guides

CocoaPods is fully open-sourced, so it depends on community contributions to get better. If you're looking to start working on CocoaPods, this is the place to start.

guides.cocoapods.org

// intel Chip 일 경우
sudo gem install cocoapods
// Apple Silicon 일 경우
sudo gem uninstall ffi && sudo gem install ffi -- --enable-libffi-alloc

에러상황

ERROR:  Error installing cocoapods:
	The last version of activesupport (>= 5.0, < 8) to support your Ruby & RubyGems was 6.1.7.4. Try installing it with `gem install activesupport -v 6.1.7.4` and then running the current command again
	activesupport requires Ruby version >= 2.7.0. The current ruby version is 2.6.10.210.

위와 같은 에러가 나왔다..

문제의 원인은 Ruby 버전과 호환되는 Active Support 버전이 없어서 발생하는 것이다.

따라서, Ruby 버전을 업그레이드하거나 Active Support 버전을 낮춰주는 것이 있는데 일단 Ruby를 최신 버전으로 설치해보자

 

에러 해결 방법 -  Ruby 최신 버전으로 설치하기

brew install ruby

Install이 완료 되면 MAC 재부팅을 한 후에 다시 아래 커맨드를 입력해서 설치해보자

// intel Chip 일 경우
sudo gem install cocoapods
// Apple Silicon 일 경우
sudo gem uninstall ffi && sudo gem install ffi -- --enable-libffi-alloc

 

설치가 완료 되고 아래 커맨드를 쳐서 설치가 잘 된건지 확인해보자

pod --version

 

이렇게해도 설치가 안된다면 삭제 후 brew로 재설치 해보고 다시 버전을 확인해보자

// 삭제
sudo gem uninstall cocoapods

// brew를 이용하여 재설치
brew install cocoapods

1.12.1 버전으로 잘 설치된 것을 확인할 수 있다. 

 

Android Studio 다운로드

아래 링크에서 다운 받으면 된다.

https://developer.android.com/studio

 

Download Android Studio & App Tools - Android Developers

Android Studio provides app builders with an integrated development environment (IDE) optimized for Android apps. Download Android Studio today.

developer.android.com

ㅇ. 안드로이드 의존성 설치

More Actions -> SDK Manager 실행

SDK Tools -> Android SDK Command -line Tools를 선택 -> OK 버튼 눌러서 설치

 

 

ㅇ. Android licenses 설정

아래 커맨드를 입력해서 라이센스에 동의를 해주자

flutter doctor --android-licenses

 

 

ㅇ. Flutter Plugins 설치

Settings -> Plugins -> Flutter 설치

 

이렇게 설치 후 아래 커맨드를 입력 후 잘 설치되었는지 확인해보자

flutter doctor -v

잘 설치 된 것을 확인할 수 있다. 


이제 설치는 끝났다
android Studio에서 Flutter Project를 만들고 실행시켜보자

아래 사진과 같이 잘 실행되는 것 을 확인할 수 있다. 

 

Comments