Skip to content

Android custom lib #5501

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

Closed
wants to merge 4 commits into from
Closed

Android custom lib #5501

wants to merge 4 commits into from

Conversation

kirklandsign
Copy link
Contributor

@kirklandsign kirklandsign commented Sep 19, 2024

  1. Clean up the file to group all deps libs together.
  2. Add an option EXECUTORCH_JNI_CUSTOM_LIBRARY for user to pass in their own library.

Example:

echo "int my_function() { return 0; }" > my_source.cpp
echo "int my_function2() { return 0; }" > my_source2.cpp

${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android27-clang -c my_source.cpp -o file1.o
${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android27-clang -c my_source2.cpp -o file2.o

ar rcs libmystaticlib.a file1.o
ar rcs libmystaticlib2.a file2.o

rm my_source.cpp my_source2.cpp file1.o file2.o

cmake extension/android \
    -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake \
    -DANDROID_ABI=arm64-v8a \
    -DANDROID_PLATFORM=android-23 \
    -DCMAKE_INSTALL_PREFIX=cmake-out-android-arm64-v8a \
    -DEXECUTORCH_ENABLE_LOGGING=ON \
    -DEXECUTORCH_LOG_LEVEL=Info \
    -DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
    -DEXECUTORCH_BUILD_LLAMA_JNI=ON \
    -DEXECUTORCH_JNI_CUSTOM_LIBRARY="/home/hsz/executorch/libmystaticlib.a;/home/hsz/executorch/libmystaticlib2.a" \
    -DCMAKE_BUILD_TYPE=Release \
    -Bcmake-out-android-arm64-v8a/extension/android

cmake --build cmake-out-android-arm64-v8a/extension/android -j 10 --config Release

nm -gDC ./cmake-out-android-arm64-v8a/extension/android/libexecutorch_jni.so | grep my_function

and you will see

00000000001d1ff0 T my_function()
00000000001d1ff8 T my_function2()

kirklandsign and others added 4 commits September 19, 2024 15:25
Group dependent library rules together
Also add test instruction

```
echo "int my_function() { return 0; }" > my_source.cpp
echo "int my_function2() { return 0; }" > my_source2.cpp

${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android27-clang -c my_source.cpp -o file1.o
${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android27-clang -c my_source2.cpp -o file2.o

ar rcs libmystaticlib.a file1.o
ar rcs libmystaticlib2.a file2.o

rm my_source.cpp my_source2.cpp file1.o file2.o

cmake extension/android \
    -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake \
    -DANDROID_ABI=arm64-v8a \
    -DANDROID_PLATFORM=android-23 \
    -DCMAKE_INSTALL_PREFIX=cmake-out-android-arm64-v8a \
    -DEXECUTORCH_ENABLE_LOGGING=ON \
    -DEXECUTORCH_LOG_LEVEL=Info \
    -DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
    -DEXECUTORCH_BUILD_LLAMA_JNI=ON \
    -DEXECUTORCH_JNI_CUSTOM_LIBRARY="/home/hsz/executorch/libmystaticlib.a;/home/hsz/executorch/libmystaticlib2.a" \
    -DCMAKE_BUILD_TYPE=Release \
    -Bcmake-out-android-arm64-v8a/extension/android

cmake --build cmake-out-android-arm64-v8a/extension/android -j 10 --config Release

nm -gDC ./cmake-out-android-arm64-v8a/extension/android/libexecutorch_jni.so | grep my_function

```
Copy link

pytorch-bot bot commented Sep 19, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/5501

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 60db84f with merge base 47f4f07 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 19, 2024
@facebook-github-bot
Copy link
Contributor

@kirklandsign has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@kirklandsign merged this pull request in a9f3f81.

@kirklandsign kirklandsign deleted the android-custom-lib branch September 20, 2024 04:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants