Add an integration test to verify ndk libs are not included

android apps that target an sdk should not embed an ndk lib even if
one of its jni libraries has a transiive depdencny on it.

Add an integration test that asserts this behavior for `b` built apps.

Bug: 301295448
Test: b run //build/bazel/examples/android_app/java/com/app:no_ndk_libs_in_android_app --config=android

Change-Id: I879933c47e15261e9e96aea90ff3f81a9f1a3c5b
diff --git a/examples/android_app/java/com/app/BUILD b/examples/android_app/java/com/app/BUILD
index 013a580..29eb78d 100644
--- a/examples/android_app/java/com/app/BUILD
+++ b/examples/android_app/java/com/app/BUILD
@@ -109,3 +109,11 @@
         "//external/dexmaker:libstaticjvmtiagent",
     ],
 )
+
+# A test to verify that ndk libs are not included in an android_app
+sh_test(
+    name = "no_ndk_libs_in_android_app",
+    srcs = ["no_ndk_libs_in_android_app.sh"],
+    # SimpleJNI has jni libs that builds against the NDK by setting sdk_version: "current"
+    data = ["//development/samples/SimpleJNI"],
+)
diff --git a/examples/android_app/java/com/app/no_ndk_libs_in_android_app.sh b/examples/android_app/java/com/app/no_ndk_libs_in_android_app.sh
new file mode 100755
index 0000000..42398bc
--- /dev/null
+++ b/examples/android_app/java/com/app/no_ndk_libs_in_android_app.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+#
+# Copyright 2023 Google Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -euo pipefail
+
+# This test asserts that the android_app under test does not package ndk libs
+#
+# Setup
+# android_app: SimpleJni
+# jni_libs: libsimplejni
+# transitive_dep_of_jni_lib: liblog (an NDK library)
+#
+# Expectation
+# SimpleJni.apk contains libsimplejni.so
+# SimpleJni.apk does not contain libglog.so
+
+unsigned_apk=$(find ${RUNFILES_DIR} -name *_unsigned.apk)
+
+# check that the apk contains libsimplejni.so
+if ! [[ $(unzip -l ${unsigned_apk} | grep lib/.*libsimplejni.so ) ]]; then
+  echo "Could not find libsimplejni.so in SimpleJni's apk file: ${unsigned_apk}"
+  exit 1
+fi
+
+# check that the apk does not liblog.so
+if [[ $(unzip -l ${unsigned_apk} | grep lib/.*liblog.so ) ]]; then
+  echo "Found liblog.so in SimpleJni's apk file: ${unsigned_apk}. Since this is an NDK library, it should not be included."
+  exit 1
+fi