Crate android_build

Source
Expand description

Supports Android-specific Java build and run tasks in Rust projects from a Cargo build script.

§Tools exposed by this crate

§Environment variables in use

  • ANDROID_HOME or ANDROID_SDK_ROOT: path to the Android SDK directory.
  • ANDROID_BUILD_TOOLS_VERSION: the version of the Android build tools.
    • Examples: 33.0.1, 34.0.0-rc2.
    • This must be fully specified all in one string.
  • ANDROID_PLATFORM, ANDROID_API_LEVEL, or ANDROID_SDK_VERSION: the platform version string (aka API level, SDK version) being targeted for compilation.
    • All three of these environment variables are treated identically.
    • Examples: 34, android-34, android-33, 33.
    • If an SDK extension must be specified, use the full string with the android prefix like so: android-33-ext4.
    • This may or may not include the SDK extension level as a suffix (see ANDROID_SDK_EXTENSION below).
  • ANDROID_SDK_EXTENSION: the extension of the Android SDK.
    • To specify android-33-ext4, this can be set to -ext4, ext4, or just 4. All of these will be treated identically.
    • If ANDROID_PLATFORM/ANDROID_API_LEVEL/ANDROID_SDK_VERSION already includes an extension, then ANDROID_SDK_EXTENSION will be ignored.
  • ANDROID_D8_JAR: the path to the d8.jar file.
  • ANDROID_JAR: the path to the android.jar file.
  • JAVA_HOME: the Java SDK directory.
  • JAVA_SOURCE_VERSION: the Java version for source compatibility, which is passed to the --source javac option, e.g., 8 for Java 1.8, or 17 for Java 17.
  • JAVA_TARGET_VERSION: the Java version for target compatibility, which is passed to the --target javac option, e.g., 7 for Java 1.7, or 17 for Java 17.

§Acknowledgments

This crate simplifies some code found in other crates:

  • dirs-sys for the Windows-specific home directory lookup.
  • java-locator for finding the Java home directory on macOS, Linux, and Windows.
  • jerk for arguments that can be passed into java and javac commands.
  • i-slint-backend-android-activity for parsing javac version and finding the latest platform and build tools versions in the Android SDK installation.

Structs§

DebugInfo
Debug information to include in the output of a javac build.
Dexer
A builder for generating Android DEX bytecode by invoking d8 commands.
JavaBuild
A builder for a javac command that can be invoked.
JavaRun
A builder for a java command that can be invoked.

Constants§

ANDROID_API_LEVEL
ANDROID_BUILD_TOOLS_VERSION
ANDROID_D8_JAR
ANDROID_HOME
ANDROID_JAR
ANDROID_PLATFORM
ANDROID_SDK_EXTENSION
ANDROID_SDK_ROOT
ANDROID_SDK_VERSION
JAVA_HOME
JAVA_SOURCE_VERSION
JAVA_TARGET_VERSION

Traits§

PathExt
An extension trait for checking if a path exists.

Functions§

android_d8_jar
Returns the path to the d8.jar file for the given build tools version.
android_jar
Returns the path to the android.jar file for the given API level.
android_sdk
Returns the path to the Android SDK directory.
check_javac_version
Returns the major version number of the javac compiler.
java
Returns the path to the java executable by looking for $JAVA_HOME/bin/java.
java_home
Returns the JAVA_HOME path by attempting to discover it.
java_source_version
Returns the source version for compilation from environment variable JAVA_SOURCE_VERSION.
java_target_version
Returns the target version for compilation from environment variable JAVA_TARGET_VERSION.
javac
Returns the path to the javac compiler by looking for $JAVA_HOME/bin/javac.