In my project, I have one .aar file(Bundle of .so files which build on armebabi-v7a) and it will successfully build in the Android AOSP source tree. (Source tree is based on the arm64-v8a).
But I run the application, in the device, it will crash and shows the following error.
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader
Please help me to solve the below issue,
To pack .aar lib in the application apk itself.
Related
I'm writing an application which uses a library contained in .aar file. The archive contains .so files. The .aar file is added as a dependency. When I click Build -> Make Project everything is OK, I get 11 MB APK which contains the .so files. But when I click Run then a different APK is being built. It's only 6 MB and doesn't contain .so libraries so it crashes with java.lang.UnsatisfiedLinkError.
In the build log I see:
> Task :app:packageDebug
There are no .so files available to package in the APK for armeabi-v7a.
I am new to Android Studio. I am using Android Studio 1.3 because it has built in NDK support. I have a project that can be used as an application or as a library project. When I imported it to Android Studio as an application (and modified the gradle scipts as documented), it built the .so files and included them in the .apk output. When I modified it to be a library project, it is building the .so files, but not including them in the .aar output and hence they are missing in the final .apk. Should I have to do anything to inform it to put the .so files into the .aar? If so, what should I do?
Are you building your .so files by calling ndk-build or by using the gradle or gradle-experimental plugin ?
If your .so files are already built, you can just drop them inside src/main/jniLibs/ folders and they should get included into the .aar as well as the APK.
I've made an android library project that uses some native libraries.
I've made the jni wrapper and put the native libs (.so) in the libs// folders. The native libs are compiled using cmake, for armeabi, armeabi-v7a, x86 and mips.
I export this project to a jar and put this jar into a "normal" android project. I then export this project to an apk and can see that my libs are bundles into it.
However, when i install the apk, the libs corresponding to the device are not copied into /data/data/com.my.app/lib and obviously, running the app complains about not finding the libs (UnsatisfiedLinkError).
I've search through SO and everywhere i can but found no answer that solved my case.
i'm using Eclipse, btw
Thanks for your help
UPDATE
OK, i've read the doc in the ndk and seen the examples, and unfortunately, i can't see the solution.
The ndk build the c code into shared libs and places them into the appropriated location in the project. But it doesn't generate anything that says that the libs must be installed with the apk.
My goal is to provide an android library (so a jar), that can be included within an android application. I don't see the real difference between what i'm doing (compile the c libs using cmake and package the jni and java compiled classes into a jar) and what is done with android.mk
If you see what i'm missing, feel free to tell me (even if its obvious).
thanks
UPDATE
i've made a dirty hack: in the libs folder of my application, i've put the jar file containing my classes and my native libs and a copy of the .so files for each arch. Suprise, the libs are no installed in /data/data/com.me.myapp/lib
It seems to confirm that it's a packaging problem.
I export this project to a jar and put this jar into a "normal"
android project. I then export this project to an apk and can see that
my libs are bundles into it.
The issue is that the Android packaging system doesn't handle with binary assets in JARs. For your application project to find and include the generated .so files, you need it to reference the library project as an 'Android library project':
Did you call ndk-build command?
See description below for details.
http://developer.android.com/tools/sdk/ndk/index.html
You can build the shared libraries for the sample apps by going into /samples// then calling the ndk-build command. The generated shared libraries will be located under /samples//libs/armeabi/ for (ARMv5TE machine code) and/or /samples//libs/armeabi-v7a/ for (ARMv7 machine code).
I am trying to make a Live Wallpaper for android that plays an .mp4 video located on the device in android-asset (with the example I am using, it actually copies the file to the sdcard at runtime/doesn't matter)
I found this example
And using this post I was able to get my eclipse set up with NDK and building the project.
When building in eclipse using the NDK plugin I get this error in my problems window:
Description Resource Path Location Type
make: *** [libs/armeabi/libavcodec.so] Error 1 GLWallpaperVideoDemo-master C/C++ Problem
make: *** Deleting file `libs/armeabi/libavcodec.so' GLWallpaperVideoDemo-master C/C++ Problem
I get the same error if I try to run ndk-build from command prompt.
I downloaded the project from the link above and then imported into eclipse. I added the lib GLWallpaperService to the build path, and made sure my NDK was setup. Knowing that the lib folder changed to libs I also tried moving the GLWallpaperService to the libs folder, which didn't help.
The project builds without NDK just fine in eclipse but obviously errors when trying to run the wallpaper because the native libraries were not built.
How can I resolve this error?
The package you get by git clone https://github.com/frankandrobot/GLWallpaperVideoDemo.git is Linux oriented. The file jni\ffmpeg-android\build\ffmpeg\armeabi\lib\libavcodec.so and many others are simply symbolic links to actual files.
To make this all work easily on Windows, I suggest to go to the jni\ffmpeg-android\build\ffmpeg\armeabi\lib folder, and run
del *.so
copy libavcodec.so.52.99.1 libavcodec.so
copy libavcore.so.0.16.0 libavcore.so
copy libavdevice.so.52.2.2 libavdevice.so
copy libavfilter.so.1.69.0 libavfilter.so
copy libavformat.so.52.88.0 libavformat.so
copy libavutil.so.50.34.0 libavutil.so
copy libswscale.so.0.12.0 libswscale.so
The issue might be because of a corrupted so file. Try to build the ffmpeg library again or find another version. Because I have a different error in eclipse when I try to compile the project:
C:/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/arm-linux-androideabi-strip:./libs/armeabi/libavcodec.so: File format not recognized
And when I search for this error it seems like the error is because of a corrupted file: NDK prebuilt shared library file format not recognized
Or the library is not in a format that Android can use:
Error in linking C++ static library with android ndk(Error: file format not recognized)
I'm trying to build an app using a library packed in a JAR file.
When I call one of the functions I get this error:
Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing thelibrary.class
I've check the source code of the library and I think it crushes when loading some .so files ( System.loadLibrary("usb-1.0");
those files do exists in the JAR project under libs/armeabi (libusb-1.0.so)
I guess the .so files are not packed with the JAR, so how do I get them to be found in my project ?
(tried to copy them to libs/armeabi but the same exception is thrown....)
I do not get any link / build errors....
Thanks.
An ordinary JAR file will not work for distributing something that is dependent upon an Android NDK-compiled library. However, an Android library project can also distribute an NDK-compiled library.
but the real problem is that my app is going to be a library as well, and I don't know if I can make it a library while it is using other libraries
Assuming that "make it a library" == "make it an Android library project", this is fine, so long as projects attempting to use your library project also have access to the other library project.