How to include a C++ project in my own in Android - android

as per the title i want to include a C++ project in my own project in Android Studio.
I tried copying all the files in my /cpp folder and manually including them into my MakeList.txt, but i got numerous compilation errors, because some system library is missing (such as files).
The project i would to include is this.
Is there a method to include it in my app?

Related

JNI folder is not picked up by Android studio after headers are generated

I am working on building an Android Library which is part of a larger Android app project. I am using Android Studio.
I created the Android library as a module in the Android app project. I created my native methods, and then I put the .class through javah -jni and I was able to see the jni folder created and the header file generated.
However, Android Studio is not picking up the jni folder and showing it in the project view.
Anybody have any idea, what am I missing?
After hours of looking through docs, and posts, and tutorials, I remembered to check the simplest of things. Make sure your jni folder is in src/main

Linking with native SO file present in included library project of Android

I am working on a project in which it has dependency on another library project. Library project has both java files and native SO files.
Accessing JAVA source files (APIs) from the Android project java source doesn't have any problem. But, my native code is dependent on native SO files present in the included library project of android as well.
Library Project Android Project
--------------- ---------------
src/Java files <-- Java files
libs/.so files <-- libs/.so files
.so files are part of the included library project. How can my current Android project native code try to use .so files of the included library project. Currently I am getting linking error of undefined reference to all the functions which are part of the library/libs/.so files.
Please let me know if any one has faced/resolved similar type of issue.
You probably have both projects imported into your Eclipse. But ndk-build knows nothing about Eclipse. If the library comes with its own .mk file that defines PREBUILT_SHARED_LIBRARY, it would be even better. One such example is OpenCV which includes sdk/native/jni/OpenCV.mk file.
But you can simply add path to the .so files to your Android.mk, e.g. put the following lines in the end of your file:
include $(CLEAR_VARS)
LOCAL_MODULE:=LibraryProjectSO
LOCAL_SRC_FILES:=/LibraryProject/libs/library.so
include $(PREBUILT_SHARED_LIBRARY)
Now you can add LibraryProjectSO to the list of LOCAL_SHARED_LIBRARIES.

Build native library and JAR at the same time

I am trying to build a JAR file that I can import and use it for other android projects.
I created Android project that contains java code (src/main.java) and it calls bunch of native code I wrote (Using System.loadLibrary(...))
Under jni folder, I have bunch of C/C++ codes, for instance jni/sample/sample.cpp.
My question is that when I export this project to JAR, can I build native library at the same time?
In other words, do I need to have pre-built .so file before exporting to JAR file?
My goal is when I export or something like that, it will do:
Build C/C++ code and create .so files --> Build .java ---> JAR
at once.
If you are using Eclipse, you can create a "Launch Group" in your debug/run configurations. That way you can include your Java build and an Android Native Application build in one configuration.
If you are looking to move to a more sophisticated build system, you should look into Maven. It is considerably more complex than the plain old debug/run configurations, but it is much more powerful. It includes an apklib packaging to build libraries for Android. There are a few quirks with using the NDK in an apklib, but reasonable project design can avoid most problems.

Building and including an external module in an Android app

I would like to include this plist parser module in my Android application, ideally without just copying the entire module source into my source tree (if that would even work).
I have successfully added the module as a project into Eclipse (3.7.0) and resolved errors by fixing the build path to include Android 2.1, which is what I am using. However, now I'm stuck. All of the information on using external libraries with your Android project I can find expect you to have a JAR of the library, but I only have this source code. I can run the plist parser module as an Android application, which appears to compile an .apk, but that doesn't actually do anything because it's not a standalone application. Any options to just build the module without running it are greyed out in the Eclipse interface.
How can I either build this module into a .jar for inclusion, or include it in some other way?
Edit: In order to clear the errors in the module after I added it to Eclipse, I followed the instructions in this answer.
You can either convert the whole thing to a library project or simply include the source code in your app's project. To create a library project, you can import the project from github, and after you get it compile, remove any activities, go to the project's Properties->Android and check the 'Is a library' check box. Then add it as a dependency to your own project.

Adding prebuilt library to android apk

I have built a dynamic library in android using android build system. This library provides jni interface for functions inside it. Now I want to include this library in an application (.apk). I am using eclipse for application development. Now, how can I use the prebuild dynamice library (.so) in my application ? I tried putting it in a lib folder in my application but it is not working.
Any pointers are appreciated.
I am not using ndk to build my .so.
Since you write 'so' I think you're using NDK. If you're using NDK I don't know the answer.
If you're using the "Java" SDK, then in your library project go to Properties -> Android, and Check "Is Library". In your "apk" project, go to Properties -> Android -> Add . And your Library project should be available.
Also, any Library added in the "Java Build Path" Menu (again, in project properties) should be available in the APK in the end.
I know it's slightly old, but have you checked in the built APK to see if your .so library is there? Should be in the libs/armeabi folder.
Also, your .so file should be in lib/armeabi folder in your eclipse solution. I'm guessing the armeabi bit depends on which processor your .so file is build for.
Also, I know that if your library isn't called lib[name].so, it won't get copied when the apk is installed on the device. So:
libfoo.so copies
foo.so doesn't copy
foo.so doesn't copy
Also, you can use DDMS (its a view in eclipse) and it's file explorer to see if it's been copied to your device. It should be under data/data/[packagename]/lib.
Hope this helps a bit!
Andy.
I hit this same problem while building Qiqqa for Android. Under your eclipse android project, make sure you have a libs directory (not that it is plural libS not singular lib). Inside that create the armeabi/etc subdirs with their respectibe .so files.
Then when you build, eclipse will automatically pick up this libs directory and create the corresponding lib in your apk. System.loadLibrary("XXX") will then resolve to libXXX.so on your correct architecture...
Cheers,
Jimme

Categories

Resources