diff --git a/.github/workflows/kotlin-ci.yml b/.github/workflows/kotlin-ci.yml index 0d9c0571cb5..2a158233357 100644 --- a/.github/workflows/kotlin-ci.yml +++ b/.github/workflows/kotlin-ci.yml @@ -55,5 +55,14 @@ jobs: source emsdk/emsdk_env.sh tools/generate-files + - name: CMake (Java, Kotlin) + run: | + cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Debug -DTW_UNITY_BUILD=ON -DTW_COMPILE_JAVA=ON -DTW_COMPILE_KOTLIN=ON -GNinja + + # The build artifact will be used in `tools/kotlin-build` in the future. + - name: Build JNI + run: | + ninja -Cbuild + - name: Build Kotlin Multiplatform run: tools/kotlin-build diff --git a/CMakeLists.txt b/CMakeLists.txt index c232a4dccb7..5cba2961f0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,7 @@ include(cmake/Protobuf.cmake) # Source files if (${ANDROID}) - message("Configuring for JNI") + message("Configuring for Android JNI") file(GLOB_RECURSE core_sources src/*.c src/*.cc src/*.cpp src/*.h jni/cpp/*.cpp jni/cpp/*.h) if (${KOTLIN}) file(GLOB_RECURSE specific_sources @@ -75,6 +75,24 @@ if (${ANDROID}) set(WALLET_CORE_BINDGEN ${WALLET_CORE_RS_TARGET_DIR}/x86_64-linux-android/release/${WALLET_CORE_RS_LIB}) endif () target_link_libraries(TrustWalletCore PUBLIC ${WALLET_CORE_BINDGEN} ${PROJECT_NAME}_INTERFACE PRIVATE TrezorCrypto protobuf ${log-lib} Boost::boost) +elseif (${TW_COMPILE_JAVA}) + message("Configuring for JNI") + file(GLOB_RECURSE core_sources src/*.c src/*.cc src/*.cpp src/*.h jni/cpp/*.cpp jni/cpp/*.h) + if (${TW_COMPILE_KOTLIN}) + file(GLOB_RECURSE specific_sources + jni/kotlin/*.h + jni/kotlin/*.c + kotlin/wallet-core-kotlin/src/commonAndroidJvmMain/cpp/generated/*.h + kotlin/wallet-core-kotlin/src/commonAndroidJvmMain/cpp/generated/*.c + ) + else () + file(GLOB_RECURSE specific_sources jni/android/*.h jni/android/*.c) + endif () + set(sources ${core_sources} ${specific_sources}) + add_library(TrustWalletCore SHARED ${sources} ${PROTO_SRCS} ${PROTO_HDRS}) + find_package(JNI REQUIRED) + target_include_directories(TrustWalletCore PRIVATE ${JNI_INCLUDE_DIRS}) + target_link_libraries(TrustWalletCore PUBLIC ${WALLET_CORE_BINDGEN} ${PROJECT_NAME}_INTERFACE PRIVATE TrezorCrypto protobuf Boost::boost) else () message("Configuring standalone") file(GLOB_RECURSE sources src/*.c src/*.cc src/*.cpp src/*.h) diff --git a/cmake/StandardSettings.cmake b/cmake/StandardSettings.cmake index 752b2285672..bef5a651b52 100644 --- a/cmake/StandardSettings.cmake +++ b/cmake/StandardSettings.cmake @@ -66,7 +66,7 @@ endif () option(TW_UNIT_TESTS "Enable the unit tests of the project" ON) option(TW_BUILD_EXAMPLES "Enable the examples builds of the project" ON) -if (ANDROID OR IOS_PLATFORM OR TW_COMPILE_WASM) +if (ANDROID OR IOS_PLATFORM OR TW_COMPILE_WASM OR TW_COMPILE_JAVA) set(TW_UNIT_TESTS OFF) set(TW_BUILD_EXAMPLES OFF) endif() diff --git a/jni/cpp/Random.cpp b/jni/cpp/Random.cpp index 3e15e28062f..8e583ae5a92 100644 --- a/jni/cpp/Random.cpp +++ b/jni/cpp/Random.cpp @@ -6,6 +6,7 @@ #include #include +#include static JavaVM* cachedJVM; @@ -27,7 +28,12 @@ uint32_t random32() { void random_buffer(uint8_t *buf, size_t len) { JNIEnv *env; + +#if defined(__ANDROID__) || defined(ANDROID) cachedJVM->AttachCurrentThread(&env, nullptr); +#else + cachedJVM->AttachCurrentThread((void **) &env, nullptr); +#endif // SecureRandom random = new SecureRandom(); jclass secureRandomClass = env->FindClass("java/security/SecureRandom"); diff --git a/trezor-crypto/CMakeLists.txt b/trezor-crypto/CMakeLists.txt index 76f526bd984..2e38617da2f 100644 --- a/trezor-crypto/CMakeLists.txt +++ b/trezor-crypto/CMakeLists.txt @@ -65,7 +65,7 @@ if (EMSCRIPTEN) message(STATUS "Skip building trezor-crypto/tests") set(TW_WARNING_FLAGS ${TW_WARNING_FLAGS} -Wno-bitwise-instead-of-logical) else () - if(NOT ANDROID AND NOT IOS_PLATFORM) + if(NOT ANDROID AND NOT IOS_PLATFORM AND NOT TW_COMPILE_JAVA) add_subdirectory(crypto/tests) endif() endif()