Issue
EDIT: I managed to built x86_64 version of libreactnativejni.so
(see my answer). However it didn't resolved my problem.
To sum up what I learned here is:
You cannot test android components, which are using native libraries on Linux, because "libandroid.so" (core android lib), doesn't exists for Linux.
Original question:
My goal is to run tests on my Linux box using PowerMockito similar to RootViewTest.java.
Not sure how react-native team managed to run this test, but from my experience mocking Arguments.createArray
is not possible, without loading jni library reactnativejni
. Reason is that Arguments.createArray()
calls WritableNativeArray
which in static initializer ReactBridge.staticInit() calls SoLoader.loadLibrary("reactnativejni")
.
So I thought I've no other option, but compile this reactnativejni shared library for linux, using 64bit android-ndk-r10e
I managed to load this jni lib and test my code using:
ndkDir=$(pwd)/react-ndk/all/x86 \
JAVA_OPTS="-Djava.library.path=\".:$ndkDir\"" \
LD_LIBRARY_PATH="$ndkDir:$LD_LIBRARY_PATH" ./gradlew app:test
But test failed with:
libreactnativejni.so: wrong ELF class: ELFCLASS32 (Possible cause: architecture word width mismatch)
Checked platform with objdump:
objdump -s --section .comment libreactnativejni.so
libreactnativejni.so: file format elf32-i386
My question how is possible that 64 bit ndk produced 32 bit library and how to force to produce 64 bit.
Library build script is written as gradle script:
Solution
I'm going to answer my own question (thank Alex for good APP_ABI lead). To compile x86_64 variant of reactnativejni
follow this steps:
- Update APP_ABI to
APP_ABI := armeabi-v7a x86_64 x86
in fileReactAndroid/src/main/jni/Application.ml
The next problem is dependency jsc-android, which is not build for X86_64 target. There is alternative jsc-android-buildscripts which is also built for X86_64.
- Extract folder X86_64 directly from aar and put it in
ReactAndroid/build/third-party-ndk/jsc/jni/x86_64
However compilation will be failing on X86_64 with errors: lambda capture initializers only available with -std=c++1y or -std=gnu++1y
Fix that error, by replacing all occurrences of
-std=c++1y
with-std=c++11
in allAndroid.mk
files.Now you can start build with:
./gradlew buildReactNdkLib
- Optionally you might need to clean build folder with
./gradlew cleanReactNdkLib
Built reactnativejni
- libreactnativejni.so
will be present in ReactAndroid/build/react-ndk/all/x86_64
.
But unfortunately libreactnativejni.so
will not work on Linux, as it has dependency on libandroid.so
, which doesn't exists for Linux.
Answered By - mauron85
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.