Skip to content

Android build cmake in gradle #11085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -721,4 +721,8 @@ if(EXECUTORCH_BUILD_VULKAN)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/vulkan)
endif()

if(ANDROID)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/android)
endif()

include(Test.cmake)
13 changes: 7 additions & 6 deletions extension/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

cmake_minimum_required(VERSION 3.24) # 3.24 is required for WHOLE_ARCHIVE

project(executorch_jni)
if(NOT EXECUTORCH_ROOT)
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
endif()

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
Expand All @@ -16,7 +18,6 @@ if(NOT ANDROID)
message(FATAL_ERROR "This directory is for Android build only")
endif()

set(EXECUTORCH_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..")
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
set(_common_compile_options -Wno-deprecated-declarations -fPIC)
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
Expand Down Expand Up @@ -60,8 +61,6 @@ set_target_properties(fbjni PROPERTIES
IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/libs/android.${ANDROID_ABI}/libfbjni.so"
)

set(executorch_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../lib/cmake/ExecuTorch)
find_package(executorch CONFIG REQUIRED)
target_link_options_shared_lib(executorch)

add_library(executorch_jni SHARED jni/jni_layer.cpp jni/log.cpp jni/jni_layer_runtime.cpp)
Expand Down Expand Up @@ -152,12 +151,12 @@ if(EXECUTORCH_BUILD_LLAMA_JNI)
target_compile_definitions(executorch_jni PUBLIC EXECUTORCH_BUILD_LLAMA_JNI=1)
add_subdirectory(
${EXECUTORCH_ROOT}/examples/models/llava/runner
${CMAKE_CURRENT_BINARY_DIR}/../../examples/models/llava/runner
${CMAKE_CURRENT_BINARY_DIR}/examples/models/llava/runner
)

add_subdirectory(
${EXECUTORCH_ROOT}/examples/models/llama/runner
${CMAKE_CURRENT_BINARY_DIR}/../../examples/models/llama/runner
${CMAKE_CURRENT_BINARY_DIR}/examples/models/llama/runner
)

if(NEURON_BUFFER_ALLOCATOR_LIB)
Expand Down Expand Up @@ -192,3 +191,5 @@ target_include_directories(
target_compile_options(executorch_jni PUBLIC ${_common_compile_options})

target_link_libraries(executorch_jni ${link_libraries} log)

set_target_properties(executorch_jni PROPERTIES OUTPUT_NAME executorch)
36 changes: 24 additions & 12 deletions extension/android/executorch_android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,35 @@ android {
minSdk = 23

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
externalNativeBuild {
cmake {
abiFilters "arm64-v8a"
targets "executorch_jni"
arguments "-DBUILD_TESTING=OFF", "-DCMAKE_POLICY_VERSION_MINIMUM=3.24", "-DEXECUTORCH_BUILD_XNNPACK=ON", "-DEXECUTORCH_XNNPACK_SHARED_WORKSPACE=ON", "-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON", "-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON", "-DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON", "-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON", "-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON", "-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON"
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

sourceSets {
main {
jniLibs.srcDirs = ['../../../cmake-out-android-so/']
sourceSets {
androidTest {
resources.srcDirs += ['src/androidTest/resources']
}
}
androidTest {
resources.srcDirs += [ 'src/androidTest/resources' ]

kotlinOptions {
jvmTarget = "1.8"
}
}
kotlinOptions {
jvmTarget = "1.8"

externalNativeBuild {
cmake {
path "../../../CMakeLists.txt"
}
}
}

Expand Down
Loading