6
3

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 3 years have passed since last update.

FlutterアプリとFirebaseを連携させるときに困ったあれこれ

Posted at

FlutterをFirebaseと連携させようと色々弄ってたらこんなエラーに遭遇したのでメモ

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':firebase_core:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home contains a valid JDK installation.

筆者の環境

MacBook Air (M1, 2020) zsh

Flutter doctorの結果

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.3, on macOS 11.3.1 20E241 darwin-arm, locale
    ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[!] Android Studio (not installed)
[✓] Connected device (2 available)

! Doctor found issues in 1 category.

pubspec.yamlはこちら

pubspec.yaml
dependencies:
  flutter:
    sdk: flutter
  provider: ^5.0.0
  transparent_image: ^2.0.0
  firebase_core: ^1.5.0
  cloud_firestore: ^2.5.0
  flutter_slidable: ^0.6.0
  firebase_auth: ^3.1.0
  firebase_storage: ^10.0.3
  image_picker: ^0.8.4
  direct_select: ^2.0.0

実装の手順

1.https://www.oracle.com/java/technologies/downloads/#jdk17-mac からjavaのjdkをインストール(この過程でOracleアカウントを作成する必要あり)

2./usr/libexec/java_home -V | grep jdk コマンドでjdkがインストールされているか確認

3.android ディレクトリ内のgradle.propertiesファイルにorg.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Homeを追加

gradle.properties
org.gradle.jvmargs=-Xmx1536M
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home //これを追加する
android.useAndroidX=true
android.enableJetifier=true

4.appディレクトリ内のbuild.gradleファイルにあるdefaultConfigの中のminSdkVersionを16から21に書き換える

build.gradle
 defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.testapp"
        minSdkVersion 21 //ここがデフォルトでは16になってるからこれを21に変更する
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

5.アプリをリビルドする

以上の手順で自分の場合はエラーは解消されました。
それでは良いFlutterライフを!

6
3
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
6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?