![]() ![]() The second step is needed to load your library at runtime here called “hello”. To access your swift function over the JNI, you have to define some that include the java package name: public func returnData(env: UnsafeMutablePointer?, jobj: jobject) -> jstring? ![]() That last configuration point is to set up your Package.swift file to generate a dynamic link library, that can be used in any android project, for this you need to add a product definition: ![]() Next you have to set all compiler flags: -Xswiftc -I and linker flags : -Xlinker -L correctly to get an binary for armv7 /root/usr/bin/swift build \ -Xcc -I$ANDROID_NDK_HOME/platforms/android-21/arch-arm/usr/include \ -Xswiftc -I/usr/local/lib/swift/android/armv7 \ -Xswiftc -I$ANDROID_SWIFT_SOURCE/build/Ninja-ReleaseAssert/foundation-linux-x86_64/Foundation \ -Xswiftc -I$ANDROID_SWIFT_SOURCE/swift-corelibs-foundation \ -Xswiftc -I$ANDROID_SWIFT_SOURCE/swift-corelibs-foundation/closure \ -Xswiftc -target -Xswiftc armv7-none-linux-androideabi \ -Xswiftc -sdk -Xswiftc $ANDROID_NDK_HOME/platforms/android-21/arch-arm \ -Xcc -target -Xcc armv7-none-linux-androideabi \ -Xcc -B -Xcc $ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin/ \ -Xcc -sysroot=$ANDROID_NDK_HOME/platforms/android-21/arch-arm/ \ -Xlinker -L/usr/local/lib/swift/android/ \ -Xlinker -L$ANDROID_SWIFT_SOURCE/build/Ninja-ReleaseAssert/foundation-linux-x86_64/Foundation/ \ -Xlinker -L$ANDROID_NDK_HOME/sources/cxx-stl/llvm-libc /libs/armeabi-v7a \ -Xlinker -L$ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/ \ -Xlinker -L$ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/lib/armv7-a/ \ -Xlinker -L$ANDROID_LIBICONV/armeabi-v7a \ -Xlinker -L/root/android-standalone-toolchain/sysroot/usr/lib/ \ -Xlinker -sysroot=$ANDROID_NDK_HOME/platforms/android-21/arch-arm/ \ -Xlinker -L$ANDROID_LIBICONV/armeabi-v7a/lib \ -Xlinker -lgcc -Xlinker -ldispatch \ -Xlinker -lFoundation \ -Xlinker -latomic -Xlinker -licuuc \ -Xlinker -licui18n In order to create an (.so) library that can be used with an JNI in your android app, you have to set up your swift package manager, here a step by step manual:Įxport ANDROID_NDK_HOME=/root/ndk/android-ndk-r13bĮxport ANDROID_SWIFT_SOURCE=/root/swift-sourceĮxport ANDOIRD_CJINI=/root/source_compileĮxport ANDROID_LIBICONV=/root/libiconv-libicu-android/ ![]() Now you can compile your swift code with swift package manager. In the first step, you created an Swift Development Environment for Android ( previous post) for example on your Ubuntu 16.10 VM. You probably need to select a different build tool.Android App with Java native interface for Swift Call Stack (most recent call first): /opt/homebrew/Cellar/cmake/3.22.1/share/cmake/Modules/CMakeDetermineSystem.cmake:160 (include) CMakeLists.txt:113 (enable_language) CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". Android_configure: cmake config NDK_VESION_MAJOR: 23 NDK_PLATFORM: android-21 ANDROID_NDK_HOME: /Users/~/Library/Android/sdk/ndk/620 SYSROOT: /Users/~/Library/Android/sdk/ndk/620/toolchains/llvm/prebuilt/darwin-x86_64/sysroot Toolchain: /Users/~/Library/Android/sdk/ndk/620/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include AR: /Users/~/Library/Android/sdk/ndk/620/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ar /Users/~/Library/Android/sdk/ndk/620 /Users/~/SOURCE/apothecary/apothecary/build/opencv/build_android_x86 CMake Error at /opt/homebrew/Cellar/cmake/3.22.1/share/cmake/Modules/Platform/Android-Determine.cmake:584 (message): Android: CMAKE_ANDROID_ARM_MODE is set but is valid only for 'armeabi' architectures. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |