How to build android-gif-drawable lib to .so file - android

In the android-gif-drawable lib source, it doesn't contain any Andorid.mk or Application.mk file, as the result when I use the ndk-build, it returns some error like this
Please define the NDK_PROJECT_PATH variable to point to it
I am really poor in ndk, is there anyone could help me?
You may wonder why I need to build the so file, the reason is that: in my project, I already have another .so file lib, it seems that when I use the gradle to add the gif lib(compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.6') my another ".so" file can't be found, and my app error.
So I now try to build the gif lib to a ".so" file, I hope this way could be help.

The inclusion of android-gif-drawable shouldn't lead to the removal of your other .so files. Can you post your current build.gradle file ?
Amyway, you can directly get android-gif-drawable .so files from the jni folder that is inside the lib's .aar: https://bintray.com/artifact/download/koral/maven/pl/droidsonroids/gif/android-gif-drawable/1.1.6/android-gif-drawable-1.1.6.aar
Else, in orer to rebuild it yourself, you can can clone the github repo and build it using gradle. If you want to use the ndk-build command, you'll have to write the Makefiles.

Related

How to call a Android ndk build .so file in another Android application?

I have an requirement which i have to build .so file using NDK build in Android and I have to call some of the methods from the .so file in my other Android application.
What I have tried so far.
I have taken the .so file from the lib folder of my Android project and put in my other application libs folder where I should call that .so file. I have used the below code:
Note: I am using ECLIPSE
static {
System.loadLibrary("NativeCode");
}
and also tried with full path of library
static {
System.loadLibrary("fullpath\NativeCode");
}
both the cases its giving unsatisfiedLinkError that mean it's not getting the path of my .so file.
You need to have your libNativeCode.so in the jni folder of your root, and not in the libs or lib folder
Here is a nice tutorial : http://www3.ntu.edu.sg/home/ehchua/programming/android/android_ndk.html
Alternatively, you can use following commands:
adb shell
$echo $PATH
What it will do is display a path like this :
/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin
You can have your .so in any of these folders like /system, /system/bin, /system/sbin. (Remember, but you would need to manually copy it, and it is not a good idea to do so for an app)
Edit :
You can not call any JNI function in your app, because the signature. You need to have a JNI wrapper (a .so JNI lib that in turn uses the .h header file to call the JNI function of the other library). This is because JNI is very sensitive to signatures. So, as I recommended earlier, follow the tutorial !
In order to get your .so library to be loaded using loadLibrary() you'll have to copy the libNativeCode.so lib into the jniLibs/architecture folder.
The folder should be located under src/main/jniLibs/armeabi-v7a of your Android Application module (assuming you're using Android Studio).
After you copy the libraries, add the following line to your build.gradle located at the app module folder:
assert file("./src/main/jniLibs/armeabi-v7a/libNativeCode.so").exists()
After you'll complete the above steps it should load the lib properly.
If the libNativeCode.so is located at the wrong path, the Gradle build will fail.
Good luck,

Facebook Conceal .so files not uploading in Android Project

I cannot get the Conceal Library to work, it may be something I am doing wrong, I wish the instructions were a bit more detailed.
http://facebook.github.io/conceal/documentation/
I have added the crypto.jar to my project, and then the instructions tell me to add the files armeabi/*.so to my jni folder.
"Add a dependency to crypto.jar from java code using your favorite dependency management system, and drop the .so files in libs.zip into your jni/ folder."
I don't have a jni folder, since my project is a normal Android progect, not an NDK project. How can I get this to work, I tried creating the folder and adding it to the build path, but it did not work. I am completely lost on this. In my source code I am loading the libraries like this:
static {
// Load Facebook Conceal Crypto Files
System.loadLibrary("libconceal.so");
System.loadLibrary("libcryptox.so");
}
then the instructions tell me to add the files armeabi/*.so to my jni folder.
That's a bug in their documentation. Pre-compiled .so files will go in libs/. So, you should wind up with libs/armeabi/*.so.
I tried creating the folder and adding it to the build path
That is almost never the right answer and can seriously screw things up, so I recommend that you reverse that step.

Add .so file to android solution

I don't know how to use .so files in my project. So I downloaded the ffmpeg.so file and now I need to add it to my solution so that I can convert video formats on my device but I do not know how. I tried finding tutorials on the internet on how to add this file but nothing seems to work for me.
Do I still need the Android NDK to compile my C code as I have the .so file.
Any good tutorials how I can add this library to my solution?
Put the file named libffmpeg.so into libs/armeabi subdirectory of your project. You don't need NDK if you don't have C/C++ sources of your own.
A mistake that happen sometimes is that the Android name expectations are not met. The name must start with lib and end with .so.

How to add a .o file to an Android ndk build

I have a .o file for a 3rd party library. I do not have the .c files for it, nor can I get access to them. Normally this isn't a problem, I would just add this to the list of files to link in. But I can't find a way to link in a file without compiling it in the NDK without altering the build scripts. Any suggestions?
I found an answer. Pain in the neck, but it works. I had to turn my .o file into a .a file via the program ar, then create a new static module in my Android.mk file to turn it into a library that android could link via LOCAL_STATIC_LIBS.

Creating a product SDK: How do I add a native lib (.so) and a jar with the SDK I am creating?

I am creating a widget that we will provide to developer end users and it consists of a .jar and a native library (.so) built using the NDK. The JAR has a JNI interface to the dynamic library.
It's very clear on how to include an external .jar in a project but not how to include a dependent dynamic library.
How do I package up and build the .jar and .so? What are the best practices here?
I can create the JAR file using the JDK's jar command. Do I need to run dx.bat on the jar to convert to Dalvik bytecode?
I need to create a sample project showing the widget in action. How do I include this .jar and .so in a sample project that demonstrates how to use the widget?
I spent some time on this, and i just can't understand why isn't this written on wikitude documentation.... anyway follow this changes!
go to windows/preferences/android/build
uncheck the first and the second option
extract files from wikitudesdk.jar with winrar as if it is an archive, search libarchitect.so and copy it in /libs/libs/armeabi/
add wikitudesdk.jar to your build path
You should use the standard build tools included with the SDK for this. If you include the .jar files you need in the /lib directory of your project, the ant build process will convert the included class files to Dalvik bytecode format and include them in your classes.dex file for the app. Add a build.properties file to your project root as well, with one line:
external.libs.dir=lib
Depending on the version of your SDK and configuration of it, you may need to place the jar in libs rather than lib.
As for the .so, I presume that it's properly compiled using the Android NDK, or using a build script that uses the proper compiler and compiler flags that are required to successfully link the shared object on Android. If this is the case, you can include the .so file in libs/armeabi and they will be added in the jar as well. Furthermore, the dynamic library loader will know to look in this location in the .jar when you actually try to load the library from Java code.
Using ADT 12, I accomplished this by doing the following:
1) Export JAR from your library with the SO file using Eclipse. Make sure you exclude AndroidManifest.xml. This will include source code and other data, so if you are distributing, you'll want to strip these unnecessary bits out using any ZIP utility.
2) Create a directory in your App's source tree (I use "lib" directory) and copy your library JAR to it.
3) Right-click project in Eclipse and select "Configure Build Path". Add JAR and point it to JAR inside your App source tree.
4) In your Eclipse preferences, select Android/Build section and uncheck "Automatically refresh Resources and Assets folder on build". You will notice an option below that says "Force error when external jars contain native libraries." There is an ADT bug, which will supposedly be fixed in R17, which uses the wrong setting. Once it is fixed, you will use the "Force error" one (make sure it unchecked).
5) Once you build your app APK, you will have a libs/armeabi/libXXXX.so file. This will not be automatically unpacked on install. You will need to write code to extract it from your APK file into your data directory, then use System.load on the .so file in your data directory.
I have bidirectional JNI calls going from the dynamically loaded file, and even use dlopen() on it to do my custom plugin registration stuff.
Add the below lines to android.mk.
include $(BUILD_PACKAGE)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := alias:libs/your.jar
include $(BUILD_MULTI_PREBUILT)

Categories

Resources