Starting March 27, 2025, we recommend using android-latest-release
instead of aosp-main
to build and contribute to AOSP. For more information, see Changes to AOSP.
Use Trade Federation with Scripting Layer for Android
Stay organized with collections
Save and categorize content based on your preferences.
Scripting Layer for Android, SL4A, is an
automation toolset for calling Android APIs in a platform-independent manner.
It supports both remote automation via adb
and execution of scripts
from on-device via a series of lightweight translation layers.
The project is located at platform/external/sl4a.
Use
You can follow the SL4A README
to build and install it manually. And when running through Tradefed, you
can take advantage of some of the harness utilities to make use easier.
Download and install
You can start by reviewing
BT-discovery-sl4a.xml,
an example Tradefed configuration that uses two devices. The SL4A.apk
is
available in most device builds within their tests
folder.
The Tradefed example above automatically fetches the builds, flashes both
devices and installs SL4A.apk
on both devices. You can run it like so:
source build/envsetup.sh
lunch
make sl4a
tradefed.sh run google/example/BT-discovery-sl4a
Or once built:
./tradefed.sh run google/example/BT-discovery-sl4a
Write a test in Tradefed using SL4A
You can follow the test sample describe above:
Sl4aBluetoothDiscovery.java.
This gives a good example of the flow to use SL4A within a Tradefed test.
SL4A API documentation
The complete list of callbacks available through SL4A can be generated. From the
SL4A source directory, platform/external/sl4a/
, run this command:
python Docs/generate_api_reference_md.py
In the Docs directory there will be an ApiReference.md
file that contains
the RPC functions available in SL4A, as well as documentation for the RPC
functions.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-06-18 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-18 UTC."],[],[],null,["# Use Trade Federation with Scripting Layer for Android\n\nScripting Layer for Android, SL4A, is an\nautomation toolset for calling Android APIs in a platform-independent manner.\nIt supports both remote automation via `adb` and execution of scripts\nfrom on-device via a series of lightweight translation layers.\n\nThe project is located at [platform/external/sl4a](https://android.googlesource.com/platform/external/sl4a/).\n\nUse\n---\n\nYou can follow the [SL4A README](https://android.googlesource.com/platform/external/sl4a/+/refs/heads/android16-release/README.md)\nto build and install it manually. And when running through Tradefed, you\ncan take advantage of some of the harness utilities to make use easier.\n\n### Download and install\n\nYou can start by reviewing\n[BT-discovery-sl4a.xml](https://android.googlesource.com/platform/tools/tradefederation/contrib/+/refs/heads/android16-release/res/config/google/example/BT-discovery-sl4a.xml),\nan example Tradefed configuration that uses two devices. The `SL4A.apk` is\navailable in most device builds within their `tests` folder.\n\nThe Tradefed example above automatically fetches the builds, flashes both\ndevices and installs `SL4A.apk` on both devices. You can run it like so: \n\n source build/envsetup.sh\n lunch\n make sl4a\n tradefed.sh run google/example/BT-discovery-sl4a\n\nOr once built: \n\n ./tradefed.sh run google/example/BT-discovery-sl4a\n\n### Write a test in Tradefed using SL4A\n\nYou can follow the test sample describe above:\n[Sl4aBluetoothDiscovery.java](https://android.googlesource.com/platform/tools/tradefederation/contrib/+/refs/heads/android16-release/src/com/android/tradefed/Sl4aBluetoothDiscovery.java).\nThis gives a good example of the flow to use SL4A within a Tradefed test.\n\n### SL4A API documentation\n\nThe complete list of callbacks available through SL4A can be generated. From the\nSL4A source directory, `platform/external/sl4a/`, run this command: \n\n python Docs/generate_api_reference_md.py\n\nIn the Docs directory there will be an `ApiReference.md` file that contains\nthe RPC functions available in SL4A, as well as documentation for the RPC\nfunctions."]]