ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Flutter] 플러터 설치 및 환경설정 에러 해결
    Flutter 2021. 6. 16. 17:15

     

    최근에는 멀티 플랫폼을 지원하는 개발툴이 다양하게 존재한다. 물론 앱이 고도화되면 플랫폼별로 네이티브 개발을 하는게 제일 좋겠지만, 프로토타입을 개발하거나 MVP 버전의 앱을 개발하는 것은 멀티 플랫폼 툴이 아무래도 편한 것이 사실이다.

     

    이번에 새로운 작업을 검토하면서 대세에 따라 Flutter를 활용해 보려고 야심차게 SDK 설치를 진행했다. 
    Flutter가 대세 중 대세라고 하지만 설정 과정은 역시나 구글스러워서 셋업중 예상치 못한 에러를 몇 개 만났다. 해결 방법을 정리해 본다.

     

     

    Installation Process

     

    [Android Studio 설치]

     

    안드로이드 개발자라면 대부분 설치가 되어 있겠지만 없다면 안드로이드 개발 환경 설치가 필요하다. JDK나 에디터를 따로 설치해도 무방하지만 Android Studio는 Open JDK를 내장하고 있어서 안드로이드 개발환경이 쉽게 완료된다. 이 링크에서 다운받을 수 있다.

     

    [Flutter 설치]

     

    Flutter 설치는 간단하다. 스테이블 버전을 압축 파일로 받아 압출을 풀거나 Git에서 최신 버전을 당겨오는 것으로 Flutter의 설치는 사실상 완료된다. 한 가지 주의할 점은 압축을 푼 디렉토리가 Program Files 등 권한이 필요한 디렉토리가 아니어야 한다는 점이다. 윈도우향 Flutter는 이 링크에서 다운받을 수 있다.

     

    [환경변수 설정]

     

    Flutter 디렉토리 밑의 bin 디렉토리에 Flutter의 executable 및 배치 파일들이 들어있다. 해당 위치를 환경변수 path에 추가해 준다.

    [설치 확인]

     

    환경 변수가 설정되었다면 command 창 어느 위치에서나 flutter 커맨드를 실행 가능하다. 설치 확인을 위해 Flutter가 설치된 디렉토리로 이동해 다음 명령을 실행한다.

     

    c:\FLUTTER_PATH> flutter doctor

     

    다음과 같이 모두 패스가 되면 환경이 완료된 것이다.

     

    Doctor summary (to see all details, run flutter doctor -v):
    [√] Flutter (Channel stable, 2.2.2, on Microsoft Windows [Version 10.0.19042.985], locale en-US)
    [√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    [√] Chrome - develop for the web
    [√] Android Studio
    [√] VS Code (version 1.57.0)
    [√] Connected device (2 available)

     

    하지만 개발이 늘 그렇듯이, 게다가 오픈소스 개발 환경이 늘 그렇듯이 한 번에 되기가 어렵다.

     

     

    Issues

     

    [No JDK]

     

    분명 안드로이드 스튜디오가 설치되어 있는데 JDK를 못 찾는 경우 다음 에러가 나타난다.

     

    c:\FLUTTER_PATH>flutter doctor
    [!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        X No Java Development Kit (JDK) found; You must have the environment variable 
        JAVA_HOME set and the java binary in your PATH. You can download the JDK from 
        https://www.oracle.com/technetwork/java/javase/downloads/.

     

    해결 방법은 flutter config --android-studio-dir 명령으로 안드로이드 스튜디오 위치를 지정해 주는 것이다. 내 경우에는 디펄트 위치인 Program Files\Android\Android Studio에 설치가 되어 있어 다음과 같이 설정했다.

     

    c:\FLUTTER_PATH>flutter config --android-studio-dir="c:\Program Files\Android\Android Studio"

     

     

    [No SDK]

     

    보통은 괜찮지만, 만약 안드로이드 SDK를 기본 위치가 아닌 다른 위치에 설치한 경우 다음 에러가 나타난다.

     

    C:\FLUTTER_PATH>flutter doctor
    Doctor summary (to see all details, run flutter doctor -v):
    ...
    [X] Android toolchain - develop for Android devices
        X Unable to locate Android SDK.
          Install Android Studio from: https://developer.android.com/studio/index.html
          On first launch it will assist you in installing the Android SDK components.
          (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).
          If the Android SDK has been installed to a custom location, please use
          `flutter config --android-sdk` to update to that location.

     

    해결 방법은 flutter config --android-sdk 명령으로 안드로이드 SDK의 위치를 지정해 주는 것이다. 예를 들어, C:\SDK\adnroid_sdk에 설치가 되어 있다면 다음과 같이 설정한다.

     

    flutter config --android-sdk="c:\SDK\androidsdk"

     

     

    [Android Licenses]

     

    이제 다시 flutter doctor를 실행하면 이번엔 안드로이드 라이선스에 문제가 있단다.

     

    c:\FLUTTER_PATH>flutter doctor
    [!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        X Android license status unknown.
          Run `flutter doctor --android-licenses` to accept the SDK licenses.
          See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.

     

    해결 방법은 flutter doctor --android-licenses 명령을 통해 안드로이드 라이선스에 동의하는 것이다. 그런데 이게 또 에러가 난다.

     

    c:\FLUTTER_PATH>flutter doctor --android-licenses
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
            at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
            at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
            at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
            at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
            at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
    Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
            at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
            at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
            at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
            ... 5 more

     

    Java에 익숙한 사람이라면 바로 눈치채겠지만 이건 200% JDK를 못찾는 경우이다. 분명 안드로이드 스튜디오 위치를 지정했는데 무슨 일인가 싶을텐데, 원인은 커맨드라인 툴이 없어서 그렇다.

    안드로이드 스튜디오의 우상단에 위치한 메뉴바에서 SDK 매니저 버튼을 클릭해 SDK 매니저를 실행한다. (Tools->SDK Manager 메뉴를 선택해도 된다.)

     


    그러면 다음의 화면이 나타난다.

     

    다음 과정을 수행한다.

    1. 왼쪽 트리 메뉴에서 Appearance & Behavior > System Settings > Android SDK 선택
    2. 우측에서 SDK Tools 선택
    3. 하단의 Hide Obsolete Packages 체크박스 해제
    4. Android SDK Command-line tools 선택
    5. Android SDK Tools (Obsolete) 선택
    6. Apply 버튼 클릭

     

    이후 설치 과정을 진행하고 완료될 때까지 기다린다. 설치가 완료되면 다시 Command 창으로 돌아가 Flutter 설치 디렉토리에서 --android-licenses를 수행한다.

     

    c:\FLUTTER_PATH>flutter doctor --android-licenses
    6 of 7 SDK package licenses not accepted. 100% Computing updates...
    Review licenses that have not been accepted (y/N)? y
    ...
    
    14.7 This License Agreement, and your relationship with Google under this License Agreement, 
    shall be governed by the laws of the State of California without regard to its conflict of 
    laws provisions. You and Google agree to submit to the exclusive jurisdiction of the courts 
    located within the county of Santa Clara, California to resolve any legal matter arising 
    from this License Agreement. Notwithstanding this, you agree that Google shall still be 
    allowed to apply for injunctive remedies (or an equivalent type of urgent legal relief) in 
    any jurisdiction.
    
    
    August 15, 2011
    ---------------------------------------
    Accept? (y/N): y
    
    ...
    
    All SDK package licenses accepted

     

    주루룩 나오는 라이선스에 y키를 눌러 하나 하나 동의해주면 라이선스 동의 과정이 완료된다. 이제 두근거리는 마음으로 다시 설치를 확인한다.

     

    c:\FLUTTER_PATH> flutter doctor
    Doctor summary (to see all details, run flutter doctor -v):
    [√] Flutter (Channel stable, 2.2.2, on Microsoft Windows [Version 10.0.19042.985], locale en-US)
    [√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    [√] Chrome - develop for the web
    [√] Android Studio
    [√] VS Code (version 1.57.0)
    [√] Connected device (2 available)

     

    설치 상태가 체크되었고 이제 Flutter를 사용할 준비가 완료되었다. 사실 구글정도 되는 회사가 사람 몇 명 투입해서 간단한 GUI 몇 개 제공해주면 끝날 일인데 아쉽다는 생각을 해본다.

     

     

    Fin.

    반응형

    댓글

Calvin's Memo