0
0

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]AndroidStudioをFlamingoにしたら起動ができずにjava.lang.IllegalAccessErrorの対策

Posted at

はじめに

Flutter開発はAndroidStudioで行っています。最近はVSCodeが増えてきているようですが、Studioの方がGUIが多くエミュ実行など含め数倍使いやすいので。
AndroidStudioのFlamingoがリリースされたのでインストールしたところFlutterでAndroidのエミュレータでエラーが出たので対応をメモ。

今回Flutter実行できがついただけで実際はAndroidStudioをアップグレードするとエラーになると思う。確認してないので不明です。Flutter要素もあるかも。

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.IllegalAccessError: class org.gradle.internal.compiler.java.ClassNameCollector (in unnamed module @0x6b2f1807) cannot access class com.sun.tools.javac.code.Symbol$TypeSymbol (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.code to unnamed module @0x6b2f1807

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

原因

FlamingoになってからJava17以降でないと動かないらしい。合わせてGradleも合わせないとダメそう。

javaのバージョンを確認。

% java -version                                                    (git)-[main]
java version "1.8.0_331"
Java(TM) SE Runtime Environment (build 1.8.0_331-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.331-b09, mixed mode)

解決

javaとgradleのバージョンをアップします
javaはhomebrewでインストールします。

まずbrewでopenjdk@17の詳細確認

% brew info openjdk@17                                             (git)-[main]
==> openjdk@17: stable 17.0.7 (bottled) [keg-only]
Development kit for the Java programming language
https://openjdk.java.net/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openjdk@17.rb
License: GPL-2.0-only with Classpath-exception-2.0
==> Dependencies
Build: autoconf ✔, pkg-config ✔
Required: giflib ✔, harfbuzz ✘, jpeg-turbo ✘, libpng ✘, little-cms2 ✘
==> Requirements
Build: Xcode (on macOS) ✔
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
  sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk

openjdk@17 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.
==> Analytics
install: 21,035 (30 days), 76,122 (90 days), 76,122 (365 days)
install-on-request: 10,435 (30 days), 11,213 (90 days), 11,213 (365 days)
build-error: 0 (30 days)

インストールされていないのでbrewでインストールします

% brew install openjdk@17                                          (git)-[main]
Running `brew update --auto-update`...
==> Auto-updated Homebrew!
Updated 3 taps (heroku/brew, homebrew/core and homebrew/cask).
==> New Formulae

次にパスを設定

% sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk

バージョン確認

% java -version                                                    (git)-[main]
openjdk version "17.0.7" 2023-04-18
OpenJDK Runtime Environment Homebrew (build 17.0.7+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.7+0, mixed mode, sharing)

これでアップしました。

あとはGradleをアップしたいので、AndroidStudioを立ち上げてリンクよりアップデートします。
a1.png

これでFlutterアプリを実行するとエミュレータで実行できました。
Flutterは依存がapple,googleとしててさらにFlutterなのでどこかでコケると処置が大変。
アップデートするときは覚悟持って時間ある時にやりましょう。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?