LoginSignup
9
1

[Flutter]Unable to find bundled Java versionエラーを改善

Last updated at Posted at 2023-03-25

はじめに

Flutterで久しぶりにdoctorコマンドを実行したら「✗ Unable to find bundled Java version.」が出ました。以前は問題なく動作してたはずなので、最新のAndroidStudioのバージョンを上げたタイミングで問題が起きた模様。

% flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.5.1, on macOS 12.5 21G72 darwin-arm, locale
    ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version
    32.1.0-rc1)
[!] Xcode - develop for iOS and macOS
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin
        code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To install see
      https://guides.cocoapods.org/using/getting-started.html#installation for
      instructions.
[✓] Chrome - develop for the web
[!] Android Studio (version 2022.1)
    ✗ Unable to find bundled Java version.
[✓] VS Code (version 1.76.2)
[✓] Connected device (1 available)

原因

flutterの見ているjavaのパスが間違っている。jbrではなくjreが正しい。
Contents配下を見るとjbrになっていた。

/Applications/Android Studio.app/Contents/jbr

jreは「Java Runtime Environment」ということ。
AndroidStudioのバージョンを上げたことにより、AndroidStudioのバグでjbrになってしまったのかと思います。そのためいずれgoogleが治しそう。

修正

対処療法として、フォルダ名をjreにすればよさそうだが、AndroidStudioはjbrでないと現状は動作しないようなので、jbrフォルダをコピーしてjreと二つのフォルダを持つとよさそう。

下記をjbrをコピーして新規作成

/Applications/Android Studio.app/Contents/jre

またはシンボリックリンクを張るとよさそう。

ln -s jbr jre

しかし、AndroidStudioの一時的な問題の場合を考えるとコピーのほうがアンパイ。

doctorコマンドで再度確認

% flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.5.1, on macOS 12.5 21G72 darwin-arm, locale
    ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version
    32.1.0-rc1)
[!] Xcode - develop for iOS and macOS
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin
        code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To install see
      https://guides.cocoapods.org/using/getting-started.html#installation for
      instructions.
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.1)
[✓] VS Code (version 1.76.2)
[✓] Connected device (1 available)

OK

2024/3/29リリースのIguanaをインストール

新しく出たIguanaをインストールするとまたしても同じエラーが出ました。

% flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.6, on macOS 14.4.1 23E224 darwin-arm64,
    locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version
    32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.2)
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.84.2)
[✓] Connected device (2 available)
    ! Device 18101FDF6003S3 is not authorized.
      You might need to check your device for an authorization dialog.
[✓] Network resources

ということで改善は上と同じでjreフォルダをコピーして作れば改善されます。
もしかしたらFlutterが見ているパスの方がバグでそちらを直した方がいいのかもしれません。
しかしjbrって何の略でしょうか。jbrで問題なく実はFlutterの読み込もうとしてるパスを直した方がいいのかもしれませんが、一旦暫定対応で動作するのでこのままでよしとしておきます。

% flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.6, on macOS 14.4.1 23E224 darwin-arm64,
    locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version
    32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✓] Chrome - develop for the web
[!] Android Studio (version 2023.2)
    ✗ Unable to find bundled Java version.
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.84.2)
[✓] Connected device (2 available)
    ! Device 18101FDF6003S3 is not authorized.
      You might need to check your device for an authorization dialog.
[✓] Network resources

まとめ

AndroidはAndroidStudioやAGPやアップデートするとなかなか素直に動いてくれません。
Flutter開発のみであればVSCも体験が良かったのでそちらへの切り替えも検討して良いかもです。

9
1
1

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
9
1