コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7

概要

Running Gradle...

XXXX\Temp\PlayServicesResolverGradle\gradlew.bat --no-daemon -b "XXXX\Temp\PlayServicesResolverGradle\PlayServicesResolver.scripts.download_artifacts.gradle" "-PANDROID_HOME=C:\Program Files\Unity\Hub\Editor\2022.1.11f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK" "-PTARGET_DIR=XXXX\Assets\Plugins\Android" "-PMAVEN_REPOS=" "-PPACKAGES_TO_COPY=com.google.android.play:core-common:2.0.0;com.google.android.play:review:2.0.0" "-PUSE_JETIFIER=0" "-PDATA_BINDING_VERSION=4.0.1"
Executing command: XXXX\Temp\PlayServicesResolverGradle\gradlew.bat --no-daemon -b "XXXX\Temp\PlayServicesResolverGradle\PlayServicesResolver.scripts.download_artifacts.gradle" "-PANDROID_HOME=C:\Program Files\Unity\Hub\Editor\2022.1.11f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK" "-PTARGET_DIR=XXXX\Assets\Plugins\Android" "-PMAVEN_REPOS=" "-PPACKAGES_TO_COPY=com.google.android.play:core-common:2.0.0;com.google.android.play:review:2.0.0" "-PUSE_JETIFIER=0" "-PDATA_BINDING_VERSION=4.0.1"

ERROR: Gradle failed to fetch dependencies.

Failed to run 'XXXX\Temp\PlayServicesResolverGradle\gradlew.bat --no-daemon -b "XXXX\Temp\PlayServicesResolverGradle\PlayServicesResolver.scripts.download_artifacts.gradle" "-PANDROID_HOME=C:\Program Files\Unity\Hub\Editor\2022.1.11f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK" "-PTARGET_DIR=XXXX\Assets\Plugins\Android" "-PMAVEN_REPOS=" "-PPACKAGES_TO_COPY=com.google.android.play:core-common:2.0.0;com.google.android.play:review:2.0.0" "-PUSE_JETIFIER=0" "-PDATA_BINDING_VERSION=4.0.1"'
stdout:

stderr:
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
    at org.codehaus.groovy.vmplugin.VMPluginFactory.<clinit>(VMPluginFactory.java:43)
    at org.codehaus.groovy.reflection.GroovyClassValueFactory.<clinit>(GroovyClassValueFactory.java:35)
    at org.codehaus.groovy.reflection.ClassInfo.<clinit>(ClassInfo.java:109)
    at org.codehaus.groovy.reflection.ReflectionCache.getCachedClass(ReflectionCache.java:95)
    at org.codehaus.groovy.reflection.ReflectionCache.<clinit>(ReflectionCache.java:39)
    at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.registerMethods(MetaClassRegistryImpl.java:209)
    at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:107)
    at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:85)
    at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:36)
    at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:86)
    at groovy.lang.GroovyObjectSupport.getDefaultMetaClass(GroovyObjectSupport.java:59)
    at groovy.lang.GroovyObjectSupport.<init>(GroovyObjectSupport.java:32)
    at org.gradle.api.internal.plugins.DefaultExtraPropertiesExtension.<init>(DefaultExtraPropertiesExtension.java:29)
    at org.gradle.api.internal.plugins.DefaultConvention.<init>(DefaultConvention.java:47)
    at org.gradle.api.internal.ExtensibleDynamicObject.<init>(ExtensibleDynamicObject.java:58)
    at org.gradle.initialization.DefaultSettings.<init>(DefaultSettings.java:93)
    at org.gradle.initialization.DefaultSettings_Decorated.<init>(Unknown Source)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    at org.gradle.internal.reflect.DirectInstantiator.newInstance(DirectInstantiator.java:51)
    at org.gradle.api.internal.ClassGeneratorBackedInstantiator.newInstance(ClassGeneratorBackedInstantiator.java:36)
    at org.gradle.initialization.SettingsFactory.createSettings(SettingsFactory.java:52)
    at org.gradle.initialization.ScriptEvaluatingSettingsProcessor.process(ScriptEvaluatingSettingsProcessor.java:56)
    at org.gradle.initialization.PropertiesLoadingSettingsProcessor.process(PropertiesLoadingSettingsProcessor.java:37)
    at org.gradle.initialization.SettingsEvaluatedCallbackFiringSettingsProcessor.process(SettingsEvaluatedCallbackFiringSettingsProcessor.java:34)
    at org.gradle.initialization.RootBuildCacheControllerSettingsProcessor.process(RootBuildCacheControllerSettingsProcessor.java:36)
    at org.gradle.initialization.BuildOperationSettingsProcessor$2.call(BuildOperationSettingsProcessor.java:48)

Android ビルド時に上記のエラーが発生する現象に遭遇した

Preferences を開いて「External Tools」の
「Android JDK Installed with Unity (recommended)」のチェックを一度オフにしてから
オンにし直して Android ビルドしたら正常にビルドが完了した