buck2 icon indicating copy to clipboard operation
buck2 copied to clipboard

Android Kotlin build fails: cpython_archive select() missing default for cfg:no-san configuration

Open homeup-ai opened this issue 10 months ago • 1 comments

Description

When building an Android Kotlin app using system_demo_toolchains(), the build fails because the cpython_archive target's sha256 attribute uses a select() without a default value, and the Android build configuration (cfg:no-san) sets CPU to x86_32 which doesn't match any of the available options.

Environment

  • Buck2 version: 2026-01-14-27ba7841b62d77ea13dbee5f69fa5999cfe18a90
  • OS: macOS (Darwin 25.1.0, Apple Silicon arm64)
  • Java: OpenJDK 17 via Homebrew

Steps to Reproduce

  1. Create a new Buck2 project with buck2 init
  2. Add an android_binary target with Kotlin source files using android_library with language = "KOTLIN"
  3. Run buck2 build //path/to:android_target

Error Message

BUILD FAILED
Error running analysis for `root//app:app_debug (prelude//platforms:default#...)`

Caused by:
    0: Error in configured node dependency, dependency chain follows:
              root//app:app_debug
           -> root//app:core (cfg:no-san#...)
           -> toolchains//:kotlin_for_android
           -> prelude//toolchains/android/.../kotlincd_tool
           -> toolchains//:java_bootstrap
           -> prelude//java/tools:fat_jar
           -> toolchains//:python_bootstrap
           -> toolchains//:cpython
           -> toolchains//:cpython_archive
       
    1: configuring attr `sha256`
    2: None of 2 conditions matched configuration `cfg:no-san#...` and no default was set:
         prelude//cpu:arm64
         prelude//cpu:x86_64

Analysis

The cpython_archive target in system_demo_toolchains() uses a nested select based on OS and CPU:

sha256 = select({
    "prelude//os:macos": select({
        "prelude//cpu:arm64": "...",
        "prelude//cpu:x86_64": "...",
    }),
    ...
})

When building for Android, the configuration cfg:no-san is created with:

  • prelude//cpu/constraints:x86_32 (Android target architecture)
  • prelude//os/constraints:macos (host OS)

The select for CPU only has arm64 and x86_64 options, so x86_32 doesn't match, causing the failure.

Expected Behavior

The cpython_archive should use the host execution platform's CPU (arm64 on Apple Silicon) rather than the target platform's CPU (x86_32 for Android), since Python is needed for build tooling, not for running on the Android device.

Suggested Fix

Either:

  1. Add a default value to the sha256 select that falls back to the host platform
  2. Use exec_compatible_with or execution platform constraints to ensure cpython_archive resolves based on the execution platform, not the target platform
  3. Document that system_demo_toolchains() doesn't support Android Kotlin builds

Workaround

Currently, building Java-only Android resources works:

buck2 build //app:res  # Works
buck2 build //app:app_debug  # Fails (Kotlin)

homeup-ai avatar Jan 16 '26 02:01 homeup-ai

I encountered the same problem. I don't understand how to build the simplest Kotlin Android app, and there's not a single working example. I tried specifying cpu_filters:

android_binary(  
    name = 'simple-app',  
    manifest = 'app/src/main/AndroidManifest.xml',  
    keystore = ':debug_keystore',  
    package_type = 'debug',  
    cpu_filters = ["arm64", "x86_64"],  
    deps = [  
        ':simple-lib',  
    ],  
)

And got a new error:

BUILD FAILED
Error running analysis for `root//:simple-app (prelude//platforms:default#b42aeba648b8c415)`

Caused by:
    0: Error running analysis for `root//:simple-lib (cfg:<empty>#5af357d0afac1d79)`
    1: Attribute requires a dep that provides `TestListingInfo`, but it was not found on `toolchains//:android (cfg:<empty>#5af357d0afac1d79)`. Found these providers: DefaultInfo, AndroidPlatformInfo, AndroidToolchainInfo

IndiTheo avatar Apr 22 '26 20:04 IndiTheo