Importing Android NDK projects (to decode OGG) - android

I am trying to decode OGG files in Android using an NDK project (I've tried a few). No matter which one I try, I always get an error similar to this when I build:
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load videokit: findLibrary returned null
I'm very new to the NDK (obviously) so I'm not sure what I'm doing wrong. All I want to do is to be able to set the playback rate of an OGG file.

The java part of the code links to a shared library object (.so file), which is obtained by compiling the C++/NDK parts of the code with ndk-build. In this case, your app is not able to find the right .so file to load. Here are a few things you could check for -
Very basic check - did you run "ndk-build" inside the jni folder? If you didn't, no .so file is generated - eclipse will still compile your project, but it won't work.
If your project root directory is PROJECT, check $(PROJECT)/jni/libs/armeabi or $(PROJECT)/jni/libs/armeabi-v7a - either or both of the locations should contain a .so file once you are done with the "ndk-build" command.
Check that somewhere in your java code, you are invoking "System.LoadLibrary" on this .so file.
I think it should be "System.LoadLibrary(videokit)", but I am not sure.

Related

Android Library unsatisfied link error with jar file

I have one project that includes a sample app, and a module that we'll call the sdk that I created that I will eventually package up as an .aar file when all is complete. The sample app tells the sdk to run a service. This service requires the use of external libraries that have been packaged as a .jar file that includes .so files. The issue is that every time I try to load the libraries, I get an unsatisfied link error saying that the .so file does not exist and therefore cannot open the library. I'm not quite sure if I'm placing everything in the right place as the error says. If I am missing a step, I was hoping someone could help point me towards the right direction. Below I'll show the file structure of my project as well as what I'm doing to try to open the library.
File Structure
`- MY PROJECT
- My Sample App (com.mine.mysampleapp)
- build
- src...etc
- SDK (separate module) (com.mine.mysamplesdk)
- build
- libs
- my-lib.jar
- assets
- arm64-v8a
- my-lib.so
- armeabi-v7a
- my-lib.so
Library Loading Code
System.load(context.getFilesDir() + "/my-lib.so");
What I'm not understanding is that the .so file lives inside the sdk but the error message:
dlopen failed: library "/data/user/0/com.mine.mysampleapp/files/my-lib.so" not found
shows that it's looking for the file in my sample application.
If you're trying to package as an AAR, those have built in support for JNI libraries: https://www.codepool.biz/build-so-aar-android-studio.html
Rather than putting the libraries in the assets directory and trying to assemble the System.load path yourself, put them in that directory and then you can just System.loadLibrary("my-lib") (note that System.loadLibrary won't actually let you open a library that isn't prefixed with "lib", so you need to rename your library for this to work).

Android Studio - Native method not found - Include .so file, missing jni function option

I am working on a Android fingerprint project with JNI. I have some source of the project, but i only have .so file and the .java file of the source. how to resolve missing jni function option and how to use native method
i got this answer....i explain when call this path then use actual package path..like my project path is com.aadhar.startek.fm220 then create java class which name is tstlib..i use difference path when error is occur...like my path is com.ashishnewproj.aadhar.startek.fm220....so every time is error is occur.....so keep on mind when use .so file then notice allready is use sdk path will use actual sdk path....not change manually....

Error 1 libavcodec.so File format not recognized Android GL Live Wallpaper

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 got the error on sample project "Hello Word" on android - cocos2d

I have eclipse 3.7, cocos2d-1.0.1-x-0.9.2, android-ndk-r7.
When I have create sample project but, it will get error "FORCE CLOSE"...
So is there any other thing i want to include on the project ?
Your main application has a load static library method that is pointing to a nonexistent library, which means it has not found it. Recheck your makefiles for the correct module name. Also make sure they have compiled correctly with NDK beforehand and the .a and .so files are in the lib folder.

Questions on how the build .c files

I have been trying to implement the API for the serial port found the the below web page. I am a beginner in all this and I am sure about what I am looking at:
http://code.google.com/p/android-serialport-api/source/browse/#svn%2Ftrunk%2Fandroid-serialport-api%2Fproject%2Fjni
Questions:
1) The .c files are built how? Do I need to download the NDK? I assume the .c file is run directly by the virtual machine, or what? Or is the executable for the .c the file in the libs directory? If so, how do I utilize the libserial_por.so file?
Thanks!
The .c files are built into a library by running ndk-build in the project directory. You need the NDK.
The .c files are not run directly by the virtual machine, but rather a library is created in the libs directory, which is then loaded along with the SerialPort class.
To use the library, just use the SerialPort class which already has bindings to the library.
C files will be compiled to an ARM binary library with the extension .so by the NDK. Take a look at the NDK Documentation, section "Getting Started with the NDK", to find out how to use it.
Basically, you place your .c files in the jni directory, change Android.mk to specify how to compile them, then run ndk-build to build the library. The resulting lib<name>.so will be placed in the lib directory. You then use your library in the Java project with System.loadLibrary('<name>').
This of course means the library must have a JNI interface for you to be able to use with the Java application, since Android doesn't support JNA yet.
I see though that the code you pointed out is an Android project. To run it, simply run ndk-build in the project directory to build the library, then run the project in an emulator.

Categories

Resources