#!/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 test environment source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../test-setup.sh \ || { echo "test-setup.sh not found!" >&2; exit 1; } function test_android_binary() { create_new_workspace setup_android_support 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 bazel build -s //java/bazel:bin || fail "build failed" } if [[ ! -r "${TEST_SRCDIR}/external/androidndk/ndk/RELEASE.TXT" ]]; then echo "Not running Android tests due to lack of an Android NDK." exit 0 fi if [[ ! -r "${TEST_SRCDIR}/external/androidsdk/SDK Readme.txt" ]]; then echo "Not running Android tests due to lack of an Android SDK." exit 0 fi run_suite "Android integration tests"