I transitioned from using Eclipse to Android Studio. I discovered after hours of battle that the project.properties file that used to be generated by Eclipse was necessary for me to build the JNI component of my app.
I'm just looking for someone to explain:
Why is this project.properties file necessary?
Is there a way I can tweak my Android.mk so I don't need it?
The project.properties file that I need has 1 line:
target=android-10
I am doing native window API calls in my JNI code.
Edit:
I just wanted to add...without this properties file my symptoms include not being able to locate header files and libraries, such as this sample output:
Compile++ thumb : videolibs <= video_codec_jni.cpp
/Users/spartygw/vpdsec/src/applications/VideoSend/jni/video_codec_jni.cpp:11:35: error: android/native_window.h: No such file or directory
/Users/spartygw/vpdsec/src/applications/VideoSend/jni/video_codec_jni.cpp:12:39: error: android/native_window_jni.h: No such file or directory
In file included from /Users/spartygw/vpdsec/src/applications/VideoSend/jni/../../../libraries/VideoCodec/H263.h:13,
The easiest workaround would be to put this one-line file in jni/.. directory manually.
You can also add APP_PLATFORM=android-10 to your ndk-build command line.
You can also set it in your Application.mk. Unfortunately, you cannot set this in Android.mk.
Related
I'm working on an Android NDK project in which I have to use functionalities which needs c++ header files such as iostream , sstream , etc,. I have already did this in linux by adding /usr/include/c++/4.7.. in C++ Paths & Symbols tab. But still din't find a way to do this in Mac. I have tried the following:
I have simply included iostream header #include<iostream> , it shows the following error while build using ndk-build, fatal error: iostream: No such file or directory
Added android-ndk-r9/sources/cxx-stl/gnu-libstdc++/4.8/include in C++ Paths and Symbols->Includes tab->cpp , It doesn't change anything.
In my Android.mk file,
LOCAL_C_INCLUDES := android-ndk-r9/sources/cxx-stl/gnu-libstdc++/4.8/include
it gave the following error:
fatal error: bits/c++config.h: No such file or directory
I have also tried adding prebuilt shared library in Android.mk file , which gave the same error.
Then made a search for the file bits/c++config.h , copied it in to the actual place it is looking for, it shows the same error for osdefines.h , I have copied all the files it is looking for , atlast it asked for bits/memoryfwd.h , but I can't find the file anywhere in my Mac.
What is the actual problem here? What should I do to include those headers in cpp files in my Android NDK project?
Create a file called Application.mk in the directory projet_dir/jni/ (so it is projet_dir/jni/Application.mk).
Add the following line to that file
APP_STL:=stlport_static
If you run into a shared_ptr error, try using APP_STL := gnustl_static instead.
(I had this exact same issue on Linux and the above resolved it for me.)
I'm making a Unity3d plugin for this c++ library for Android. Ive gotten it to work in windows by opening the visual studio project the library makers provided, adding a new .cpp file to it with my API code and building to a dll.
I'm wondering now how I can add this new .cpp file to the library and build it for Android.
So far I have installed the Android sdk and ndk on a machine with ubuntu and successfully built the original library using ndk-build (as per these instructions)
I'm guessing it is not as simple as copying my .cpp file into the folder and building as there are AndroidManifest.xml files and so on.
The AndroidManifest.xml file is not pertinent for an NDK build.
You will need to find the appropriate Android.mk file. You may need to add the file name into the LOCAL_SRC_FILES in that make file, although they may have it set up to compile all the .cpp files in the directory or something more intelligent along those lines. It is, after all, a regular make file.
See here for info on the Android.mk file specifics.
Edit:
I suppose I should add that it would be the LOCAL_SRC_FILES preceding the relevant include $(BUILD_SHARED_LIBRARY) for the library you intend to build. Each make file may contain an arbitrary number of targets, although in the simplest case it's usually one make file to build a library.
I have followed tutorials to implement NDK functionality in a test project. Created jni folder and added .mk and .c file. NDK is linked and the C++ make file has link to ndk-build file in NDK folder.
On building project i am getting this error :-
Build of configuration Default for project HomeTestingNDK **
/home/falooka/adt-bundle-linux-x86-20130917/ndk/ndk-build all
Compile thumb : HomeTestingNDK <= native.c
make: /home/falooka/adt-bundle-linux-x86-20130917/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc: Command not found
make: * [obj/local/armeabi/objs/HomeTestingNDK/native.o] Error 127
Build Finished **
Now the issue is that 'make' is going for arm-linux-androideabi-gcc while this file doesn't exist in the folder and instead there is arm-linux-androideabi-gcc-4.6. Now I am totally struck how to solve this issue after googling for a while now.
Thanks in advance.
I was able to resolve my issue by following these multiple steps :
1) For some stupid reason, arm-linux-androideabi-gcc was missing in the ndk directory. So i tried re-installing the zip and extracted it inside the home folder instead of my drive to avoid ownership errors. Now file was there and this error was gone !
2) Then i was getting "Android NDK java.lang.UnsatisfiedLinkError: findLibrary returned null" error which had something to do with libraries missing. After reading some posts, it was prominent that the libs/ folder in project directory should have .so files which were not there. I am using OpenCv with my project so i updated the environment links and put explicit path to ndk-build file in 'make' to make sure it finds ndk-build.
3) I also did this : https://stackoverflow.com/a/7646921/1016544
So finally its compiling and shows building of .so files before installing and runs perfectly.
I am getting error while trying to build android ndk project:
error: jni.h: No such file or directory
But: locate jni.h command show me:
locate jni.h
/usr/lib/jvm/java-6-openjdk-i386/include/jni.h
What is wrong in my actions?
EDIT:
If I hardcode it in the source code it work but I have a lot of files that are using this header. What I need to do that all my files can see /usr/lib/jvm/java-6-openjdk-i386/include/jni.h
?
Try setting the installation location of your NDK in PATH in your rc file, let's say ~/.bashrc:
NDK=/path/to/your/ndk/location
export PATH=$PATH:$NDK
Source the rc file by running source ~/.bashrc.
Now when you run ndk-build, it will setup the whole build environment for you by running make command against a bunch of make files under $NDK/build/core, it will setup correct header file search path for your project depending on the android:targetSdkVersion setting in AndroidManifest.xml.
The jni.h needed by your NDK project is located under $NDK/platforms/android-14/arch-arm/usr/include.
Android NDK projects will not use any JNI header files under your JDK installation, files under /usr/lib/jvm/.... will never be touched.
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)