diff --git a/java/CMakeLists.txt b/java/CMakeLists.txt new file mode 100644 index 00000000..e48c75e1 --- /dev/null +++ b/java/CMakeLists.txt @@ -0,0 +1,40 @@ +# +# Copyright (c) 2014-present, Facebook, Inc. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. An additional grant +# of patent rights can be found in the PATENTS file in the same directory. +# + +cmake_minimum_required(VERSION 3.4.1) + +set(CMAKE_VERBOSE_MAKEFILE on) + +# configure import libs +set(libfb_DIR ${CMAKE_SOURCE_DIR}/../lib/fb/src/main/cpp) +set(yogacore_DIR ${CMAKE_SOURCE_DIR}/..) + +set(build_DIR ${CMAKE_SOURCE_DIR}/build) + +set(libfb_build_DIR ${build_DIR}/libfb/${ANDROID_ABI}) +set(yogacore_build_DIR ${build_DIR}/yogacore/${ANDROID_ABI}) + +file(MAKE_DIRECTORY ${build_DIR}) + +add_subdirectory(${libfb_DIR} ${libfb_build_DIR}) +add_subdirectory(${yogacore_DIR} ${yogacore_build_DIR}) + +add_compile_options( + -fno-omit-frame-pointer + -fexceptions + -Wall + -std=c++11) + +add_library(yoga SHARED jni/YGJNI.cpp) + +target_include_directories(yoga PRIVATE + ${libfb_DIR}/include + ${yogacore_DIR}) + +target_link_libraries(yoga yogacore fb) diff --git a/java/build.gradle b/java/build.gradle index 71611fc3..3284dbad 100644 --- a/java/build.gradle +++ b/java/build.gradle @@ -6,12 +6,6 @@ apply plugin: 'maven-publish' version = '1.4.2' group = 'com.facebook.yoga' -// We currently build the native libraries with buck and bundle them together -// at this point into the AAR -task buckBuildAndCopy(type: Exec) { - commandLine "$rootDir/scripts/build_natives_for_gradle.sh" -} - android { compileSdkVersion rootProject.compileSdkVersion buildToolsVersion rootProject.buildToolsVersion @@ -19,6 +13,22 @@ android { defaultConfig { minSdkVersion rootProject.minSdkVersion targetSdkVersion rootProject.targetSdkVersion + + ndk { + abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a' + } + + externalNativeBuild { + cmake { + arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static' + } + } + } + + externalNativeBuild { + cmake { + path 'CMakeLists.txt' + } } compileOptions { @@ -36,8 +46,6 @@ android { } } -preBuild.dependsOn buckBuildAndCopy - dependencies { compile 'com.google.code.findbugs:jsr305:3.0.1' compile 'com.facebook.soloader:soloader:0.2.0' diff --git a/scripts/build_natives_for_gradle.sh b/scripts/build_natives_for_gradle.sh deleted file mode 100755 index e570e1c5..00000000 --- a/scripts/build_natives_for_gradle.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -set -e -BASEDIR=$(dirname $0) - -DESTINATIONS=( - "build/buck-out/jniLibs/x86" - "build/buck-out/jniLibs/x86_64" - "build/buck-out/jniLibs/armeabi-v7a" - "build/buck-out/jniLibs/arm64-v8a" -) - -BUCK_TARGETS=( - "android-x86" - "android-x86_64" - "android-armv7" - "android-arm64" -) - -for (( i=0; i<4; i++ )); -do - mkdir -p "${DESTINATIONS[i]}" -done - -# There must be a better way to get gnustl_shared than building the android target. -# But for now, we include that target simply for that shared library... -echo "Build libgnustl_shared.so" -buck build //android/sample:sample - -cp "$BASEDIR/../buck-out/gen/android/sample/sample#X86,android-strip,libgnustl_shared.so/libgnustl_shared.so" "${DESTINATIONS[0]}" -cp "$BASEDIR/../buck-out/gen/android/sample/sample#X86_64,android-strip,libgnustl_shared.so/libgnustl_shared.so" "${DESTINATIONS[1]}" -cp "$BASEDIR/../buck-out/gen/android/sample/sample#ARMV7,android-strip,libgnustl_shared.so/libgnustl_shared.so" "${DESTINATIONS[2]}" -cp "$BASEDIR/../buck-out/gen/android/sample/sample#ARM64,android-strip,libgnustl_shared.so/libgnustl_shared.so" "${DESTINATIONS[3]}" - -# This is to clean up after the mess above. Yes, it is required. -buck clean -rm -r "$BASEDIR/../buck-out" - -for (( i=0; i<4; i++ )); -do - echo "Build ${BUCK_TARGETS[i]}" - buck build "//java:jni#${BUCK_TARGETS[i]},shared" - cp "$BASEDIR/../buck-out/gen/java/jni#${BUCK_TARGETS[i]},shared/libyoga.so" "${DESTINATIONS[i]}" - cp "$BASEDIR/../buck-out/gen/yoga#${BUCK_TARGETS[i]},shared/libyogacore.so" "${DESTINATIONS[i]}" - cp "$BASEDIR/../buck-out/gen/lib/fb/fbjni#${BUCK_TARGETS[i]},shared/liblib_fb_fbjni.so" "${DESTINATIONS[i]}" -done diff --git a/scripts/deploy_jcenter.sh b/scripts/deploy_jcenter.sh index 21aae0fa..897331a1 100755 --- a/scripts/deploy_jcenter.sh +++ b/scripts/deploy_jcenter.sh @@ -1,10 +1,11 @@ #!/bin/bash set -e +ROOTDIR="$(dirname $0)/.." echo -e "\033[1;34m** We can deploy two libraries\n** (1) Java bindings to Yoga\n** (2) Android YogaLayout\n** Which do you want to ship today? \033[0m" read -p "" -n 1 mod case $mod in - 1 ) MODULE="java";; - 2 ) MODULE="android";; + 1 ) MODULE="yoga";; + 2 ) MODULE="yoga-layout";; * ) echo -e "\n\033[1;34m** Invalid selection" && exit esac @@ -17,12 +18,12 @@ read -r BINTRAY_KEY echo -e "\033[1;34m** [3/3] Please enter your GPG passphrase: \033[0m" read -r GPG_PASS -uploadcmd="gradle clean build bintrayUpload --info -PbintrayUsername='$BINTRAY_USER' -PbintrayApiKey='$BINTRAY_KEY' -PbintrayGpgPassword='$GPG_PASS'" +uploadcmd="$ROOTDIR/gradlew clean :${MODULE}:build bintrayUpload --info -PbintrayUsername='$BINTRAY_USER' -PbintrayApiKey='$BINTRAY_KEY' -PbintrayGpgPassword='$GPG_PASS'" echo echo -e "\033[1;34m** Dry run\033[0m" -(cd $MODULE ; eval "$uploadcmd -PdryRun=true") +eval "$uploadcmd -PdryRun=true" echo echo -e "\033[1;34m** Are you happy to conintue?: [yN]\033[0m" @@ -35,4 +36,4 @@ read -p "" -n 1 yn echo echo -e "\033[1;34m** Publishing\033[0m" -(cd $MODULE ; eval "$uploadcmd") +eval "$uploadcmd"