규칙
- 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가 설정된 경우에만 생성됩니다.
예
Android 규칙의 예는 Bazel 소스 트리의 examples/android 디렉터리에서 확인할 수 있습니다.
인수
| 속성 | |
|---|---|
name |
이름: 필수 이 타겟의 고유한 이름입니다. |
deps
|
라벨 목록입니다. 기본값은 android_library, android 제약 조건이 있는 java_library, Android 타겟 플랫폼용 .so 네이티브 라이브러리를 래핑하거나 생성하는 cc_library입니다.
|
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
|
라벨: 필수 Android 매니페스트 파일의 이름입니다(일반적으로AndroidManifest.xml).
resource_files 또는 assets가 정의된 경우 정의해야 합니다.
|
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입니다.
생성된 파일 (genrule에서)도 여기에서 라벨로 참조할 수 있습니다. 유일한 제한사항은 생성된 출력이 포함된 다른 리소스 파일과 동일한 ' 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
|
라벨: 필수 이 타겟에 종속된 Android 타겟에 제공할.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: 소스 ('소스 jar')가 포함된 보관 파일입니다.name.aar: 이 타겟의 Java 보관 파일과 리소스를 포함하는 Android 'aar' 번들입니다. 전이적 폐쇄가 포함되어 있지 않습니다.
예
Android 규칙의 예는 Bazel 소스 트리의 examples/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, android 제약 조건이 있는 java_library, Android 타겟 플랫폼용 .so 네이티브 라이브러리를 래핑하거나 생성하는 cc_library입니다.
|
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로 변환되거나 컴파일되지는 않습니다.
이 라이브러리의 이러한 파일은 aidl 컴파일러가 찾을 수 있도록 적절하게 배치해야 합니다. 이것이 무엇을 의미하는지 알아보려면 idl_import_root 설명을 참고하세요. |
idl_preprocessed
|
라벨 목록입니다. 기본값은 android_library 타겟의 가져오기로 제공되지만 Java로 변환되거나 컴파일되지는 않습니다.
이 라이브러리의 |
idl_srcs
|
라벨 목록입니다. 기본값은 srcs의 콘텐츠와 함께 컴파일됩니다.
이러한 파일은 이 라이브러리에 직접 또는 전이적 클로저를 통해 종속된 모든 이러한 파일은 aidl 컴파일러가 찾을 수 있도록 적절하게 배치해야 합니다. 이것이 무엇을 의미하는지 알아보려면 idl_import_root 설명을 참고하세요. |
javacopts
|
문자열 목록입니다. 기본값은 이러한 컴파일러 옵션은 전역 컴파일러 옵션 뒤에 javac에 전달됩니다. |
manifest
|
라벨: 기본값은 AndroidManifest.xml).
resource_files 또는 assets가 정의된 경우 정의해야 합니다.
|
neverlink
|
불리언, 기본값은 neverlink로 표시된 규칙의 출력은 .apk 생성에 사용되지 않습니다. 실행 중에 런타임 환경에서 라이브러리를 제공하는 경우에 유용합니다.
|
plugins
|
라벨 목록입니다. 기본값은 java_plugin는 이 타겟이 빌드될 때마다 실행됩니다. 플러그인에서 생성된 리소스는 타겟의 결과 jar에 포함됩니다.
|
proguard_specs
|
라벨 목록입니다. 기본값은 android_binary 타겟에 추가됩니다.
여기에 포함된 파일에는 -dontnote, -dontwarn, assumenosideeffects, -keep으로 시작하는 규칙 등 멱등원 규칙만 있어야 합니다. 다른 옵션은 android_binary의 proguard_specs에만 표시되어야 합니다. 그래야 동어 반복이 아닌 병합이 보장됩니다.
|
resource_files
|
라벨 목록입니다. 기본값은 res 디렉터리 아래에 있는 모든 파일의 glob입니다.
생성된 파일 (genrule에서)도 여기에서 라벨로 참조할 수 있습니다. 유일한 제한사항은 생성된 출력이 포함된 다른 리소스 파일과 동일한 ' 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 타겟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: 소스를 포함하는 보관 파일('소스 jar')입니다.name_deploy.jar: 배포에 적합한 Java 배포 보관 파일입니다 (명시적으로 요청된 경우에만 빌드됨).
예
android_local_test와 함께 Robolectric을 사용하려면 WORKSPACE 파일에 Robolectric 저장소를 추가하세요.
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()
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 또는 assets가 정의된 경우 또는 테스트 중인 라이브러리의 매니페스트에 minSdkVersion 태그가 있는 경우 정의해야 합니다.
|
manifest_values
|
사전: 문자열 -> 문자열, 기본값은 applicationId, versionCode, versionName, minSdkVersion, targetSdkVersion, maxSdkVersion도 매니페스트 및 uses-sdk 태그의 해당 속성을 재정의합니다. packageName은 무시되고 지정된 경우 applicationId 또는 매니페스트의 패키지에서 설정됩니다.
manifest_values를 사용하기 위해 규칙에 매니페스트가 있을 필요는 없습니다.
|
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 run 명령어를 통해 시작하거나 생성된 스크립트를 직접 실행하여 시작할 수 있습니다. 자체 규칙을 정의하는 대신 기존 android_device 규칙을 사용하는 것이 좋습니다.
이 규칙은 Bazel 테스트 및 Blaze 실행에 --run_under 플래그의 적합한 타겟입니다. 에뮬레이터를 시작하고 테스트/실행할 타겟을 에뮬레이터에 복사하고 적절하게 테스트하거나 실행합니다.
android_device는 기본 system_image가 X86 기반이고 최대 I686 CPU 아키텍처에 최적화된 경우 KVM 이미지 생성을 지원합니다. KVM을 사용하려면 android_device 규칙에 tags = ['requires-kvm'] 를 추가합니다.
암시적 출력 타겟
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 connect를 실행해야 합니다.
- --emulator_port: 에뮬레이터의 텔넷 관리 콘솔을 노출할 포트입니다.
- --enable_display: true인 경우 디스플레이로 에뮬레이터를 시작합니다 (기본값은 false).
- --action: 시작 또는 종료
- --apks_to_install: 에뮬레이터에 설치할 APK 목록입니다.
인수
| 속성 | |
|---|---|
name |
이름: 필수 이 타겟의 고유한 이름입니다. |
cache
|
정수, 필수 에뮬레이터의 캐시 파티션 크기(MB)입니다. 이 값의 최솟값은 16MB입니다. |
default_properties
|
라벨: 기본값은 |
horizontal_resolution
|
정수, 필수 에뮬레이션할 가로 화면 해상도(픽셀)입니다. 최솟값은 240입니다. |
platform_apks
|
라벨 목록입니다. 기본값은 |
ram
|
정수, 필수 기기에서 에뮬레이션할 RAM 양(MB)입니다. 이는 기기에 설치된 특정 앱이 아닌 기기 전체에 적용됩니다. 최솟값은 64MB입니다. |
screen_density
|
정수, 필수 에뮬레이트된 화면의 밀도(인치당 픽셀)입니다. 이 값의 최솟값은 30ppi입니다. |
system_image
|
라벨: 필수 다음 파일이 포함된 파일 그룹:
|
vertical_resolution
|
정수, 필수 에뮬레이션할 세로 화면 해상도(픽셀)입니다. 최솟값은 240입니다. |
vm_heap
|
정수, 필수 Android가 각 프로세스에 사용할 가상 머신 힙의 크기(MB)입니다. 최솟값은 16MB입니다. |
android_ndk_repository
규칙 소스 보기android_ndk_repository(name, api_level, path, repo_mapping)
네이티브 코드로 Android 타겟 빌드를 지원하도록 Android NDK를 사용하도록 Bazel을 구성합니다.
이 android_ndk_repository 구현은 Starlark의 구현으로 대체되고 있습니다. 버전 25 이상의 향후 NDK 버전 지원은 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에는 런타임에 기기의 CPU를 감지하는 데 사용할 수 있는 cpufeatures 라이브러리가 포함되어 있습니다. 다음 예에서는 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 NDK는 Android 개발자 사이트 에서 다운로드할 수 있습니다. |
repo_mapping
|
사전: 문자열 -> 문자열, 기본값은 예를 들어 |
android_sdk_repository
규칙 소스 보기android_sdk_repository(name, api_level, build_tools_version, path, repo_mapping)
Android 타겟 빌드를 지원하기 위해 로컬 Android SDK를 사용하도록 Bazel을 구성합니다.
예
Bazel용 Android SDK를 설정하는 최소한의 방법은WORKSPACE 파일에 'androidsdk'라는 android_sdk_repository 규칙을 넣고 $ANDROID_HOME 환경 변수를 Android SDK 경로로 설정하는 것입니다. Bazel은 기본적으로 Android SDK에 설치된 가장 높은 Android API 수준과 빌드 도구 버전을 사용합니다.
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 지원 저장소'로 제공됩니다.
이는 지원 및 AppCompat 라이브러리와 같은 버전이 지정된 일반 Android 라이브러리 집합으로, 로컬 Maven 저장소로 패키징됩니다. android_sdk_repository는 android_binary 및 android_library 타겟의 종속 항목에서 사용할 수 있는 이러한 각 라이브러리의 Bazel 타겟을 생성합니다.
생성된 타겟의 이름은 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
|
정수; 구성할 수 없음; 기본값은 지정된 빌드에 사용되는 API 수준은
|
build_tools_version
|
문자열, 구성 불가, 기본값은 Bazel에는 빌드 도구 버전 30.0.0 이상이 필요합니다. |
path
|
문자열, 구성 불가, 기본값은 $ANDROID_HOME 환경 변수를 설정해야 합니다.
Android SDK는 Android 개발자 사이트에서 다운로드할 수 있습니다. |
repo_mapping
|
사전: 문자열 -> 문자열, 기본값은 예를 들어 |