Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Studio 4.1: google-java-format option not appearing in "Other Settings" #536

Closed
brianliyang opened this issue Oct 18, 2020 · 17 comments
Labels

Comments

@brianliyang
Copy link

I upgraded from Android Studio 4.0 to 4.1 and the google-java-format plugin seemed to stop working. At first, it was because all my plugins were reset so I reinstalled the plugin (1.9.0.0) from Marketplace. As per the README for Intellij setup, I tried to go to "Other Settings" in my project settings to enable google-java-format for my project. However, the option doesn't appear where it used to be.

androidstudio-4 1

On my other machine with Android Studio 4.0 and google-java-format v1.7.0.4 installed, the option is there (see below).

androidstudio-4 0

Has there been a regression in compatibility with Android Studio 4.1?

@yvvr
Copy link

yvvr commented Oct 19, 2020

when I upgraded Android Studio 4.0 to 4.1 I got this exception while loading google-java-format 1.9.0.0 version plugin.

com.intellij.diagnostic.PluginException: While loading class com.google.googlejavaformat.intellij.GoogleJavaFormatConfigurable: com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0 [Plugin: google-java-format] [Plugin: google-java-format]
	at com.intellij.openapi.options.ConfigurableEP.createProducer(ConfigurableEP.java:299)
	at com.intellij.openapi.util.AtomicNotNullLazyValue$1.compute(AtomicNotNullLazyValue.java:59)
	at com.intellij.openapi.util.AtomicNotNullLazyValue.getValue(AtomicNotNullLazyValue.java:37)
	at com.intellij.openapi.options.ConfigurableEP.canCreateConfigurable(ConfigurableEP.java:342)
	at com.intellij.openapi.options.ex.ConfigurableWrapper.wrapConfigurable(ConfigurableWrapper.java:34)
	at com.intellij.openapi.options.ex.ConfigurableExtensionPointUtil.getConfigurables(ConfigurableExtensionPointUtil.java:383)
	at com.intellij.openapi.options.ex.ConfigurableExtensionPointUtil.lambda$getConfigurableGroup$0(ConfigurableExtensionPointUtil.java:128)
	at com.intellij.openapi.util.ClearableLazyValue$2.compute(ClearableLazyValue.java:30)
	at com.intellij.openapi.util.ClearableLazyValue.getValue(ClearableLazyValue.java:45)
	at com.intellij.openapi.util.AtomicClearableLazyValue.getValue(AtomicClearableLazyValue.java:21)
	at com.intellij.openapi.options.ex.EpBasedConfigurableGroup.<init>(EpBasedConfigurableGroup.kt:100)
	at com.intellij.openapi.options.ex.ConfigurableExtensionPointUtil.getConfigurableGroup(ConfigurableExtensionPointUtil.java:127)
	at com.intellij.ide.actions.ShowSettingsUtilImpl.getConfigurableGroups(ShowSettingsUtilImpl.java:50)
	at com.intellij.ide.actions.ShowSettingsAction.perform(ShowSettingsAction.java:54)
	at com.intellij.ide.actions.ShowSettingsAction.actionPerformed(ShowSettingsAction.java:41)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:280)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.lambda$actionPerformed$0(ActionMenuItem.java:296)
	at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:281)
	at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.runOnOwnContext(IdeFocusManagerImpl.java:77)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:285)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem.lambda$fireActionPerformed$0(ActionMenuItem.java:112)
	at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:94)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:112)
	at com.intellij.ui.plaf.beg.BegMenuItemUI.doClick(BegMenuItemUI.java:517)
	at com.intellij.ui.plaf.beg.BegMenuItemUI.access$300(BegMenuItemUI.java:36)
	at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:539)
	at java.awt.Component.processMouseEvent(Component.java:6550)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3325)
	at java.awt.Component.processEvent(Component.java:6315)
	at java.awt.Container.processEvent(Container.java:2239)
	at java.awt.Component.dispatchEventImpl(Component.java:4899)
	at java.awt.Container.dispatchEventImpl(Container.java:2297)
	at java.awt.Component.dispatchEvent(Component.java:4721)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
	at java.awt.Container.dispatchEventImpl(Container.java:2283)
	at java.awt.Window.dispatchEventImpl(Window.java:2746)
	at java.awt.Component.dispatchEvent(Component.java:4721)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:766)
	at java.awt.EventQueue.access$500(EventQueue.java:98)
	at java.awt.EventQueue$3.run(EventQueue.java:715)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
	at java.awt.EventQueue$4.run(EventQueue.java:739)
	at java.awt.EventQueue$4.run(EventQueue.java:737)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:736)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:974)
	at com.intellij.ide.IdeEventQueue.dispatchMouseEvent(IdeEventQueue.java:912)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:844)
	at com.intellij.ide.IdeEventQueue.lambda$null$8(IdeEventQueue.java:449)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:741)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$9(IdeEventQueue.java:448)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:831)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:502)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: com.intellij.diagnostic.PluginException: While loading class com.google.googlejavaformat.intellij.GoogleJavaFormatConfigurable: com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0 [Plugin: google-java-format]
	at com.intellij.ide.plugins.cl.PluginClassLoader.loadClassInsideSelf(PluginClassLoader.java:262)
	at com.intellij.ide.plugins.cl.PluginClassLoader.tryLoadingClass(PluginClassLoader.java:205)
	at com.intellij.ide.plugins.cl.PluginClassLoader.loadClass(PluginClassLoader.java:113)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at com.intellij.openapi.extensions.AbstractExtensionPointBean.findClass(AbstractExtensionPointBean.java:59)
	at com.intellij.openapi.extensions.AbstractExtensionPointBean.findExtensionClass(AbstractExtensionPointBean.java:48)
	at com.intellij.openapi.options.ConfigurableEP.createProducer(ConfigurableEP.java:291)
	... 65 more
