3

I have been trying endlessly to build the sample HelloJni sample project for the Android NDK.

How I set up the environment:

I followed the instructions of the getting started in the docs: android-ndk-r10d\docs\Getting_Started/html/index.html:

  1. Downloaded Eclipse Luna
  2. Downloaded the Android SDK
  3. Downloaded the Android NDK: android-ndk-r10d
  4. Set the NDK installation folder in eclipse in preferences window -> android -> NDK.
  5. Imported the hellp-jni sample.
  6. Right click on the HelloJni Project -> Android tools -> Add native support.
  7. Cleaned and Built the project.
  8. Ran on my device the HelloJni library (not the tests)

And the app is running and everything is WORKING and I can see the generated .so file per architecture in the libs folder of the project (for every architecture, for example armebi, mips, etc...)

Here is a Print Screen showing everything is working:

enter image description here

Now here comes the strange part...

The Problem:

If I open the hello-jni.c file for editing or viewing in eclipse, I suddenly see compilation errors and I can't build and can't run the project anymore...

Here is a Print Screen showing that after i open the file, I suddenly get compilation errors:

enter image description here

What I have already tried but failed:

  1. Adding the Android Native Nature, then removing it by: Deleting the .project file, the buildCommand tag of: org.eclipse.cdt.managedbuilder.core.genmakebuilde, the buildCommand tag of: org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder and removing the lines: [nature]org.eclipse.cdt.core.cnature[/nature] [nature]org.eclipse.cdt.core.ccnature[/nature] [nature]org.eclipse.cdt.managedbuilder.core.managedBuildNature[/nature] [nature]org.eclipse.cdt.managedbuilder.core.ScannerConfigNature[/nature] removing the .cproject and all compiled files. Then adding back the Android Native Nature.

According to this stackoverflow link: Eclipse ADT - Unresolved inclusion jni.h

Failed

  1. Once I got the error of (I am not getting it anymore): Unable to launch cygpath. Is Cygwin on the path?] java.io.IOException: Cannot run program "cygpath". So I Googled and I changed the build settings to give the absolute path of my NDK installation folder:

According to this stackoverflow link: Unable to launch cygpath in android

Here is a Print Screen: enter image description here

Failed

  1. Changing the Used tools from Android GCC Compiler to GCC C Compiler

according to this stackoverflow link: Android NDK build, Method could not be resolved

Here is a Print Screen: enter image description here

Failed

  1. Copying an eclipse Luna installation from a friend that has the project working for him.

Failed

I have been spending hours on this and I couldn't find any solution to why this is happening.

PLEASE HELP

Community
  • 1
  • 1
ZiviMagic
  • 1,034
  • 2
  • 10
  • 25
  • I also wonder if Android-Studio can import and create projects that use NDK . – android developer Dec 13 '14 at 19:30
  • assuming you aren't getting any errors, did you do `static { System.loadLibrary("your.so"); }` – SemperAmbroscus Dec 13 '14 at 19:36
  • Yes, this is the sample project it has it: static { System.loadLibrary("hello-jni"); } – ZiviMagic Dec 13 '14 at 19:42
  • @FeatheredOrcian Since he said he tried the NDK sample called "helloJni", if you look at the java file, they have this code called at the bottom : static { System.loadLibrary("hello-jni"); } . Besides, he wrote the app works, and that only when he tries to edit the C/C++ file, problems appear. – android developer Dec 13 '14 at 19:42
  • Do a clean and look at the console tab (not the problem tab). The console tab should show the progress of the NDK build process, this will most likely be clean. Your errors look like Eclipse CDT errors. I don't think CDT is correctly setup by "Add Native Support". I usually have to set it up by hand. – Richard Critten Dec 13 '14 at 23:22
  • Richard thanks for your help, when I do clean & build all, it does get built, and it generates the different *.so files under libs. But since Eclipse is showing me that I have errors, I can't run the project, what do you suggest? how can i solve my problem and "correctly setup and fix the Eclipse CDT errors" ? – ZiviMagic Dec 14 '14 at 00:00
  • Temporary fix is to highlight the error reports in the Problems tab and then press [Delete]. This will get rid these errors until you try and edit the file(s) in Eclipse again. If you edit your C/C++ files outside of Eclipse (eg. use Notepad++) then the "fake" errors will not return. Long term fix is to setup Eclipse CDT/Indexer to work correctly with Android-NDK. – Richard Critten Dec 14 '14 at 08:10
  • Ok it is now building, but It is a problem programming like that, i might as well write in notepad++ :) how do you setup Eclipse CDT/Indexer to work correctly with Android-NDK, from my understanding there is some bug about it in: eclipse-4.3 + cdt-8.2.0 + adt-22.0.4. according to this link: https://code.google.com/p/android/issues/detail?id=33788 – ZiviMagic Dec 14 '14 at 09:36
  • I'm new to NDK, and I have the exact same problem. ZiviMagic, did you find a solution? @RichardCritten, where did you learn how to setup Eclipse to work with NDK? – DannyA Dec 28 '14 at 15:56
  • @DannyA Didn't find a permanent solution. What I am doing is to simply delete all the errors in eclipse every time before I build. This sucks, but no1 else replied and found an answer – ZiviMagic Dec 28 '14 at 16:33

2 Answers2

0

This is a common problem when you try to edit a C/C++ file inside a JAVA workspace/perspective without the proper configuration. You can simply select all the entries in the Error Log and delete them.

bonnyz
  • 13,458
  • 5
  • 46
  • 70
0

FWIW, Eclipse seems to have issues with the r10d version of Android NDK. See https://code.google.com/p/android/issues/detail?id=97023. I suggest you try r10c instead #worksforme :)

MMrko
  • 31
  • 3
  • I have tried with r8 and it didn't work. I just moved to AS. and in the cases I want to use eclipse I delete the errors before I compile.. Thanks for the help though – ZiviMagic Jan 23 '15 at 22:30