7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

FlutterアプリをAndroid端末にインストールする時にハマった内容メモ

Last updated at Posted at 2022-06-10

はじめに

久しぶりにFlutterアプリを開発してAndroidで実機確認しようとした際に、上手くビルドできずに時間がかかってしまった。時間が経つと細かいところ忘れてしまうので、メモとしてハマったポイントを残しておく。

環境

【PC】
  MacBook Air (M1, 2020)

【各SWバージョン】
 ・macOS Big Sur 11.6.1
 ・Flutter 2.5.3 (dart 2.14.4)
 ・Xcode 13.1

メモ内容

Android実機にインストールするためflutter build apkを実行するがエラー

* What went wrong:
Execution failed for task ':app:checkReleaseAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > The minCompileSdk (31) specified in a]
・・・

SDKのバージョンが悪いとのことなので、以下を修正。

android/app/build.gradle
android {
    compileSdkVersion 30  ←ここを適切なバージョンに変更!

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "**************"
        minSdkVersion 16  ←ここを適切なバージョンに変更!
        targetSdkVersion 30  ←ここを適切なバージョンに変更!
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

再度flutter build apkを実行するが、またしてもエラー。今度のエラーメッセージは Kotlinのバージョンに問題があるらしい。

* What went wrong:
Execution failed for task ':app:compileReleaseKotlin'.
android/build.gradle
buildscript {
    // ext.kotlin_version = '1.3.50' コメントアウトして
    ext.kotlin_version = '1.4.32'  ←ここを適切なバージョンを追記!
    repositories {
        google()
        mavenCentral()
    }

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

上記を修正をしたら、一旦flutter build apkのコマンドよりビルドができたため、flutter install -d [端末シリアル] でインストールできた。

7
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?