NativeActivty will not start - Unable to load native library - android

I created another question because all of the others were answered with a solution that was similar but unrelated. I have also ensured that it's not a symbol stripping issue.
I'm getting the dreaded error:
D/AndroidRuntime(16487): Shutting down VM
W/dalvikvm(16487): threadid=1: thread exiting with uncaught exception (group=0x41b1b700)
E/AndroidRuntime(16487): FATAL EXCEPTION: main
E/AndroidRuntime(16487): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.test/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/app-lib/com.test.test-1/libtest.so
E/AndroidRuntime(16487): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
E/AndroidRuntime(16487): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
...
Everything compiles and links just fine.
I also have app_dummy() and it's producing it properly as when I run with objdump I get it:
001186f4 g DF .text 000001a4 ANativeActivity_onCreate
If it matters, using vs-android with toolchain 4.7.2, targeting 2.3.3 (android-10), for armv7-a. I have libraries that I include appropriately, and end up fully linking.
My one theory, which I'm still unable to prove, is that there are some .so files that I also need to include with the apk. I assumed that the external libraries (so) would be merged with my own. If this is not the case, this would likely explain the issue at hand.
I am not using any makefiles directly - vs-android is handling most of it. I only have access to some .xml and .property files.

It seems this error will come up ambiguously if there are dependant libraries that cannot be found. Since I'm using vs-android, I'm still unsure how to even get the external .so files to properly be included in the apk under the /libs/ path.
The only solution to include external .so files is to somehow get the libraries into your apk and link them manually within code, call System.loadLibrary() on the Java side before your native library gets loaded, or have one native library load the libraries and then launch your main library.

Related

Pure NativeActivity: Unable to start activity; Unable to load native library

Once the APK launches, I get this error:
E AndroidRuntime: java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.engine001.test/android.app.NativeActivity}:
java.lang.IllegalArgumentException: Unable to load native library:
/data/app/com.myapp.test-2/lib/arm/libLauncher.so
Even the most basic NDK app seems to have this issue, even without linking to other .so. Using latest Tegra/NDK/etc... tools.
Entire system worked fine until I upgraded systems and updated tools.
EDIT: I have tried to install the previous version of the tools I had working (ndk r12b). I have also tried literally copying my old NVPACK and setting things back up to no avail.
I am not sure what to include. This is a very large project currently in use.
I cannot include actual Java code as I modify the APK after and this cannot be done if a DEX file is produced, which is what Java entails. So to be clear, using a pure NativeActivity.
Unable to load native library: /data/app/com.myapp.test-2/lib/arm/libLauncher.so
Newer NDK does not support this path anymore. You need to ensure that your ABIs are x86, x86_64, armeabi-v7a, arm64-v8a. i.e. paths should be something like below:
/data/app/com.myapp.test-2/lib/arm64-v8a/libLauncher.so

Why does my Android app look for /data/app/package_name-1/lib/arm/libLibrary.so instead of using the folder armeabi

I get this in logcat when trying to load a library compiled only for armeabi (assuming that it is the fallback for all arm* abis).
08-14 09:43:51.516 7486-7486/package_name E/art﹕ dlopen("/data/app/package_name-1/lib/arm/libLibrary.so", RTLD_LAZY) failed: dlopen failed: unknown reloc type 160 # 0xa3725ab4 (82108)
Due to practical constraints, I cannot test this on a rooted device, so all I know is that the /data/data/package_name folder has a symlink lib -> /data/app/package_name-1/lib/arm
I know that this is not a device specific problem, since I have used native libraries earlier on the same device (with a different app, but same architecture earlier).
Can someone help me out here? Really confused on what exactly is happening.
I use gradle build (Android Studio), and the libLibrary.so is present inside the lib/armeabi folder within the apk on unzipping it.
The question was only partially correct. The true problem was with the relocation type (of which I had no idea initially).
Relocation errors usually occur when the loader and the object file do not understand the same format.
In this case, the .so file was built with c++_static instead of gnustl_static. Android/NDK provides most c++11 functionality, but some of them are not fully operational/functional like std::to_string which led me to try c++_static.
Hope this helps someone else out there who still has hairs left on his/her head.

Create a .jar from a .dll

