0

I am new to Android NDK and I am trying to understand it. So far I discovered that every example in the NDK/samples folder is written in C, not C++. Everything works fine when I import those projects and work on them. However when I create new project in Eclipse and then right-click on the project -> Android Tools -> Add Native Support it always creates the libname.cpp file. Naturally the c code doesn't compile after copying into .cpp file.

I've also tried to replace nativetest.cpp with nativetest.c in the following lines in the Android.mk file

LOCAL_MODULE    := nativetest
LOCAL_SRC_FILES := nativetest.cpp

but it produced this error:

 No rule to make target `jni/nativetest.c', needed by `obj/local/armeabi/objs/nativetest/nativetest.o'.  Stop.

My question is: how can i add native support for .c files?

grzebyk
  • 1,024
  • 1
  • 15
  • 26
  • Did you just change the name inside `Android.mk`, or did you also rename the actual file? – Michael Nov 07 '14 at 15:19
  • Well, I just tried your scenario in Eclipse: I created a new Android app project, selected Add Native Support, highlighted the generated .cpp file in Eclipse's file explorer, pressed F2 to rename and changed the ending from .cpp to .c, and finally changed the file ending inside `Android.mk` as well. The project built just fine after that, and the C file appears to have been compiled successfully. – Michael Nov 07 '14 at 16:22
  • There must be something wrong with my eclipse installation. Doing this and copying hello-ini code results in this problem: [link](http://stackoverflow.com/questions/15899813/eclipse-method-newstringutf-could-not-be-resolved). What's more, compiling imported hello-jni code works fine, but after opening .c file eclipse shows errors related to unresolved inclusions. I'll try to follow [this answer](http://stackoverflow.com/questions/19360668/eclipse-adt-could-not-be-resolved-with-android-ndk-and-c-files?rq=1) – grzebyk Nov 10 '14 at 14:08

1 Answers1

0

After reinstallation of ADT eclipse bundle and few hours wasted on looking for the solution I overcame my problem by copying new .c file into project structure (jni folder) and changing values of LOCAL_MODULE LOCAL_SRC_FILES located in Android.mk

Unfortunately this workaround still leaves problems described here, here and here

Community
  • 1
  • 1
grzebyk
  • 1,024
  • 1
  • 15
  • 26
  • While it's understandable that you'd want to get this working, it is worth noting that there's no requirement to make eclipse aware of your native code. It's entirely possible to develop that with your favorite editor or IDE, run ndk-build however you like and then build the the java-level project with eclipse, picking up the native libraries automatically if they are in the correct locations. – Chris Stratton Nov 11 '14 at 17:33