Caused by: java.lang.UnsupportedClassVersionError: com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:757)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:636)
	at com.intellij.util.lang.UrlClassLoader._defineClass(UrlClassLoader.java:380)
	at com.intellij.util.lang.UrlClassLoader.defineClass(UrlClassLoader.java:376)
	at com.intellij.util.lang.UrlClassLoader._findClass(UrlClassLoader.java:340)
	at com.intellij.ide.plugins.cl.PluginClassLoader.loadClassInsideSelf(PluginClassLoader.java:259)
	... 73 more

@morphine9
Copy link

upvote for AS 4.1

2 similar comments
@iTheDaybreak
Copy link

upvote for AS 4.1

@ReinisSeredzinsS
Copy link

upvote for AS 4.1

@tbroyer
Copy link
Contributor

tbroyer commented Oct 26, 2020

Caused by: java.lang.UnsupportedClassVersionError: com/google/googlejavaformat/intellij/GoogleJavaFormatConfigurable has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

Google Java Format 1.9 requires JDK 11, and apparently Android Studio uses/bundles JDK 8 (JBR 8). So the problem isn't an incompatibility with AS 4.1 in itself, but incompatibility with the bundled JDK, and updating your Android Studio probably means you reinstalled and/or updated the GJF plugin to 1.9.

According to https://www.reddit.com/r/android_devs/comments/hiv4d7/using_a_jdk_other_than_the_one_bundled_with/fwip1qz/ you should be able to easily run Android Studio with JDK 11, through https://plugins.jetbrains.com/plugin/12836-choose-runtime

Either that or downgrade the GJF plugin to 1.8.

@ened
Copy link

ened commented Oct 31, 2020

Is it somehow possible to make the plugin compatible with the JDK that ships with Android Studio by default? Getting other engineers to adjust their IDE settings just to make a formatting plugin work is a huge headache. Problems will get misidentified, etc..

Additionally, there is no option to downgrade from within AS.

Screen Shot 2020-10-31 at 15 47 19

I fully understand this on Android Studio shipping with a antique JDK and we should somehow let the Android Tools team know about this, but for the current state of affairs, it would be great to have a out-of-the box working version of the formatter.

PS: The formatter plugin in AS mentions a bump to version 1.9 of the plugin but does not mention the new JDK requirement in any shape or format. This should be included, really.

