xref: /aosp_15_r20/build/bazel/examples/android_app/java/com/app/BUILD (revision 7594170e27e0732bc44b93d1440d87a54b6ffe7c)
1# Copyright (C) 2023 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15load("//build/bazel/rules/android:aar_import.bzl", "aar_import")
16load("//build/bazel/rules/android:android_binary.bzl", "android_binary")
17load("//build/bazel/rules/android:android_library.bzl", "android_library")
18load("//build/bazel/rules/cc:cc_library_shared.bzl", "cc_library_shared")
19load("//build/bazel/rules/cc:cc_library_static.bzl", "cc_library_static")
20
21package(default_applicable_licenses = ["//build/soong/licenses:Android-Apache-2.0"])
22
23android_binary(
24    name = "app",
25    manifest = "AndroidManifest.xml",
26    sdk_version = "current",
27    target_compatible_with = ["//build/bazel_common_rules/platforms/os:android"],
28    deps = [
29        ":applib",
30        ":jni",
31    ],
32)
33
34android_binary(
35    name = "app-cert-string",
36    certificate_name = "platform",
37    manifest = "AndroidManifest.xml",
38    sdk_version = "current",
39    target_compatible_with = ["//build/bazel_common_rules/platforms/os:android"],
40    deps = [
41        ":applib",
42    ],
43)
44
45android_binary(
46    name = "app-cert-module",
47    certificate = "//build/make/target/product/security:aosp-testkey",
48    manifest = "AndroidManifest.xml",
49    sdk_version = "current",
50    target_compatible_with = ["//build/bazel_common_rules/platforms/os:android"],
51    deps = [
52        ":applib",
53    ],
54)
55
56android_library(
57    name = "applib",
58    srcs = [
59        "Jni.java",
60        "MainActivity.java",
61        "some_kotlin.kt",
62    ],
63    manifest = "AndroidManifest.xml",
64    resource_files = glob(["res/**"]),
65    sdk_version = "current",
66    target_compatible_with = ["//build/bazel_common_rules/platforms/os:android"],
67    deps = [
68        ":lib",
69    ],
70)
71
72android_library(
73    name = "lib",
74    srcs = ["Lib.java"],
75    sdk_version = "current",
76    target_compatible_with = ["//build/bazel_common_rules/platforms/os:android"],
77)
78
79cc_library_shared(
80    name = "jni",
81    srcs = ["jni.cc"],
82    stl = "libc++",
83    deps = [":jni_dep"],
84)
85
86cc_library_static(
87    name = "jni_dep",
88    srcs = ["jni_dep.cc"],
89    hdrs = ["jni_dep.h"],
90    stl = "libc++",
91    deps = ["//libnativehelper:jni_headers"],
92)
93
94aar_import(
95    name = "import",
96    aar = "example_lib.aar",
97    sdk_version = "32",
98    target_compatible_with = ["//build/bazel_common_rules/platforms/os:android"],
99)
100
101# This is a minimal app that builds against the NDK
102android_binary(
103    name = "app_with_sdk_variant_of_jni_deps",
104    manifest = "AndroidManifest.xml",
105    sdk_version = "current",
106    target_compatible_with = ["//build/bazel_common_rules/platforms/os:android"],
107    deps = [
108        "//external/dexmaker:libdexmakerjvmtiagent",
109        "//external/dexmaker:libstaticjvmtiagent",
110    ],
111)
112
113# A test to verify that ndk libs are not included in an android_app
114sh_test(
115    name = "no_ndk_libs_in_android_app",
116    srcs = ["no_ndk_libs_in_android_app.sh"],
117    # SimpleJNI has jni libs that builds against the NDK by setting sdk_version: "current"
118    data = ["//development/samples/SimpleJNI"],
119)
120