Skip to content

[ASWB] [Android] Kotlin source files in src/main/kotlin are not recognized as a source root #27935

@phoenixwxy

Description

@phoenixwxy

Description of the bug:

Bug Description
The Android Studio Bazel Plugin (ASWB) does not correctly identify src/main/kotlin as a source directory when it is used alongside a separate src/main/java directory within the same Bazel target.

While the project builds successfully using Bazel (from the command line or the IDE's "Build" button), the IDE itself fails to index the Kotlin files correctly. This leads to:

Failed Symbol Resolution: Code in .kt files is highlighted in red, with errors like "Unresolved reference".
No Code Completion: Standard IDE features for Kotlin do not work.
Broken Navigation: "Go to Declaration," "Find Usages," and other navigation features do not work for symbols defined in the kotlin/ directory.
The expected behavior is for the IDE to recognize both src/main/java and src/main/kotlin as source roots, enabling full IDE support for both Java and Kotlin files in the project, which is standard behavior in Gradle-based Android projects.

Steps to Reproduce
1.Create an Android project with the following directory structure, separating Java and Kotlin sources:

my_android_app/
└── src
    └── main
        ├── AndroidManifest.xml
        ├── BUILD.bazel
        ├── java/com/my/package/MyJavaClass.java
        └── kotlin/com/my/package/MyKotlinActivity.kt

2.In BUILD.bazel, define an android_binary or android_library target that includes both source directories in its srcs attribute, for example: srcs = glob(["java//*.java", "kotlin//*.kt"]).
3.Import the project into Android Studio using the Bazel plugin ("Import Bazel Project").
4.After the sync completes, open the MyKotlinActivity.kt file.
5.Observe that the IDE cannot resolve symbols, even basic ones like AppCompatActivity.
Minimal, Reproducible BUILD.bazel Example
Here is a sample BUILD.bazel file that demonstrates the issue:

# //apps/Android/bazel_demo/src/main/BUILD.bazel
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")
# This library will contain the Kotlin code
kt_android_library(
    name = "lib_kt",
    srcs = glob(["kotlin/**/*.kt"]),
    custom_package = "com.phoenix.bazel_demo",
    manifest = "AndroidManifest.xml",
    resource_files = glob(["res/**"]),
    deps = [
        # Common Android dependencies
    ],
)
# A final binary that depends on the Kotlin library
# (A single android_binary with mixed sources also shows the issue)
android_binary(
    name = "app",
    srcs = glob(["java/**/*.java"]), # Assuming MainActivity is Java
    custom_package = "com.phoenix.bazel_demo",
    manifest = "AndroidManifest.xml",
    deps = [
        ":lib_kt",
    ],
)

Version Information
Android Studio Version:

Android Studio Otter 2 Feature Drop | 2025.2.2
Build #AI-252.27397.103.2522.14514259, built on December 1, 2025
Runtime version: 21.0.8+-14196175-b1038.72 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 6.12.43+deb13-amd64
Current Desktop: GNOME

Android Studio Bazel Plugin Version: com.google.idea.bazel.aswb (14514259)

Bazel version: bazel 8.4.2
rules_android version:0.6.6
rules_kotlin version:2.2.0

Which category does this issue belong to?

Android

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

No response

Which operating system are you running Bazel on?

Linux User 6.12.43+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.43-1 (2025-08-27) x86_64 GNU/Linux

What is the output of bazel info release?

release 8.4.2

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?


If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions