#!/bin/bash # # Copyright 2015 The Bazel Authors. 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. # Load the test setup defined in the parent directory CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${CURRENT_DIR}/../../integration_test_setup.sh" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function create_android_binary() { mkdir -p java/bazel cat > java/bazel/BUILD < java/bazel/AndroidManifest.xml < EOF cat > java/bazel/Lib.java < java/bazel/Jni.java < java/bazel/MainActivity.java < java/bazel/jni_dep.h < jstring NewStringLatin1(JNIEnv *env, const char *str); EOF cat > java/bazel/jni_dep.cc < #include jstring NewStringLatin1(JNIEnv *env, const char *str) { int len = strlen(str); jchar *str1; str1 = reinterpret_cast(malloc(len * sizeof(jchar))); for (int i = 0; i < len; i++) { str1[i] = (unsigned char)str[i]; } jstring result = env->NewString(str1, len); free(str1); return result; } EOF cat > java/bazel/jni.cc < #include #include "java/bazel/jni_dep.h" extern "C" JNIEXPORT jstring JNICALL Java_bazel_Jni_hello(JNIEnv *env, jclass clazz) { std::string hello = "Hello"; std::string jni = "JNI"; return NewStringLatin1(env, (hello + " " + jni).c_str()); } EOF } function check_num_sos() { num_sos=$(unzip -Z1 bazel-bin/java/bazel/bin.apk '*.so' | wc -l | sed -e 's/[[:space:]]//g') assert_equals "11" "$num_sos" } function check_soname() { # For an android_binary with name foo, readelf output format is # Tag Type Name/Value # 0x00000010 (SONAME) Library soname: [libfoo] # # If -Wl,soname= is not set, then SONAME will not appear in the output. # # readelf is a Linux utility and not available on Mac by default. The NDK # includes readelf however the path is difference for Mac vs Linux, hence the # star. readelf="${TEST_SRCDIR}/androidndk/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/*/bin/arm-linux-androideabi-readelf" soname=$($readelf -d bazel-bin/java/bazel/_dx/bin/native_symlinks/x86/libbin.so \ | grep SONAME \ | awk '{print substr($5,2,length($5)-2)}') assert_equals "libbin" "$soname" } function test_sdk_library_deps() { create_new_workspace setup_android_support mkdir -p java/a cat > java/a/BUILD<