[flutter] Do It! 플러터 예제 코드 버전 관련 오류 수정

개요

 

플러터앱 개발에 관심이 생겨서 책을 한권 샀습니다.

Do it! 플러터 앱 프로그래밍 정가 3만원 짜리 책. 소스까지 제공되기에 이걸로 플러터를 익혀보자해서 샀는데 제공되는 예제코드 실행에 애를 먹었습니다. 

 

현재 진행해보고 있는 예제는 12장. 네이티브 API와 통신하기 부분인데 3가지 오류가 발생하고 있습니다. 

다만 플러터 빌드 시 오류에 대한 부분을 해결하는 명시적인 방법을 컴파일러가 알려주고 있어서 해결이 어렵지 않습니다.

 

 

 

 

본문

 

첫번째 오류

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Warning
──────────────────────────────────────────────────────────────────────────────
Your Flutter application is created using an older version of the Android
embedding. It is being deprecated in favor of Android embedding v2. Follow the
steps at

https://flutter.dev/go/android-project-migration

to migrate your project. You may also pass the --ignore-deprecation flag to
ignore this check and continue with the deprecated v1 embedding. However,
the v1 Android embedding will be removed in future versions of Flutter.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
The detected reason was:

  D:\dev\projects\flutter\doitflutter-master\Chapter12\native_example1\android\app\src\main\AndroidManifest.xml uses `android:name="io.flutter.app.FlutterApplication"`
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

 

 

해결

 

android/app/src/main/AndroidManifest.xml 파일 내 androidname 값을 아래와 같이 변경해줍니다.

 

기존
android:name="io.flutter.app.FlutterApplication"

변경
android:name="${applicationName}"

 

 

최종적으로 변경된 이미지입니다.

 

 

 

두번째 오류

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details

* 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 44s

┌─ Flutter Fix ────────────────────────────────────────────────────────────────────────────────┐
│ [!] Your project requires a newer version of the Kotlin Gradle plugin.                       │
│ Find the latest version on https://kotlinlang.org/docs/gradle.html#plugin-and-versions, then │
│ update                                                                                       │
│ D:\dev\projects\flutter\doitflutter-master\Chapter12\native_example1\android\build.gradle:   │
│ ext.kotlin_version = '<latest-version>'                                                      │
└──────────────────────────────────────────────────────────────────────────────────────────────┘
Exception: Gradle task assembleDebug failed with exit code 1

 

 

 

해결

 

File - Settings 셋팅창을 띄운 뒤 Languages & Frameworks 아래에 Kotlin 을 눌러보시면 Kotlin 버전을 확인하실수 있습니다. 제 현재 코틀린 버전은 1.6.10 으로 나와 있어서 이 버전으로 변경해줍니다.

 

창을 닫고 다시 아래 경로의 build.gradle 파일을 찾아가서 kotlin 버전을 1.6.10으로 변경해줍니다. 본인 코틀린 버전에 맞는 숫자로 변경해주면 됩니다.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

android/build.gradle 파일

 

변경전

ext.kotlin_version = '1.3.50'

 

변경후 

ext.kotlin_version = '1.6.10'

 

 

 

 

 

 

 

변경 된 buildscript 구조입니다.

buildscript {
    ext.kotlin_version = '1.6.10' //'1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

 

 

두번째 오류를 해결한 최종적으로 변경된 구조의 이미지입니다.

 

 

 

세번째 오류

FAILURE: Build failed with an exception.

* Where:
Build file 'D:\dev\projects\flutter\doitflutter-master\Chapter12\native_example1\android\app\build.gradle' line: 25

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'kotlin-android']
   > The current Gradle version 5.6.2 is not compatible with the Kotlin Gradle plugin. Please use Gradle 6.1.1 or newer, or the previous version of the Kotlin plugin.

* 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 2s
Exception: Gradle task assembleDebug failed with exit code 1

 

 

해결

이 에러는 gradle 버전을 올려야 한다고 명시적으로 기입이 되어 있습니다. 5.6.2 에서 6.1.1로 올려야 합니다.

android/gradle/wrapper/gradle-wrapper.properties 내 gradle 버전을 6.1.1 로 변경해서 받아오도록 수정해줍니다.

 

변경전
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip

변경후
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

 

 

 

마무리

 

 

세번째 오류까지 다 수정하고 난 뒤 디바이스 매니저로 구동시킨 안드로이드 에뮬레이터에서 구동된 모습입니다.

책 구매하고 예제 다운로드 까지는 좋았으나 최신 실행환경에서 돌리기 위해서는 수정해야 하는 번거로움이 있네요. 그래도 잘돌아가는 걸 보니 뿌듯합니다. 

 

 

Do it 플러터 앱 프로그래밍 저자가 제공해주는 소스코드는 아래 링크에서 확인하실수 있습니다.

https://github.com/rollcake86/DoitFlutter2.0

 

GitHub - rollcake86/DoitFlutter2.0: 2.0 버전업된 Doit Flutter 코드입니다.

2.0 버전업된 Doit Flutter 코드입니다. Contribute to rollcake86/DoitFlutter2.0 development by creating an account on GitHub.

github.com