My JAVA_HOME is set to location "C:\Program Files\Android\Android Studio\jbr", I have done this configuration on Windows. It's set as a system variable only, but Android Studio gives me this error on Android build:
ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk-23
I have deleted the android folder, reinstalled Android Studio, did a project search for the string "C:\Program Files", but nothing worked. This error happens in Android Studio and VSCode.
Output from flutter run:
Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
Running Gradle task 'assembleDebug'...
ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk-23
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
Running Gradle task 'assembleDebug'... 28ms
Error: Gradle task assembleDebug failed with exit code 1
Output from starting Android Studio from the cmd:
2024-12-30 09:16:08,463 [ 177] WARN - #c.i.s.ComponentManagerImpl - `preload=TRUE` must be used only for core services (service=org.jetbrains.android.AndroidPlugin, plugin=org.jetbrains.android)
2024-12-30 09:16:08,480 [ 194] WARN - c.i.o.u.r.overrides - Conflicting registry key definition for key kotlin.mpp.tests.force.gradle: it was defined by plugin org.jetbrains.kotlin but redefined by plugin org.jetbrains.kotlin. Consider adding overrides="true" for one of the plugins, see the documentation for com.intellij.openapi.util.registry.RegistryKeyBean.overrides for more details.
2024-12-30 09:16:08,480 [ 194] WARN - c.i.o.u.r.overrides - Conflicting registry key definition for key unknown.sdk: it was defined by plugin com.intellij but redefined by plugin org.jetbrains.android. Consider adding overrides="true" for one of the plugins, see the documentation for com.intellij.openapi.util.registry.RegistryKeyBean.overrides for more details.
2024-12-30 09:16:08,481 [ 195] WARN - c.i.o.u.r.overrides - Conflicting registry key definition for key unknown.sdk.auto: it was defined by plugin com.intellij but redefined by plugin org.jetbrains.android. Consider adding overrides="true" for one of the plugins, see the documentation for com.intellij.openapi.util.registry.RegistryKeyBean.overrides for more details.
2024-12-30 09:16:08,481 [ 195] WARN - c.i.o.u.r.overrides - Conflicting registry key definition for key unknown.sdk.modal.jps: it was defined by plugin com.intellij but redefined by plugin org.jetbrains.android. Consider adding overrides="true" for one of the plugins, see the documentation for com.intellij.openapi.util.registry.RegistryKeyBean.overrides for more details.
2024-12-30 09:16:08,481 [ 195] WARN - c.i.o.u.r.overrides - Conflicting registry key definition for key unknown.sdk.show.editor.actions: it was defined by plugin com.intellij but redefined by plugin org.jetbrains.android. Consider adding overrides="true" for one of the plugins, see the documentation for com.intellij.openapi.util.registry.RegistryKeyBean.overrides for more details.
2024-12-30 09:16:08,481 [ 195] WARN - c.i.o.u.r.overrides - Conflicting registry key definition for key gradle.phased.sync.enabled: it was defined by plugin com.intellij.gradle but redefined by plugin org.jetbrains.android. Consider adding overrides="true" for one of the plugins, see the documentation for com.intellij.openapi.util.registry.RegistryKeyBean.overrides for more details.
2024-12-30 09:16:09,033 [ 747] WARN - #c.i.w.i.i.WorkspaceModelCacheSerializer - Could not deserialize cache from C:\Users\leandro\AppData\Local\Google\AndroidStudio2024.2\global-model-cache\cache.data
com.esotericsoftware.kryo.kryo5.KryoException: Buffer too small: capacity: 0, required: 1
at com.esotericsoftware.kryo.kryo5.io.ByteBufferInput.require(ByteBufferInput.java:166)
at com.esotericsoftware.kryo.kryo5.io.ByteBufferInput.readVarIntFlag(ByteBufferInput.java:444)
at com.esotericsoftware.kryo.kryo5.io.ByteBufferInput.readString(ByteBufferInput.java:709)
at com.intellij.platform.workspace.storage.impl.serialization.EntityStorageSerializerImpl.checkCacheVersionIdentical(EntityStorageSerializerImpl.kt:227)
at com.intellij.platform.workspace.storage.impl.serialization.EntityStorageSerializerImpl.deserializeCache-IoAF18A(EntityStorageSerializerImpl.kt:145)
at com.intellij.workspaceModel.ide.impl.WorkspaceModelCacheSerializer.loadCacheFromFile$intellij_platform_ide_impl(WorkspaceModelCacheSerializer.kt:55)
at com.intellij.workspaceModel.ide.impl.GlobalWorkspaceModelCacheImpl.loadCache(GlobalWorkspaceModelCacheImpl.kt:85)
at com.intellij.workspaceModel.ide.impl.GlobalWorkspaceModel.<init>(GlobalWorkspaceModel.kt:76)
at com.intellij.platform.instanceContainer.instantiation.InstantiateKt$instantiate$2.invoke(instantiate.kt:46)
at com.intellij.platform.instanceContainer.instantiation.InstantiateKt$instantiate$2.invoke(instantiate.kt:43)
at com.intellij.platform.instanceContainer.instantiation.InstantiateKt$instantiate$6$1.invoke(instantiate.kt:310)
at com.intellij.platform.instanceContainer.instantiation.InstantiateKt.withStoredTemporaryContext(instantiate.kt:327)
at com.intellij.platform.instanceContainer.instantiation.InstantiateKt.instantiate(instantiate.kt:309)
at com.intellij.platform.instanceContainer.instantiation.InstantiateKt.instantiate(instantiate.kt:43)
at com.intellij.serviceContainer.LightServiceInstanceSupport$LightServiceInstanceInitializer.createInstance(LightServiceInstanceSupport.kt:47)
at com.intellij.platform.instanceContainer.internal.LazyInstanceHolder$initialize$1$1.invokeSuspend(LazyInstanceHolder.kt:162)
at com.intellij.platform.instanceContainer.internal.LazyInstanceHolder$initialize$1$1.invoke(LazyInstanceHolder.kt)
at com.intellij.platform.instanceContainer.internal.LazyInstanceHolder$initialize$1$1.invoke(LazyInstanceHolder.kt)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:62)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:163)
at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
at com.intellij.platform.instanceContainer.internal.LazyInstanceHolder$initialize$1.invokeSuspend(LazyInstanceHolder.kt:160)
at com.intellij.platform.instanceContainer.internal.LazyInstanceHolder$initialize$1.invoke(LazyInstanceHolder.kt)
at com.intellij.platform.instanceContainer.internal.LazyInstanceHolder$initialize$1.invoke(LazyInstanceHolder.kt)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startCoroutineUndispatched(Undispatched.kt:27)
at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:90)
at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:123)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:52)
at kotlinx.coroutines.BuildersKt.launch(Unknown Source)
at com.intellij.platform.instanceContainer.internal.LazyInstanceHolder.initialize(LazyInstanceHolder.kt:145)
at com.intellij.platform.instanceContainer.internal.LazyInstanceHolder.access$initialize(LazyInstanceHolder.kt:13)
at com.intellij.platform.instanceContainer.internal.LazyInstanceHolder.tryInitialize(LazyInstanceHolder.kt:135)
at com.intellij.platform.instanceContainer.internal.LazyInstanceHolder.getInstance(LazyInstanceHolder.kt:95)
at com.intellij.platform.instanceContainer.internal.LazyInstanceHolder.getInstance$suspendImpl(LazyInstanceHolder.kt:83)
at com.intellij.platform.instanceContainer.internal.LazyInstanceHolder.getInstance(LazyInstanceHolder.kt)
at com.intellij.platform.instanceContainer.internal.InstanceContainerImpl.instance(InstanceContainerImpl.kt:68)
at com.intellij.serviceContainer.ComponentManagerImpl.getServiceAsync(ComponentManagerImpl.kt:694)
at com.intellij.workspaceModel.ide.impl.legacyBridge.module.ModuleBridgeLoaderService$execute$2.invokeSuspend(ModuleBridgeLoaderService.kt:163)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.UndispatchedCoroutine.afterResume(CoroutineContext.kt:277)
at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:99)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
at kotlinx.coroutines.UndispatchedCoroutine.afterResume(CoroutineContext.kt:277)
at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:99)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:608)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:873)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:763)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:750)
2024-12-30 09:16:09,189 [ 903] WARN - #c.i.s.ComponentManagerImpl - `preload=NOT_HEADLESS` must be used only for core services (service=org.jetbrains.kotlin.idea.search.refIndex.KotlinCompilerReferenceIndexService, plugin=org.jetbrains.kotlin)
2024-12-30 09:16:09,372 [ 1086] WARN - #c.i.u.j.JBCefApp - JCefAppConfig.class is not from a JBR module, url: jar:file:/C:/Program%20Files/Android/Android%20Studio/lib/lib.jar!/com/jetbrains/cef/JCefAppConfig.class (Use JBR bundled with the IDE)
2024-12-30 09:16:09,926 [ 1640] WARN - #com.android.sdklib.internal.avd.AvdManager - Observed package id 'emulator' in inconsistent location 'C:\Users\leandro\AppData\Local\Android\Sdk\emulator.backup' (Expected 'C:\Users\leandro\AppData\Local\Android\Sdk\emulator')
2024-12-30 09:16:09,926 [ 1640] WARN - #com.android.sdklib.internal.avd.AvdManager - Already observed package id 'emulator' in 'C:\Users\leandro\AppData\Local\Android\Sdk\emulator'. Skipping duplicate at 'C:\Users\leandro\AppData\Local\Android\Sdk\emulator.backup'
2024-12-30 09:16:10,663 [ 2377] WARN - #com.android.tools.ndk.HotfixForOCInitialTablesBuildingActivity - Overriding OCInitialTablesBuildingActivity with HotfixForOCInitialTablesBuildingActivity
2024-12-30 09:16:10,764 [ 2478] WARN - #c.i.i.s.i.StartupManagerImpl - Migrate io.flutter.FlutterInitializer to ProjectActivity [Plugin: io.flutter]
com.intellij.diagnostic.PluginException: Migrate io.flutter.FlutterInitializer to ProjectActivity [Plugin: io.flutter]
at com.intellij.ide.startup.impl.StartupManagerImpl.runPostStartupActivities(StartupManagerImpl.kt:296)
at com.intellij.ide.startup.impl.StartupManagerImpl.access$runPostStartupActivities(StartupManagerImpl.kt:69)
at com.intellij.ide.startup.impl.StartupManagerImpl$runPostStartupActivities$3$2.invokeSuspend(StartupManagerImpl.kt:193)
at com.intellij.ide.startup.impl.StartupManagerImpl$runPostStartupActivities$3$2.invoke(StartupManagerImpl.kt)
at com.intellij.ide.startup.impl.StartupManagerImpl$runPostStartupActivities$3$2.invoke(StartupManagerImpl.kt)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:62)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:163)
at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
at com.intellij.ide.startup.impl.StartupManagerImpl$runPostStartupActivities$3.invokeSuspend(StartupManagerImpl.kt:192)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:608)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:873)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:763)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:750)
2024-12-30 09:16:10,766 [ 2480] WARN - #c.i.i.s.i.StartupManagerImpl - Migrate io.flutter.FlutterStudioStartupActivity to ProjectActivity [Plugin: io.flutter]
com.intellij.diagnostic.PluginException: Migrate io.flutter.FlutterStudioStartupActivity to ProjectActivity [Plugin: io.flutter]
at com.intellij.ide.startup.impl.StartupManagerImpl.runPostStartupActivities(StartupManagerImpl.kt:296)
at com.intellij.ide.startup.impl.StartupManagerImpl.access$runPostStartupActivities(StartupManagerImpl.kt:69)
at com.intellij.ide.startup.impl.StartupManagerImpl$runPostStartupActivities$3$2.invokeSuspend(StartupManagerImpl.kt:193)
at com.intellij.ide.startup.impl.StartupManagerImpl$runPostStartupActivities$3$2.invoke(StartupManagerImpl.kt)
at com.intellij.ide.startup.impl.StartupManagerImpl$runPostStartupActivities$3$2.invoke(StartupManagerImpl.kt)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:62)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:163)
at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
at com.intellij.ide.startup.impl.StartupManagerImpl$runPostStartupActivities$3.invokeSuspend(StartupManagerImpl.kt:192)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:608)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:873)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:763)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:750)
2024-12-30 09:16:16,736 [ 8450] WARN - Emulator: Pixel 9 Pro API 35 - *** Basic token auth should only be used by android-studio ***
2024-12-30 09:16:17,145 [ 8859] WARN - #c.i.o.a.ActionStub - ActionGroup should be registered using <group> tag: id="android.device.liveedit.status" class="com.android.tools.idea.editors.liveedit.ui.LiveEditNotificationGroup"
2024-12-30 09:16:28,503 [ 20217] WARN - #io.flutter.run.FlutterPositionMapper - Failed to get execution context from analysis server. Some breakpoints may not work.
2024-12-30 09:16:44,894 [ 36608] WARN - #c.i.u.x.Binding - No accessors for org.jetbrains.kotlin.cli.common.arguments.InternalArgument. This means that state class cannot be serialized properly. Please see https://jb.gg/ij-psoc
2024-12-30 09:16:49,099 [ 40813] WARN - #com.android.ddmlib - * daemon not running; starting now at tcp:5037
2024-12-30 09:16:49,113 [ 40827] WARN - #com.android.ddmlib - * daemon started successfully
Output from flutter doctor:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.27.1, on Microsoft Windows [Version 10.0.22631.4602], locale pt-BR)
[✓] Windows Version (Installed version of Windows is version 10 or higher)
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
✗ Cannot execute C:\Program Files\Java\jdk-23\bin\java to determine the version
[✓] Chrome - develop for the web
[✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.12.1)
[✓] Android Studio (version 2024.2)
[✓] VS Code, 64-bit edition (version 1.96.2)
[✓] Connected device (3 available)
[✓] Network resources
! Doctor found issues in 1 category.
Could you guys help me? Thank you!
Turns out I just needed to do:
flutter config --jdk-dir "C:\Program Files\Android\Android Studio\jbr"