@jbduncan
Copy link
Contributor

The workaround I'd personally use is to:

  1. Import a formatter plugin for Gradle like sherter/google-java-format-gradle-plugin or diffplug/spotless.
  2. Set it up to use google-java-format 1.7, which is the last version to not require Java 11 (source).
  3. In Android Studio, instead of using Ctrl+Alt+L or +Alt+L to format your code, use double Ctrl and then enter "gradle goJF", "gradle spotlessApply" or whatever your plugin of choice's formatting task name is.

@plumpy
Copy link
Collaborator

plumpy commented Nov 5, 2020

Unfortunately there's no way to mark a plugin as only being compatible with a given JDK. If there was such a way, I could tell it only only use 1.8 unless you have a Java 11 JDK. But there's not AFAIK. I suppose I could just mark 1.9 as incompatible with Android Studio entirely? But that would prevent anyone from using it. But I suppose Android Studio users probably aren't writing a lot of Java 14 code, so don't really need gjf 1.9...

I don't really know what the right thing to do here is.

@ened
Copy link

ened commented Nov 5, 2020

I don't really know what the right thing to do here is.

Revert the changes in 1.9 that made it incompatible with JDK 1.8?

@ened
Copy link

ened commented Nov 18, 2020

@plumpy WDYT about reverting the plugin back to compatibility with JDK 1.8?

@plumpy
Copy link
Collaborator

plumpy commented Nov 19, 2020

IntelliJ has been shipping with a Java 11 JRE since 2019.2. Android Studio started shipping with Java 11 in 4.2 (which uses the 2020.2 API). There's no way I can find to say "this plugin is compatible with API 2019.2+ except for Android Studio, where it's only compatible with 2020.2+".

I can't even mark it as "incompatible with Android Studio" because incompatible-with isn't supported until Android Studio 4.2 (at which point the plugin actually works fine, so that's not useful).

I don't want to break compatibility for all the IntelliJ users (which has literally 10x as many users as Android Studio). So I'd recommend either manually downgrading the plugin or upgrading to AS 4.2 canary. Sorry, I know it's frustrating.

@ened
Copy link

ened commented Nov 19, 2020

@plumpy What part of google-java-format requires JDK 11 functionality to work?

Would downgrading the requirement to JDK 8 in the plugin break IntelliJ users?

I'd assume JDK 11 can execute JDK8 code just fine?

@HideNameUser
Copy link

HideNameUser commented Feb 25, 2021

I found a solution。
Download the google-java-format 1.7.0.5 plugin from https://plugins.jetbrains.com/plugin/8527-google-java-format/versions/stable/83169
Android Studio --- Preference --- Plugin --- install from disk
install this plugin.

@cushon
Copy link
Collaborator

cushon commented Feb 25, 2021

What part of google-java-format requires JDK 11 functionality to work?

It's required JDK 11 since release 1.8, as part of supporting formatting Java 11+ language features and minimizing the number of versions of the javac APIs it neds to remain compatible with: 3c191c1

@morphine9
Copy link

Either that or downgrade the GJF plugin to 1.8.

tried downgrading to 1.8 from here - https://github.com/google/google-java-format/releases/tag/google-java-format-1.8
but not working on Android Studio 4.1 (showing no exceptions either)

install from disk and choosing google-java-format-1.7.tar.gz doesn't work @plumpy .. any insights why ?

@BearKid
Copy link

BearKid commented Apr 4, 2021

Either that or downgrade the GJF plugin to 1.8.

tried downgrading to 1.8 from here - https://github.com/google/google-java-format/releases/tag/google-java-format-1.8
but not working on Android Studio 4.1 (showing no exceptions either)

install from disk and choosing google-java-format-1.7.tar.gz doesn't work @plumpy .. any insights why ?

maybe you should download the jetbrains plugin v1.7 from https://plugins.jetbrains.com/plugin/8527-google-java-format

@plumpy
Copy link
Collaborator

plumpy commented Nov 23, 2021

Since newer versions of Android Studio ship with Java 11, this shouldn't be an issue anymore.

@plumpy plumpy closed this as completed Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests