I have an apk with native .so libs, compiled for all architectures: armabi, mips, x86 and x86_64. I want to use these libs in my java app.
As i suppose, for building app on desktop i need to copy .so file from x86_64 folder anywhere on my PC, i've copied it to ~/IdeaProjects/ecg/lib/x86_64. After that i provided to VM path to this file as follows: -Djava.library.path=/home/user/IdeaProjects/ecg/lib/x86_64
Then i wrote wrapper for using this library on my project. In static initializer of wrapper i trying to load the library like that (my library file named libnative-lib.so):
static
{
System.loadLibrary("native-lib");
}
And during loading library i receive this exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/user/IdeaProjects/ecg/lib/x86_64/libnative-lib.so: liblog.so: cannot open shared object file: no such file or directory
So what is liblog.so? Where can i get it? I tried to dig and all what i found was compiled liblog.so for different arches on github. I've found one for x86_64 there, put it near my native lib file, but the exception didn't disappear.
What can i do for achieving my goal?
UPD
sudo apt install android-liblog && android-liblog-dev and provide LD_LIBRARY_PATH=/usr/lib/android resolve this issue. But now i'm received next error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/user/IdeaProjects/ecg/lib/x86_64/libnative-lib.so: /usr/lib/x86_64-linux-gnu/libm.so: invalid ELF header
UPDUPD finally i've copied all dependent libs from android sdk folder (Sdk/ndk-bundle/platforms/android-24/arch-x86_64/usr/lib64) and exceptions has gone. Now app simply falls with this report:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x0000000000000000, pid=11338, tid=0x00007ffaccb05700
#
# JRE version: OpenJDK Runtime Environment (8.0_131-b11) (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11)
# Java VM: OpenJDK 64-Bit Server VM (25.131-b11 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C 0x0000000000000000
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/user/IdeaProjects/ecg/hs_err_pid11338.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
Related
I'm building a huge project that requires ndk versions above 25 (I'm using 25.0.8775105 right now). And I would like to use TFLite on my project. Following the docs, to cross-compile it on my x86-64 machine to be suitable for arm64-v8a architectures the instructions goes as follows:
Get tensorflow source
Install bazel (I've tried both 6.0.0 and the 7.0.0-prebuild)
Run ./configure and say y to Would you like to interactively configure ./WORKSPACE for Android builds?, then configure it.
Run bazel build -c opt --config=android_arm64 //tensorflow/lite:libtensorflowlite.so
Extract the .so file and get the header files than use like any other library.
When I run ./configure and say yes to configuring ./WORKSPACE, it wants me to provide an ndk directory. However, when I provide it (it being /home/tb/Android/Sdk/ndk/25.0.8775105 on my system, very similar to what's recommended) I get hit with this: WARNING: The NDK version in /home/tb/Android/Sdk/ndk/25.0.8775105 is 25, which is not supported by Bazel (officially supported versions: [19, 20, 21]). Please use another version. Compiling Android targets may result in confusing errors. followed by an error caused by this:
Traceback (most recent call last):
File "/home/tb/Desktop/tensorflow/tensorflow_src/./configure.py", line 1363, in <module>
main()
File "/home/tb/Desktop/tensorflow/tensorflow_src/./configure.py", line 1336, in main
create_android_ndk_rule(environ_cp)
File "/home/tb/Desktop/tensorflow/tensorflow_src/./configure.py", line 653, in create_android_ndk_rule
get_ndk_api_level(environ_cp, android_ndk_home_path))
File "/home/tb/Desktop/tensorflow/tensorflow_src/./configure.py", line 747, in get_ndk_api_level
api_levels = sorted(os.listdir(platforms))
FileNotFoundError: [Errno 2] No such file or directory: '/home/tb/Android/Sdk/ndk/25.0.8775105/platforms'
I've tried compiling it with bazel build -c opt //tensorflow/lite:libtensorflowlite.so --fat_apk_cpu=arm64-v8a which did in fact built the .so file, but when I try to build the code it says C/C++: ld: error: undefined symbol: tflite::impl::Interpreter::Invoke(), I did run my project on linux and it works fine, android uses a similar if not the same cmake file so I think the .so is broken.
What should I do? Does anyone have a link to, preferably official, pre-built tflite aarch64 / arm64-v8a .so file for c++?
Update: I've opened an issue detailing everything I've tried up to now.
I just updated from Monterey 12.5 to 12.5.1.
However, after that Android Studio (android-studio-2021.2.1.16-mac_arm.dmg) no longer starts.
I get the following error message:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x0000000107d72e38, pid=92768, tid=259
#
# JRE version: OpenJDK Runtime Environment (11.0.12) (build 11.0.12+0-b1504.28-7817840)
# Java VM: OpenJDK 64-Bit Server VM (11.0.12+0-b1504.28-7817840, mixed mode, tiered, compressed oops, g1 gc, bsd-aarch64)
# Problematic frame:
# V [libjvm.dylib+0x6d2e38] AccessInternal::PostRuntimeDispatch<G1BarrierSet::AccessBarrier<1097844ull, G1BarrierSet>, (AccessInternal::BarrierType)2, 1097844ull>::oop_access_barrier(void*)+0x8
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /Users/Tom/java_error_in_studio_92768.log
[thread 74759 also had an error]
[thread 91395 also had an error]
#
# If you would like to submit a bug report, please visit:
# https://bugreport.java.com/bugreport/crash.jsp
#
The content of /Users/Tom/java_error_in_studio_92768.log is a little long to post here, but does not give any deeper insights (at least for me).
Anybody having the same problem?
I updated to the release candidate of the next version called "Dolphin" which is the file "android-studio-2021.3.1.15-mac_arm.dmg".
Now it works again as it should.
i'm using linux mint. now i'm facing this problem i can't even find solution.
hope someone help me here.
System configuration.
*Operating System : Linux Mint 19 Cinnamon
Cinnamon Version : 3.8.7
Linux Kernal : 4.15
Processor : AMD FX(tm)-8150
RAM : 8GB*
here is crash details.
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f8550bde9ca, pid=20860, tid=0x00007f84cb8ce700
#
# JRE version: OpenJDK Runtime Environment (8.0_152-b01) (build 1.8.0_152-release-1024-b01)
# Java VM: OpenJDK 64-Bit Server VM (25.152-b01 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# J 46464 C1 com.intellij.openapi.editor.impl.view.LineLayout$SingleChunk.getChunksInLogicalOrder()Ljava/util/stream/Stream; (21 bytes) # 0x00007f8550bde9ca [0x00007f8550bde4c0+0x50a]
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
#
Hi i have faced the same problem,And finally i found the solution for it.Actually in my case while i am try to checkout the subversion in android studio fully crashed.I mean it was closed unexpectedly.I spend the lot of time of it.
Go to your home directory like home/vijay(your path) then Ctrl + H.It will show your all hidden files in there just delete the following files.
.android
.java
.subversion
.gradle
Note : Do these stuffs before open android studio.
Then open android studio it will work sure.
Don't worry if you delete also it will create automatically.
Hey guys I am having issue with eclipse. Every time when I want to import some library lets say org.opencv eclipse crashes. It crashes in the moment when I write dot org(dot)opencv. Have you seen somthing like this? Can you help me to fix it please?
I am using Ubuntu 14.04,
adt-bundle-linux-x86_64-20140702.
I also recorded a video [http://tinypic.com/r/2nm15ip/8][1].
Thank you for your help.
I tried it open in terminal and of course it crashed but i got some answer:
libEGL warning: DRI2: failed to authenticate
NOT SANDBOXED
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007fc79f6052a1, pid=9886, tid=140499127801600
#
# JRE version: Java(TM) SE Runtime Environment (7.0_72-b14) (build 1.7.0_72-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.72-b04 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libsoup-2.4.so.1+0x6c2a1] soup_session_feature_detach+0x11
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/nemesis/NEW_Android_Development_Enviroment/adt-bundle-linux-x86_64-20140702/eclipse/hs_err_pid9886.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
And also I found out that in my eclispe folder has been created error report.
I uploaded it here:
http://www.filedropper.com/hserrpid32252
After 6 hours I have found solution....
To solve this issue, try to put this line (slightly different from -Dorg...)
org.eclipse.swt.browser.DefaultType=mozilla
at the end of this file
eclipse/configuration/config.ini
I am so happy and angry at the same time.
Thanks for help to everyone :)
I have a really simple helloworld.cpp program
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
And I'm trying to compile it for android x86 with the cross-compiler from the toolchain:
/Users/me/android-ndk-r8/toolchains/x86-4.4.3/prebuilt/darwin-x86/bin/i686-android-linux-g++ helloworld.cpp -L "/Users/me/android-ndk-r8/sources/cxx-stl/stlport/libs/x86/" -lstlport_static
However, I get errors:
helloworld.cpp:2:20: error: iostream: No such file or directory
Any idea why?
Check the documentation.html file included with the NDK, under "Standalone Toolchain". It says that if you invoke the compiler in this way you won't be able to "use any C++ STL". However it is possible, as the documentation explains, if you first create a "customized" toolchain installation, using something like the following command:
$NDK/build/tools/make-standalone-toolchain.sh --platform=android-8 --install-dir=/tmp/my-android-toolchain --arch=x86
where $NDK is the path to your NDK directory. Note the --arch=x86 which means that the toolchain is prepared specifically for the x86 Android. This prepares what you need in one directory, including the STL headers and folders. You should then be able to use -lstdc++ to link against the STL (static version), i.e. something like:
/tmp/my-android-toolchain/bin/i686-android-linux-g++ helloworld.cpp -lstdc++
For a more complete explanation, please see the NDK documentation.
The NDK documentation is not entirely accurate, at least not currently. In fact, it states when using the prebuilt toolchain "You won't be able to use any C++ STL (either STLport or the GNU libstdc++) with it.", but this is out of date. I created a small hello world program using the include with the same error. It can be solved without creating your own toolchain though, which is nice if you don't want to have to add one more step to your configuration process and allows you to always use the latest SDK platform without creating a new toolchain every time.
The NDK ships with the source code for several versions of standard C++ libraries: GAbi++, STLport, and GNU STL. Each flavor comes with prebuilt shared and static libs as well. My example below will use stlport.
To use the stand-alone toolchain at its installed location, you can do something like this:
export CXX='$NDK_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++ --sysroot="$NDK_ROOT/platforms/android-19/arch-arm"'
This, for example, would set your CXX compiler to compile ARM on the OS X system using SDK platform level 19. This much you probably already knew. Also, you would want to export your CC, CPP, LD, AR, and RANLIB if you use it. I also personally create an envar for READELF.
To add support for C++ libs, you could do something like follows:
$CXX helloworld.cpp -I$NDK_ROOT/sources/cxx-stl/stlport/stlport -L$NDK_ROOT/sources/cxx-stl/stlport/libs/armeabi -lstlport_shared
Note that this will link the libstlport_shared.so which will now be required at runtime, so you may need to add a relative path to the command above to support that, depending on your APK structure. If you want to just test this simple case, you can just run this on the emulator as follows:
adb push a.out /data
adb push $NDK_ROOT/sources/cxx-stl/stlport/libs/armeabi/libstlport_shared.so /data
adb shell
# su
# cd /data
# chmod 777 a.out
# ./a.out
To get rid of the headache of dealing with shared library paths, you can also statically link the C++ library in by changing "-lstlport_shared" to "-lstlport_static". There are some consequences of doing this, as explained in the NDK Dev Guide. The biggest issue is due to having the static library linked in multiple places, causing:
- memory allocated in one library, and freed in the other would leak or even corrupt the heap.
- exceptions raised in libfoo.so cannot be caught in libbar.so (and may simply crash the program).
- the buffering of std::cout not working properly
A useful tool is also included to see what dependencies your program has, the readelf tool.
To see what other shared libraries your program requires, you can run the following:
$NDK_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-readelf -a a.out | grep NEEDED
Other cool standard tools:
addr2line - convert a stack trace address to a line of code
nm - Displays the symbol table
objdump - displays info on an object
i call one of the functions from gnustl after it runs fine from prebuilt aosp arm-linux-androideabi-gcc --std=c++11 and after crashing error i cant get a backtrace from logs or reason, my hope is turning to crossbuilt qemu-linux-user to run host compiled i686 binary on the arm, difficulty is interacting with crosshost libs aapt from adt always crashes on any other than platform specific libs, unless kernel module packaged update is possible...