I’m currently trying to create a .jar from a .dll, in order to use it on Android applications. I’m quite new with this technology, so I’ll tried to be as clear as possible.
I have 3 distinct parts:
A first .dll which is an API, in C++ and developed with Visual studio 2013.
A second .dll that makes the link between my API and Java code (using JNI, so this is my native library), also developed with Visual studio 2013.
And my Java code that loads my native library and that implements native functions from API. I use eclipse IDE for that stuff, because I read somewhere that was the easiest way to create a .jar.
This part works pretty well. I created a main test and I get all the information from the API in Java. But now, I would like to create a .jar file that I can use on Android and here comes the crows...
I tried many ways, from the simple .jar export, to the One-Jar method, but nothing worked. I always have a link error on my android platform (functions are recognized on the .jar, but their implementations are not).
So here is my question, how to create a kind of ‘static library’ in a .jar that I can use on Android?
I hope I was clear enough, don’t hesitate to ask me more details.
Thank you for your help!
EDIT:
I tried with an Android Library project and my problem is always coming from my loadLibrary() function:
public class MyWrapper {
static {
System.loadLibrary("MyWrapper");
}
public static native int getNegative(int p_number);
public static native int getPositive(int p_number);
}
Every things works fine on my library, but when I use it in android application, I always get this error:
01-27 11:31:29.565: E/AndroidRuntime(7089): FATAL EXCEPTION: main
01-27 11:31:29.565: E/AndroidRuntime(7089): Process: com.example.wrappertest, PID: 7089
01-27 11:31:29.565: E/AndroidRuntime(7089): java.lang.UnsatisfiedLinkError: Couldn't load MyWrapper from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.wrappertest-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.wrappertest-2, /vendor/lib, /system/lib]]]: findLibrary returned null
My library cound’t be created as static library, to keep the link on the .dll?
A .dll file is usually windows specific. If you're wanting to load native code on Android you'll have to look into using the Native Development Kit. The specifics of using the NDK is a bit beyond what can be explained here, but the Android Developer website provides a decent starting point at http://developer.android.com/tools/sdk/ndk/index.html
As for the jar itself, you may want to look into building an Android Library Project instead. This is essentially a means of packaging a jar with some assets (including native libraries) which can be used by an Android Application project.
Compile your librarie with ndk-build
Create an Android Library module
Create a Java class and JNI wrapper
Disable gradle for ndk-build and create Android.mk and Application.mk in the jni folder
Import the .so library and pre build it on the Android.mk
Invoke ndk-build manually and its done

libgdal.so android error: could not load library "libgdal.so.1"

My problem is the following: I have succesfully built GDAL 1.10.1 using an Android toolchain (CC=i686-linux-android-gcc, CXX=i686-linux-android-c++) that produces the following output libraries libgdal.a, libgdal.la, libgdal.lai, libgdal.so, libgdal.so.1, libgdal.so.1.17.1 in the output folder .libs (in the following I'll call this folder $GDAL_LIB_PATH).
I am trying to build a simple Android app (a simple widget application with a QPushButton named TestAndroid) using Qt 5.4 on Windows. If I don't use GDAL everything works fine and I am able to run my app on an Android emulator for all available platforms: x86, armeabi and armeabi-v7.
Nonetheless, if I try to use GDAL (ex. by simply calling GDALAllRegister() in the initialization of the app) and then linking to libgdal.so the application crashes with the following error:
E/art ( 1614):
dlopen("/data/app/org.qtproject.example.TestAndroid-1/lib/x86/libTestAndroid.so",
RTLD_LAZY) failed: dlopen failed: could not load library
"libgdal.so.1" needed by "libTestAndroid.so"; caused by library
"libgdal.so.1" not found
I have verified that the Android platform is the right one (x86), otherwise the linker would skip the wrong libgdal.so object.
I have included libgdal.so in the *.apk (generated by Qt) using ANDROID_EXTRA_LIBS *= $GDAL_LIB_PATH/libgdal.so. The other files libgdal.so.x.x cannot be included in the same way since Qt prevents it.
In order to avoid dynamic linking I have also tried to link my app with libgdal.a but many link-time errors appears (ex. undefined reference to 'atof')
I have searched on the web but I have not found a solution to my problem.
I am not constrained to use dynamic linking so, a solution to any of the following problems is good for me:
Is there a way to avoid the creation of libgdal.so.x.x files when building GDAL ?
Is there a way to include libgdal.so.x.x files in the *.apk file generated by Qt ?
How can I avoid link-time errors when linking the static library libgdal.a ?
Thanks in advance for any reply!
After several days of trials and errors (mainly errors) I have found a solution to my problem.
I'm writing it as an answer to my question so that it may be helpful to others.
The problem was during the link-time of GDAL. Briefly: the linker created the "real name" shared library libgdal.so.1.17.1 together with the links to it libgdal.so.1 and libgdal.so.
For some reasons (which I ignore) forcing the link to libgdal.so, the linker searches for libgdal.so.1 (which, in turn, would have searched for libgdal.so.1.17.1).
The workaround that solved my problem can be summarized in the following steps:
In the GDAL root, run the ./configure according to the desired configuration (see http://trac.osgeo.org/gdal/wiki/BuildingForAndroid) checking that libtool is ENABLED
Edit the created libtool file (e. g. with gedit) as follows:
replace the value of library_names_spec with library_names_spec="\$libname\${shared_ext}"
replace the value of soname_spec with soname_spec=""
Type make
In the output folder .libs/ the only libgdal.so will be created and now the link to libgdal.so seems to work fine.

android ndk mupdf build error

I am trying to make a project to read pdf in android phone.
So, I created the normal Android Project and installed the android-ndk-r6-windows.
And I built the 'libmibookreader.so' and set the native functions in my java class.
But after compiling my project I have a serious Error.
Caused by: java.lang.UnsatisfiedLinkError: Library mibookreader not found
Why this error caused?
I really don't know. I referenced the address of "http://flytgr.thoth.kr/blog/697421".
I followed down as the reference document described.
This is because your library was not loaded by the kernel. Are you sure that you placed your library inside the libs/armeabi/ folder of your project?
Check the logcat when you deploy your application, you should see some messages there that your library was loaded.
If you don't you could also try to use System.loadLibrary(libPath); to manually load your library.

Categories

Resources