Kể từ ngày 27 tháng 3 năm 2025, bạn nên sử dụng android-latest-release
thay vì aosp-main
để xây dựng và đóng góp cho AOSP. Để biết thêm thông tin, hãy xem phần Thay đổi đối với AOSP.
Sử dụng Trade Federation với Lớp tập lệnh cho Android
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Lớp tập lệnh cho Android (SL4A) là một bộ công cụ tự động hoá để gọi các API Android theo cách độc lập với nền tảng.
API này hỗ trợ cả tính năng tự động hoá từ xa thông qua adb
và thực thi tập lệnh từ trên thiết bị thông qua một loạt lớp bản dịch nhẹ.
Dự án nằm ở platform/external/sl4a.
Mục đích sử dụng
Bạn có thể làm theo README về SL4A để tạo và cài đặt theo cách thủ công. Và khi chạy thông qua Tradefed, bạn có thể tận dụng một số tiện ích của dây nịt để sử dụng dễ dàng hơn.
Tải xuống và cài đặt
Bạn có thể bắt đầu bằng cách xem lại BT-discovery-sl4a.xml, một cấu hình Tradefed mẫu sử dụng hai thiết bị. SL4A.apk
có sẵn trong hầu hết các bản dựng thiết bị trong thư mục tests
.
Ví dụ về Tradefed ở trên sẽ tự động tìm nạp các bản dựng, cài đặt ROM cho cả hai thiết bị và cài đặt SL4A.apk
trên cả hai thiết bị. Bạn có thể chạy như sau:
source build/envsetup.sh
lunch
make sl4a
tradefed.sh run google/example/BT-discovery-sl4a
Hoặc sau khi tạo:
./tradefed.sh run google/example/BT-discovery-sl4a
Viết mã kiểm thử trong Tradefed bằng SL4A
Bạn có thể làm theo mẫu kiểm thử được mô tả ở trên: Sl4aBluetoothDiscovery.java.
Đây là ví dụ điển hình về quy trình sử dụng SL4A trong kiểm thử Tradefed.
Tài liệu về API SL4A
Bạn có thể tạo danh sách đầy đủ các lệnh gọi lại có sẵn thông qua SL4A. Từ thư mục nguồn SL4A, platform/external/sl4a/
, hãy chạy lệnh sau:
python Docs/generate_api_reference_md.py
Trong thư mục Tài liệu, sẽ có một tệp ApiReference.md
chứa các hàm RPC có trong SL4A, cũng như tài liệu cho các hàm RPC.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 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."]]