I've made a tiny SDK for bitmap handling using JNI (link here).
It has only 2 projects : a sample project (demonstrates usage of the SDK), and the SDK itself .
The SDK project is an Android project, and it includes some C/C++ code within it.
For some reason, even though when I've created the project , everything went fine, now that I try to get the library project and import it to Eclipse, and then I open the CPP file I've made, I see plenty of errors on it, as such:
Why does it occur? How do I import the project correctly? Can I help whoever is using this to be able to import it nicely?
I've tried to create a totally new project with JNI and just copied (carefully) the files from my library, and it compiled fine, but that's not a nice way to import a project...
It defines a way for the bytecode that Android compiles from managed code (written in the Java or Kotlin programming languages) to interact with native code (written in C/C++). JNI is vendor-neutral, has support for loading code from dynamic shared libraries, and while cumbersome at times is reasonably efficient.
Using Android Studio 2.2 and higher, you can use the NDK to compile C and C++ code into a native library and package it into your APK using Gradle, the IDE's integrated build system. Your Java code can then call functions in your native library through the Java Native Interface (JNI) framework.
jni/libs folder is where your shared library files are built from the C/C++ sources. Your native code gets compiled and depending on the value you had set in your application.mk file for the parameter APP_ABI: = <all | x86 | armv7a | armeabi-v7 | mips>
This eclipse error happens often , and your solution (starting a empty project then adding the files) is the fastest work-around, and we all use it when it comes to this. Another solution would be to remove the c nature and Android nature and add again these natures to the project (often times this works as well).
When a new project is created, Eclipse will add it's natures and it's tool chains. If you import an old project, these toolchains / natures might be badly imported.
For a project containing c and c++ , you will need to have cnature and ccnature defined in your ".project" file. For android you need Android Nature. For compiling android, you will need to have com.android.gcc as the toolchain defined in your .cproject file.
Depending on the version of ADT / CDT / Eclipse , the value from the toolchains in .cproject differs, hence they aren't easy to import from machine to machine.
My guess is you have your storm of errors because the .cproject file was generated wrongfully .
EDIT
After Android Developer's further research, a faster way to bypass Eclipse's limitation caused by how native nature is added to a project can be done in the following steps:
delete from the ".project" file the "cnature" and "ccnature"
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
delete the ".cproject" file from eclipse workspace
remove all generated files and folders : libs, obj, gen and bin
Re-add the native support for android via the "android tools" context menu
Thank you android developer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With