規則
- android_binary
- aar_import
- android_library
- android_instrumentation_test
- android_local_test
- android_device
- android_ndk_repository
- android_sdk_repository
android_binary
查看規則來源android_binary(name, deps, srcs, assets, assets_dir, compatible_with, crunch_png, custom_package, debug_key, debug_signing_keys, debug_signing_lineage_file, densities, deprecation, dex_shards, dexopts, distribs, enable_data_binding, exec_compatible_with, exec_properties, features, incremental_dexing, instruments, javacopts, key_rotation_min_sdk, licenses, main_dex_list, main_dex_list_opts, main_dex_proguard_specs, manifest, manifest_values, multidex, nocompress_extensions, package_id, plugins, proguard_apply_dictionary, proguard_apply_mapping, proguard_generate_mapping, proguard_specs, resource_configuration_filters, resource_files, restricted_to, shrink_resources, tags, target_compatible_with, testonly, visibility)
產生 Android 應用程式套件檔案 (.apk)。
隱式輸出目標
name.apk
:使用偵錯金鑰簽署並採用 zipaligned 的 Android 應用程式套件檔案,可用來開發及偵錯您的應用程式。使用偵錯金鑰簽署時,您無法發布應用程式。name_unsigned.apk
:在發布公開版本前,您可以使用發布金鑰簽署上述檔案的未簽署版本。name_deploy.jar
:包含此目標轉換關閉的 Java 封存檔。部署 jar 包含類別載入器會搜尋的所有類別,從類別到結束搜尋到此目標的執行階段類別路徑。
name_proguard.jar
:包含在name_deploy.jar
上執行 ProGuard 的 Java 封存檔。只有在指定了 proguard_specs 屬性時,系統才會產生這項輸出內容。name_proguard.map
:在name_deploy.jar
上執行 ProGuard 的對應檔案結果。只有在指定了 proguard_specs 屬性且已設定 proguard_generate_mapping 或 shrink_resources 時,系統才會產生此輸出內容。
範例
您可以在 Bazel 來源樹狀結構的 examples/android
目錄中找到 Android 規則範例。
引數
屬性 | |
---|---|
name |
此目標的專屬名稱。 |
deps
|
android_library 、java_library 設有 android 限制,以及 cc_library 封裝或產生適用於 Android 目標平台的 .so 原生資料庫。 |
srcs
|
系統會編譯
|
assets
|
assets 目錄中所有檔案的 glob 。您也可以參照其他規則 (任何產生檔案的規則) 或在其他套件中匯出檔案,只要這些檔案位於對應套件的 assets_dir 目錄中即可。 |
assets_dir
|
assets 中檔案路徑的字串。assets 和 assets_dir 配對可說明套裝資產,不建議您提供這兩個屬性或完全不提供。 |
crunch_png
|
|
custom_package
|
|
debug_key
|
警告:請勿使用實際工作環境金鑰,金鑰必須妥善保護,且不會保留在原始碼樹狀結構中。 |
debug_signing_keys
|
警告:請勿使用實際工作環境金鑰,金鑰必須妥善保護,且不會保留在原始碼樹狀結構中。 |
debug_signing_lineage_file
|
警告:請勿使用實際工作環境金鑰,金鑰必須妥善保護,且不會保留在原始碼樹狀結構中。 |
densities
|
|
dex_shards
|
請注意,每個資料分割會在最終應用程式中產生至少一個 dex。因此,建議您不要為發布二進位檔設定 1 以上的值。 |
dexopts
|
|
enable_data_binding
|
如要建構具有資料繫結的 Android 應用程式,您還必須執行下列操作:
|
incremental_dexing
|
|
instruments
|
要檢測的 如果設定這個屬性,系統會將這個 |
javacopts
|
在全域編譯器選項之後,這些編譯器選項會傳送至 javac。 |
key_rotation_min_sdk
|
|
main_dex_list
|
android/support/multidex/MultiDex$V19.class android/support/multidex/MultiDex.class android/support/multidex/MultiDexApplication.class com/google/common/base/Objects.class必須搭配 multidex="manual_main_dex" 使用。
|
main_dex_list_opts
|
|
main_dex_proguard_specs
|
multidex 屬性設為 legacy ,才能使用這個屬性。
|
manifest
|
AndroidManifest.xml 。
如果已定義 resource_files 或資產,就必須定義這項屬性。
|
manifest_values
|
|
multidex
|
可能的值包括:
|
nocompress_extensions
|
|
package_id
|
詳情請參閱 AAPT2 的 |
plugins
|
java_plugin 。外掛程式產生的資源將包含在目標的結果 jar 中。 |
proguard_apply_dictionary
|
|
proguard_apply_mapping
|
proguard_generate_mapping 產生的對應檔案,可重複使用於將相同的對應項目套用至新版本。 |
proguard_generate_mapping
|
proguard_specs 時,系統才會產生對應檔案。這個檔案會列出原始和經過模糊處理的類別、方法和欄位名稱之間的對應。警告:如果使用這個屬性,Proguard 規格不得包含 |
proguard_specs
|
|
resource_configuration_filters
|
en_XA 和/或 ar_XB 虛擬語言代碼。
|
resource_files
|
res 目錄中所有檔案的 glob 。這裡也可以將產生的檔案 (來自 genrules) 參照。唯一的限制是,產生的輸出內容必須與任何其他內含資源檔案位於相同的「 res 」目錄。 |
shrink_resources
|
manifest 和 resource_files 屬性) 的規則,而且必須使用 ProGuard。其運作原理大致與 Gradle 資源縮減器 (https://developer.android.com/studio/build/shrink-code.html#shrink-resources) 相同。
主要差異:
name_files/resource_shrinker.log ,並詳細說明執行的分析及刪除作業。可能的值包括:
|
aar_import
查看規則來源aar_import(name, deps, data, aar, compatible_with, deprecation, distribs, exec_compatible_with, exec_properties, exports, features, licenses, restricted_to, srcjar, tags, target_compatible_with, testonly, visibility)
這項規則可讓 .aar
檔案做為 android_library
和 android_binary
規則的程式庫使用。
範例
aar_import( name = "google-vr-sdk", aar = "gvr-android-sdk/libraries/sdk-common-1.10.0.aar", ) android_binary( name = "app", manifest = "AndroidManifest.xml", srcs = glob(["**.java"]), deps = [":google-vr-sdk"], )
引數
屬性 | |
---|---|
name |
此目標的專屬名稱。 |
aar
|
.aar 檔案。
|
exports
|
|
srcjar
|
|
android_library
查看規則來源android_library(name, deps, srcs, data, assets, assets_dir, compatible_with, custom_package, deprecation, distribs, enable_data_binding, exec_compatible_with, exec_properties, exported_plugins, exports, exports_manifest, features, idl_import_root, idl_parcelables, idl_preprocessed, idl_srcs, javacopts, licenses, manifest, neverlink, plugins, proguard_specs, resource_files, restricted_to, tags, target_compatible_with, testonly, visibility)
這項規則會編譯來源,並將其封存成 .jar
檔案。Android 執行階段程式庫 android.jar
以隱含方式放入編譯類別路徑。
隱式輸出目標
libname.jar
:Java 封存檔。libname-src.jar
:包含來源的封存檔案 (「source jar」),name.aar
:包含此目標 Java 封存檔案和資源之 Android 的「aar」套件。但不含間接性營業情況。
範例
您可以在 Bazel 樹狀結構的 examples/android
目錄中找到 Android 規則範例。
以下範例說明如何設定 idl_import_root
。讓 //java/bazel/helloandroid/BUILD
包含:
android_library( name = "parcelable", srcs = ["MyParcelable.java"], # bazel.helloandroid.MyParcelable # MyParcelable.aidl will be used as import for other .aidl # files that depend on it, but will not be compiled. idl_parcelables = ["MyParcelable.aidl"] # bazel.helloandroid.MyParcelable # We don't need to specify idl_import_root since the aidl file # which declares bazel.helloandroid.MyParcelable # is present at java/bazel/helloandroid/MyParcelable.aidl # underneath a java root (java/). ) android_library( name = "foreign_parcelable", srcs = ["src/android/helloandroid/OtherParcelable.java"], # android.helloandroid.OtherParcelable idl_parcelables = [ "src/android/helloandroid/OtherParcelable.aidl" # android.helloandroid.OtherParcelable ], # We need to specify idl_import_root because the aidl file which # declares android.helloandroid.OtherParcelable is not positioned # at android/helloandroid/OtherParcelable.aidl under a normal java root. # Setting idl_import_root to "src" in //java/bazel/helloandroid # adds java/bazel/helloandroid/src to the list of roots # the aidl compiler will search for imported types. idl_import_root = "src", ) # Here, OtherInterface.aidl has an "import android.helloandroid.CallbackInterface;" statement. android_library( name = "foreign_interface", idl_srcs = [ "src/android/helloandroid/OtherInterface.aidl" # android.helloandroid.OtherInterface "src/android/helloandroid/CallbackInterface.aidl" # android.helloandroid.CallbackInterface ], # As above, idl_srcs which are not correctly positioned under a java root # must have idl_import_root set. Otherwise, OtherInterface (or any other # interface in a library which depends on this one) will not be able # to find CallbackInterface when it is imported. idl_import_root = "src", ) # MyParcelable.aidl is imported by MyInterface.aidl, so the generated # MyInterface.java requires MyParcelable.class at compile time. # Depending on :parcelable ensures that aidl compilation of MyInterface.aidl # specifies the correct import roots and can access MyParcelable.aidl, and # makes MyParcelable.class available to Java compilation of MyInterface.java # as usual. android_library( name = "idl", idl_srcs = ["MyInterface.aidl"], deps = [":parcelable"], ) # Here, ServiceParcelable uses and thus depends on ParcelableService, # when it's compiled, but ParcelableService also uses ServiceParcelable, # which creates a circular dependency. # As a result, these files must be compiled together, in the same android_library. android_library( name = "circular_dependencies", srcs = ["ServiceParcelable.java"], idl_srcs = ["ParcelableService.aidl"], idl_parcelables = ["ServiceParcelable.aidl"], )
引數
屬性 | |
---|---|
name |
此目標的專屬名稱。 |
deps
|
android_library 、java_library 設有 android 限制,以及 cc_library 封裝或產生適用於 Android 目標平台的 .so 原生資料庫。 |
srcs
|
.java 或 .srcjar 檔案清單。系統會編譯
如果省略 |
assets
|
assets 目錄中所有檔案的 glob 。您也可以參照其他規則 (任何產生檔案的規則) 或在其他套件中匯出檔案,只要這些檔案位於對應套件的 assets_dir 目錄中即可。 |
assets_dir
|
assets 中檔案路徑的字串。assets 和 assets_dir 配對可說明套裝資產,不建議您提供這兩個屬性或完全不提供。 |
custom_package
|
|
enable_data_binding
|
如要建構具有資料繫結的 Android 應用程式,您還必須執行下列操作:
|
exported_plugins
|
java_plugin 清單,例如註解處理工具。
指定的 |
exports
|
exports 屬性觸及的所有規則,都視為任何與 exports 目標直接相依的規則。
|
exports_manifest
|
android_binary 目標。系統不會匯出 uses-permissions 屬性。
|
idl_import_root
|
處理這個程式庫的 Idl 來源時,系統會使用這個路徑做為匯入根目錄。 如果指定 請參閱範例。 |
idl_parcelables
|
android_library 目標,無論是直接或透過傳輸關閉而使用,但不會翻譯為 Java 或編譯。請只納入與這個程式庫中 這些檔案必須妥善放置,方便編譯器找到。如要進一步瞭解這個含義,請參閱 idl_import_root 的說明。 |
idl_preprocessed
|
android_library 目標,無論是直接或透過傳輸關閉而使用,但不會翻譯為 Java 或編譯。請只納入與這個程式庫中 |
idl_srcs
|
srcs 的內容一起編譯。這些檔案將會做為匯入到該程式庫的任何 這些檔案必須妥善放置,方便編譯器找到。如要進一步瞭解這個含義,請參閱 idl_import_root 的說明。 |
javacopts
|
在全域編譯器選項之後,這些編譯器選項會傳送至 javac。 |
manifest
|
AndroidManifest.xml 。
如果已定義 resource_files 或資產,就必須定義這項屬性。
|
neverlink
|
.apk 建立時不會使用標示為 neverlink 的規則輸出內容。如果執行階段在執行期間會提供程式庫,這個函式就非常實用。 |
plugins
|
java_plugin 。外掛程式產生的資源將包含在目標的結果 jar 中。 |
proguard_specs
|
android_binary 目標。這裡包含的檔案只能使用冪等規則,也就是 -dontnote、-dontwarn、
nonosideimpact 和開頭為 -keep 的規則。其他選項只能在 android_binary 的 Proguard_specs 中顯示,確保非自動合併。 |
resource_files
|
res 目錄中所有檔案的 glob 。這裡也可以將產生的檔案 (來自 genrules) 參照。唯一的限制是,產生的輸出內容必須與任何其他內含資源檔案位於相同的「 res 」目錄。 |
android_instrumentation_test
查看規則來源android_instrumentation_test(name, data, args, compatible_with, deprecation, distribs, env, env_inherit, exec_compatible_with, exec_properties, features, flaky, licenses, local, restricted_to, shard_count, size, support_apks, tags, target_compatible_with, target_device, test_app, testonly, timeout, toolchains, visibility)
android_instrumentation_test
規則會執行 Android 檢測設備測試。系統會啟動模擬器、安裝經過測試的應用程式、測試應用程式和其他任何其他必要應用程式,並執行測試套件中定義的測試。
test_app 屬性指定包含測試的 android_binary
。這個 android_binary
則會透過其 instruments 屬性指定待測試的 android_binary
應用程式。
範例
# java/com/samples/hello_world/BUILD android_library( name = "hello_world_lib", srcs = ["Lib.java"], manifest = "LibraryManifest.xml", resource_files = glob(["res/**"]), ) # The app under test android_binary( name = "hello_world_app", manifest = "AndroidManifest.xml", deps = [":hello_world_lib"], )
# javatests/com/samples/hello_world/BUILD android_library( name = "hello_world_test_lib", srcs = ["Tests.java"], deps = [ "//java/com/samples/hello_world:hello_world_lib", ... # test dependencies such as Espresso and Mockito ], ) # The test app android_binary( name = "hello_world_test_app", instruments = "//java/com/samples/hello_world:hello_world_app", manifest = "AndroidManifest.xml", deps = [":hello_world_test_lib"], ) android_instrumentation_test( name = "hello_world_uiinstrumentation_tests", target_device = ":some_target_device", test_app = ":hello_world_test_app", )
引數
屬性 | |
---|---|
name |
此目標的專屬名稱。 |
support_apks
|
|
target_device
|
執行測試的 android_device。 如要在已執行中的模擬器或實體裝置上執行測試,請使用以下引數: |
test_app
|
android_binary 目標必須透過其 instruments 屬性指定要測試的目標。 |
android_local_test
查看規則來源android_local_test(name, deps, srcs, data, args, compatible_with, custom_package, densities, deprecation, enable_data_binding, env, env_inherit, exec_compatible_with, exec_properties, features, flaky, javacopts, jvm_flags, licenses, local, manifest, manifest_values, nocompress_extensions, plugins, resource_configuration_filters, resource_jars, resource_strip_prefix, restricted_to, runtime_deps, shard_count, size, stamp, tags, target_compatible_with, test_class, testonly, timeout, toolchains, use_launcher, visibility)
這項規則是用來在本機測試 android_library
規則 (而不是在裝置上)。可搭配 Android Robolectric 測試架構使用。如要進一步瞭解如何編寫 Robolectric 測試,請參閱 Android Robolectric 網站。
隱式輸出目標
name.jar
:測試的 Java 封存檔。name-src.jar
:包含來源的封存檔案 (「source jar」),name_deploy.jar
:適用於部署的 Java 部署封存 (僅在明確要求時建構)。
範例
如要將 Robolectric 與 android_local_test
搭配使用,請將 Robolectric 的存放區新增至 WORKSPACE
檔案:
http_archive( name = "robolectric", urls = ["https://github.com/robolectric/robolectric-bazel/archive/<COMMIT>.tar.gz"], strip_prefix = "robolectric-bazel-<COMMIT>", sha256 = "<HASH>", ) load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories") robolectric_repositories()這會提取 Robolectric 所需的
maven_jar
規則。然後,每個 android_local_test
規則都應依附於 @robolectric//bazel:robolectric
。請參閱下方範例。
android_local_test( name = "SampleTest", srcs = [ "SampleTest.java", ], manifest = "LibManifest.xml", deps = [ ":sample_test_lib", "@robolectric//bazel:android-all", ], ) android_library( name = "sample_test_lib", srcs = [ "Lib.java", ], resource_files = glob(["res/**"]), manifest = "AndroidManifest.xml", )
引數
屬性 | |
---|---|
name |
此目標的專屬名稱。 |
deps
|
|
srcs
|
系統會編譯
系統會忽略所有其他檔案,但前提是您的檔案類型至少須有上述一種檔案類型。否則會引發錯誤。
除非指定 |
custom_package
|
test_class 。 |
densities
|
|
enable_data_binding
|
|
javacopts
|
在全域編譯器選項之後,這些編譯器選項會傳送至 javac。 |
jvm_flags
|
Java 二進位檔的包裝函式指令碼包含 CLASSPATH 定義 (可尋找所有相依 jar 檔案),並叫用正確的 Java 解譯器。
包裝函式指令碼產生的指令列會包含主要類別的名稱和 請注意,這個屬性對 |
manifest
|
AndroidManifest.xml 。
如已定義 resource_files 或資產,或測試中的程式庫有任何資訊清單中有 minSdkVersion 標記,則必須定義。 |
manifest_values
|
applicationId 、versionCode 、versionName 、minSdkVersion 、targetSdkVersion 和 maxSdkVersion 也會覆寫資訊清單和 use-sdk 標記的對應屬性。packageName 將會遭到忽略,如果指定,則將在 applicationId 中設定,或是在資訊清單中設定套件。
使用資訊清單時,不一定要在規則中加入資訊清單。
|
nocompress_extensions
|
|
plugins
|
java_plugin 。程式庫也可能繼承使用 exported_plugins 的依附元件。外掛程式產生的資源會包含在這項規則產生的 jar 路徑中。 |
resource_configuration_filters
|
|
resource_jars
|
|
resource_strip_prefix
|
如果指定,這個路徑前置字串會從 |
runtime_deps
|
deps 一樣,會顯示在執行階段類別路徑上,但與編譯類別不同,而非在編譯時間類別路徑上。這裡只需要在執行階段所需的依附元件。依附元件分析工具應忽略同時出現在 runtime_deps 和 deps 的目標。 |
stamp
|
除非依附元件的依附元件有變更,否則「不會」重建時間戳記。 |
test_class
|
這個屬性會指定要在此測試執行的 Java 類別名稱。通常很少需要設定。如果省略這個引數,系統會使用名稱與此 |
use_launcher
|
如果這個屬性設為 false,系統會忽略此目標的 launcher 屬性和相關 |
android_device
查看規則來源android_device(name, cache, compatible_with, default_properties, deprecation, distribs, exec_compatible_with, exec_properties, features, horizontal_resolution, licenses, platform_apks, ram, restricted_to, screen_density, system_image, tags, target_compatible_with, testonly, vertical_resolution, visibility, vm_heap)
這項規則會建立具有指定規格的 Android 模擬器。您可以透過 bazel 執行指令或直接執行產生的指令碼來啟動這個模擬器。建議您依附現有的 android_device 規則,而非自行定義。
此規則是 --run_under 標記適合使用目標,以測試 bael 測試和 blaze 執行作業。這項工具會啟動模擬器,將測試/執行的目標複製到模擬器中,並對其進行測試或視情況執行。
如果基礎 system_image 是以 X86 為建構基礎,且最多針對 I686 CPU 架構進行最佳化處理,android_device
則支援建立 KVM 映像檔。如要使用 KVM,請將 tags = ['requires-kvm']
新增至 android_device
規則。
隱式輸出目標
name_images/userdata.dat
:包含啟動模擬器的映像檔檔案和快照name_images/emulator-meta-data.pb
:包含要傳遞給模擬器以啟動模擬器所需的必要資訊。
範例
以下範例說明如何使用 android_device。
//java/android/helloandroid/BUILD
包含
android_device( name = "nexus_s", cache = 32, default_properties = "nexus_s.properties", horizontal_resolution = 480, ram = 512, screen_density = 233, system_image = ":emulator_images_android_16_x86", vertical_resolution = 800, vm_heap = 32, ) filegroup( name = "emulator_images_android_16_x86", srcs = glob(["androidsdk/system-images/android-16/**"]), )
//java/android/helloandroid/nexus_s.properties
包含:
ro.product.brand=google ro.product.device=crespo ro.product.manufacturer=samsung ro.product.model=Nexus S ro.product.name=soju
這項規則會產生圖片和起始指令碼。您可以在本機執行模擬器,方法是執行 bazel run :nexus_s -- --action=start。這個指令碼會公開下列標記:
- --adb_port:用於公開 ADB 的通訊埠。如要向模擬器發出 ADB 指令,則您會發出 ADB 連線通訊埠。
- --emulator_port:開啟模擬器的 telnet 管理主控台的通訊埠。
- --enable_display:如果值為 true,系統會啟動模擬器 (預設值為 false)。
- --action:開始或終止。
- --apks_to_install:要安裝在模擬器上的 apk 清單。
引數
屬性 | |
---|---|
name |
此目標的專屬名稱。 |
cache
|
|
default_properties
|
|
horizontal_resolution
|
|
platform_apks
|
|
ram
|
|
screen_density
|
|
system_image
|
|
vertical_resolution
|
|
vm_heap
|
|
android_ndk_repository
查看規則來源android_ndk_repository(name, api_level, path, repo_mapping)
設定 Bazel 使用 Android NDK,以支援使用原生程式碼建構 Android 目標。
請注意,android_ndk_repository
的實作將由 Starlark 的實作取代。日後的 NDK 版本 (包括 25 以上版本) 將支援 android_ndk_repository
的 Starlark 版本。如需 Starlark 版本的版本資訊,請參閱 rules_android_ndk。
請注意,如果是針對 Android 進行建構,您也需要在 WORKSPACE
檔案中使用 android_sdk_repository
規則。
詳情請參閱搭配 Bazel 使用 Android NDK 的完整說明文件。
範例
android_ndk_repository( name = "androidndk", )
以上範例會從 $ANDROID_NDK_HOME
找出您的 Android NDK,並偵測其支援的最高 API 級別。
android_ndk_repository( name = "androidndk", path = "./android-ndk-r20", api_level = 24, )
以上範例將使用位於 ./android-ndk-r20
工作區內的 Android NDK。在編譯 JNI 程式碼時,會使用 API 級別 24 的程式庫。
cpufeatures
Android NDK 包含 cpufeatures 程式庫,可用於在執行階段偵測裝置的 CPU。以下範例說明如何搭配 Bazel 使用 cpufeatures。
# jni.cc #include "ndk/sources/android/cpufeatures/cpu-features.h" ...
# BUILD cc_library( name = "jni", srcs = ["jni.cc"], deps = ["@androidndk//:cpufeatures"], )
引數
屬性 | |
---|---|
name |
此目標的專屬名稱。 |
api_level
|
|
path
|
$ANDROID_NDK_HOME 環境變數。您可以在 Android 開發人員網站下載 Android NDK。 |
repo_mapping
|
舉例來說,項目 |
android_sdk_repository
查看規則來源android_sdk_repository(name, api_level, build_tools_version, path, repo_mapping)
設定 Bazel 使用本機 Android SDK 支援建構 Android 目標。
範例
設定 Bazel 適用的 Android SDK 時,您必須在WORKSPACE
檔案中置入名為「androidsdk」的 android_sdk_repository
規則,並將 $ANDROID_HOME
環境變數設為 Android SDK 的路徑。Bazel 預設使用 Android API 最高層級,並建構安裝在 Android SDK 中的工具版本。android_sdk_repository( name = "androidsdk", )
為了確保可重現的建構作業,您可以將 path
、api_level
和 build_tools_version
屬性設為特定值。如果 Android SDK 並未安裝指定的 API 級別或建構工具版本,版本將會失敗。
android_sdk_repository( name = "androidsdk", path = "./sdk", api_level = 19, build_tools_version = "25.0.0", )
以上範例也示範如何使用與工作區相關的 Android SDK 路徑。如果 Android SDK 是 Bazel 工作區的一部分 (例如,如果檢查到版本管控的話),這項功能就非常實用。
支援資料庫
支援資料庫在 Android SDK Manager 中稱為「Android 支援存放區」。
這是一組常見的 Android 程式庫 (例如 Support 和 AppCompat 程式庫),會封裝成本機 Maven 存放區。android_sdk_repository
會為這些程式庫產生 Bazel 目標,這些程式庫可用於 android_binary
和 android_library
目標的依附元件。
產生的目標名稱衍生自 Android 支援存放區中程式庫的 Maven 座標,格式為 @androidsdk//${group}:${artifact}-${version}
。以下範例說明 android_library
如何依賴 v7 appcompat 程式庫 25.0.0 版。
android_library( name = "lib", srcs = glob(["*.java"]), manifest = "AndroidManifest.xml", resource_files = glob(["res/**"]), deps = ["@androidsdk//com.android.support:appcompat-v7-25.0.0"], )
引數
屬性 | |
---|---|
name |
此目標的專屬名稱。 |
api_level
|
如要查看 |
build_tools_version
|
Bazel 需要 30.0.0 以上版本的建構工具。 |
path
|
$ANDROID_HOME 環境變數。您可以在 Android 開發人員網站下載 Android SDK。 |
repo_mapping
|
舉例來說,項目 |