Shubham Panchal
Shubham Panchal

Reputation: 142

Bazel Auto-Configuration Error: Unable to Locate Java Binary in Existing Android Studio Project

I am new to Bazel and trying to open an existing project in my Android Studio, but I keep encountering this error. Despite setting up JAVA_HOME and PATH variables, as well as attempting various troubleshooting steps like clearing caches and restarting Android Studio, the issue persists trying too much solutions but getting same exact error all times. Also tried to get help from AI but still no solution working.

Error :

load("@rules_java//toolchains:fail_rule.bzl", "fail_rule")
fail_rule(
   name = "jdk",
   header = "Auto-Configuration Error:",
   message = ("Cannot find Java binary bin/java.exe in C:/users/userx/_bazel_userx/k7j5o23l/external/rules_java~~toolchains~local_jdk/nosystemjdk; either correct your JAVA_HOME, " +
          "PATH or specify Java from remote repository (e.g. " +
          "--java_runtime_version=remotejdk_11)")
)
config_setting(
   name = "localjdk_setting",
   values = {"java_runtime_version": "local_jdk"},
   visibility = ["//visibility:private"],
)
toolchain(
   name = "runtime_toolchain_definition",
   target_settings = [":localjdk_setting"],
   toolchain_type = "@bazel_tools//tools/jdk:runtime_toolchain_type",
   toolchain = ":jdk",
)
toolchain(
   name = "bootstrap_runtime_toolchain_definition",
   target_settings = [":localjdk_setting"],
   toolchain_type = "@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type",
   toolchain = ":jdk",
)

Current environment :

mvn -version

Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae)
Maven home: C:\ProgramFilesCustom\apache-maven-3.9.6
Java version: 22.0.1, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-22
Default locale: en_IN, platform encoding: UTF-8
OS name: "windows 11", version: "10.0", arch: "amd64", family: "windows"

bazel version

WARNING: Invoking Bazel in batch mode since it is not invoked from within a workspace (below a directory having a WORKSPACE file).
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
Build label: 7.1.1
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Thu Mar 21 18:11:32 2024 (1711044692)
Build timestamp: 1711044692
Build timestamp as int: 1711044692

Solution tried:

  1. Set JAVA_HOME and Java Path in User variables.
  2. Also tried to set JAVA_HOME and Java Path in System Variables.
  3. Restarted Android Studio with invalid caches.
  4. Also tried: bazel clean --expunge.

Still same error.

Upvotes: 0

Views: 81

Answers (0)

Related Questions