android_library

Android library target.

Description#

Compiles Android Java and Kotlin sources with optional resources into a classes jar, a static resource package, and an AAR. Downstream Android targets consume the emitted jars, resource package, and any transitive native library providers through the normal deps edge. Prefer a separate android_resource target for reusable resources and assets.

JAR and AAR packaging uses JDK 17 or newer jar with fixed entry timestamps, so filesystem modification times do not change archive contents.

Attributes#

AttributeTypeRequiredDefaultDescription
manifeststringnoAndroidManifest.xmlPackage-relative Android manifest
resource_fileslist<string>nofiles under resAndroid resource file glob patterns
resource_dirslist<string>no["res"]Resource roots passed to aapt2 compile
assetslist<string>no[]Android asset file glob patterns
asset_dirslist<string>no["assets"]Asset roots packaged into the AAR
assets_dirstringnoSingle package-relative asset root alias
namespacestringnoJava package for generated R classes
custom_packagestringnoAlias for generated R package
packagestringnoGenerated R package fallback
compile_sdkintnohighest installedAndroid SDK API level used for android.jar
min_sdk_versionintno23Minimum Android API level
target_sdk_versionintnocompile_sdkTarget Android API level
build_tools_versionstringnohighest installedAndroid SDK build-tools version
android_sdkstringnoenvAndroid SDK root, otherwise ANDROID_HOME or ANDROID_SDK_ROOT
java_language_levelstringno17Java source and target level passed to javac
javac_optslist<string>no[]Additional javac flags
javacoptslist<string>no[]Bazel-compatible alias for additional javac flags
kotlinc_optslist<string>no[]Additional kotlinc flags
neverlinkboolnofalseKeep this library on compile classpaths while omitting its runtime dependency closure from application classpaths

Tool override attrs are also available for javac, jar, java, java_home, kotlinc, kotlin_home, kotlin_stdlib, and aapt2.

Dependency Edges#

EdgeAcceptsDescription
depsandroid_library, android_resource, android_native_libraryAndroid libraries, resources, and native libraries consumed by this library

Providers#

The target emits android_library, android_archive, and java_library.

Capabilities#

CapabilityOutput groups
builddefault, jar, aar, resources

Source References#

Target kind discovery returns these external concepts for partial graph adoption:

Use them when the requested dependency slice needs one reusable Android library but does not need the complete source build.

Outputs#

OutputLocation
Classes jar.struo/out/<target>/<name>.jar
AAR.struo/out/<target>/<name>.aar
Static resource package.struo/out/<target>/resources.apk
R text symbols.struo/out/<target>/R.txt

Limitations#

The target supports Java sources, Kotlin sources, Android resources, assets, Android Archive packaging, Android resource dependencies, Android library dependencies, and transitive native-library propagation. Android Interface Definition Language, data binding, annotation processors, embedding native libraries directly into Android Archives, and ProGuard consumer rules are not implemented yet. Non-empty values for unsupported attributes fail validation instead of being ignored.

Example#

toml
[[target]] name = "Greeting" kind = "android_library" srcs = ["src/**/*.kt"] [target.attrs] namespace = "dev.struo.greeting" manifest = "AndroidManifest.xml"