10
4

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.

Android Studio Flamingoにアップデートするとプロジェクトのビルドに失敗する

Last updated at Posted at 2023-05-02

ビルドエラーの内容

ある日の朝、Android Studioのアップデートが来てたのでアップデートを実行すると、下記のようなエラーでプロジェクトのビルドが通らなくなりました。

class clojure.lang.Reflector cannot access class com.sun.tools.javac.model.JavacElements (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.model to unnamed module @14b2a021
	at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Unknown Source)

原因

Android Studio Flamingo の日本語版リリースノートを見てもこのようなエラーの原因っぽい更新が行われた様子はなく、エラー内容で調べてみても有力そうな情報が見当たらずで困っていたところ、ありました。英語版リリースノートに。

Android Studio bundled with JDK 17
Starting from Android Studio Flamingo Canary 3, the Studio IDE is bundled with JDK 17. If Android Studio is configured to use the embedded JDK, new projects will use the latest stable version of the Android Gradle plugin and JDK 17. However, existing projects might break, and you might have to manually set the JDK to a compatible version.

Android Studio Flamingo Canary 3 から JDK 17 がbundleされるようになったとのこと。これまでの Android Studio にbundleされていた JDK 11 を利用するプロジェクトではビルドが失敗するケースがあるようで、今回のプロジェクトもこのケースでした。

対処方法

Android Studio > Preferences > Build, Execution, Deployment > Build Tools > Gradle で、ビルドの際に利用するJDKを指定できます。
ここで JDK 11 を指定すると、 Android Studio Flamingo 以前と同様 JDK 11 を利用したビルドを行うよう設定できます。
image.png
プロジェクトを JDK 17 に対応させる、が100点の解決方法だと思いますが、すぐには対応できないことも多いので...。
すぐにビルドしたいのにエラーになった!JDK 17 対応なんてすぐにはできないよ!という場合の対処方法としてのご紹介でした。

10
4
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
10
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?