I have been given a program written in C, and have been asked to use the functions from the program in a new Android application. I have been following the tutorials of the NDK, but have hit a wall. I think all that is left is compiling or linking my C files, but I'm not sure. I have installed the SDK, NDK, Eclipse, Cygwin, and Sequoyah ( I haven't used Sequoyah yet and don't really know where it comes into play ).
I have used the ndk-build command, but am not sure what I am should be expecting. This is a screenshot of my Cygwin terminal.
This is a screen shot of my NWPTest.c file. All of the fields defined in the .h file come up as errors. I feel like this is an error that should go away once I compile the code.
BYTE and WORD etc. declarations here:
This is a screen shot of the NWPTest.h file. BYTE and WORD declarations are also coming up as errors, which is something I do not understand.
This screen shot basically shows the last thing as the last one, but I'm confused how some of the BYTEs are errors and some are not:
EDIT
Here is my Android.mk file. Just to clarify, I was given the entire C project, and was told to make it an Android application. I have no experience with C.
Probably your problem is that Eclipse doesn't know about the include path for the ndk C header files; however that should not really matter since ndk-build appears to have built your native library. Though if your C-aware eclipse setup is being obstinate and refusing to build the rest of your project with "errors" in the C files, then you will have to either fix the include path or tell eclipse to ignore the C files as it does when not aware of C.
Of more concern would be whatever is causing an error in Operations.java - that will prevent you from building an apk.
I guess this is eclipse error. It simply does not understand your c and h files. Try to install CDT plugin, maybe after that the problems will eliminate.
Related
My program needs to read jpeg-images from a file native. For that purpose I downloaded official jpeglib c-source code and that works flawlessly on a Windows version of this program, which is programmed using Embarcadero RAD Studio 8.
But when I try to use the same source code in Android Studio JNI, I see lots of errors almost every c-source file :( Below is a screenshot:
As you can see, there's errors on both
-Macro expansions (ERREXIT, red underlines), which complain "class 'blahblah' doesn't have a field 'blahblah'".
-member methods (red text in code), which complain also "class 'blahblah' doesn't have a field 'blahblah'".
Looks like there are many C-language classes and fields, or probably all, which are not working. But the jpeglib source definitely contains them all, something is just not working in Android Studio! Probably Android Studio C-compiler is somehow limited, but there must be some way to bypass it...
This problem doesn't exist in C++ source files. I have different source folders for java and C++ source files (and there are also separate jni folder, but I don't use it, probably I should), but C source files resides inside the C++ folder. I have added all c, cpp, h and hpp source files inside the parentheses of the CMakeLists.txt's add_library() directive, but that's all. I don't know is it enough...
I'm glad to get any suggestions how to fix this.
It is not enough to add all libjpeg files to your add_library(). The library expects to be configured for the specific toolchain, see e.g. this example.
I prefer an optimized version of the library, called libjpeg-turbo. On GitHub you can find step-by-step instructions how the library can be cross-compiled for Android.
Well, there seems to be happy ending...
I have to admit that Android Studio most likely can compile JPEG c-library:) The problem "class 'blahblah' doesn't have a field 'blahblah'" was because the library needs to be configured for the specific toolchain, like #Alex Cohn said. But the configuration doesn't happen in CMakeLists.txt, instead you need to rewrite the code itself at some extent. For example, you need to change
-INT32 to int32_t
-#define boolean bool
-#define EXTERN extern
-add lots of #include <> and #include ""
-and more...
If you need to do that, start from header files: don't touch C files until you have headers error free. As a side note, I had exactly the same build order in Android Studio than I had in Embarcadero Studio, but that didn't helped to succeed... I don't know yet, will this modified library work, but at least I think I will get rid of compilation errors!
I'm running the latest build of android studio. Trying to make a project compilable and running utilizing the power of this https://github.com/tpruvot/cpuminer-multi/ c++ stuff. What I've tried so far is create new project with c++ support - it creates the corresponding project structure. It also includes CPP file that is called from the main activity. Now let's say I want all this aforementioned miner code to be there as well - I’ve tried just copy-pasting it into the cpp folder. What are my next steps? Calling ndk-build against $ProjectFileDir$\app\src\main directory just fails with an error Android NDK: Your APP_BUILD_SCRIPT points to an unknown file: ./jni/Android.mk . Same goes if I try to import an existing project like https://github.com/mdelling/cpuminer-android - first of all I’m trying to do and ndk-build, but it just fails saying that it treats warning like errors so all the cpp/h functions remain inaccessible and are not packed into resulting apk. If I try to install the resulting apk it just crashed on the start. So for the first case – how can I like all the cpp sources to the app, and for the second – how can I make it work at all?
First of all, the crash is probably because your Java code is trying to load the c++ shared library and fails, because the library was not built due to the NDK errors. So take care of the errors first.
Second, did you configure your Android.mk properly? Have a look here, for example (it is for Eclipse and not Android Studio, but the mk file is the same): Getting started with Android NDK. Looking at an existing simple project can also help: hello-jni.
I have a very good Java knowledge for Android (1 year of development), and now I'm trying to learn the Android RenderScript API (but there isn't much documentations for it) anyway, I'm having some problems with it.
I learned that we need to add the following lines on project.propert:
renderscript.target=19
renderscript.support.mode=true
I created a .rs file in com.mypackage.script called FireworkScript, which has the following:
#pragma version(1)
#pragma rs java_package_name(com.mypackage.script)
#include "rs_graphics.rsh"
int root(){
return 0;
}
void init(){
}
Innitially I had some problems with the RenderScript v8 support library, but I fixed it by manually adding the renderscript-v8.jar to my project (Build Path >> Configure Build Path >> Libraries >> Add External JARs)
As expected, Eclipse generated the ScriptC_FireworkScript.java at gen folder and the fireworkscript.bc at bin/res/bc/raw
But the problem is: Eclipse doesn't "read" the code inside the .rs file, writting on this file using eclipse is the same as writting on any single text editor.
I know the sample above needs a Kernel, but how can I write it, if Eclipse doesn't read its code format? I know the simple typedef struct constructor in C, but I'm not familiarized with kernel declarations and arguments in C99
I can only find errors using project > clean, it seems to "refresh" the compiler, but anyway, I don't have any identation help, text-coloring, anything, only a file with black texts on it, what can I do to fix this? I also tried to open the .rs file with Dev C++ and Notepad++, but I had the same result. Maybe my machine doesn't know the C99 code formating?
Is there anything I can do?
Thanks in advance.
I'm using Eclipse Luna with ADT pluging, SDK build tools currently on 23.0.2 and everything is updated to the latest version.
The C99 specification RenderScript uses for its kernel code is simply C, so you can use any editor capable of editing C/C++ files such as those two you mentioned. This should help you get syntax highlighting at least. You'll just need to configure them to treat .rs files as C code. See for example this page that explains how to do that in Notepad++.
If you really want to keep everything within Eclipse though, you could also try installing the C development environment for Eclipse, but that might be overkill just to get syntax highlighting there. I doubt you would get any actual context/function help or better error reporting with that, since the RS API is still not well integrated into any IDE anyway.
I'm developing a native application using Eclipse for Mac and I can't get std::string or std::map to resolve.
I've already had to add a number of include directories to the path to handle the NDK not being set up that well out of the box; currently I have
.../Development/android-ndk-r9/sources/cxx-stl/gnu-libstdc++/4.8/include
.../Development/android-ndk-r9/platforms/android-18/arch-arm/usr/include
.../vuforia-sdk-android-2-6-10/build/include
.../android-ndk-r9/sources/cxx-stl/system/include
set as C++ symbol paths, and #include <string> seems to have worked fine. However, all the references to std::string are not resolving, and Eclipse says
Type 'std::string' could not be resolved.
I know this code builds because I successfully built it on a Windows PC; it's an eclipse problem of some description. What can I do to make these symbols resolve?
EDIT 1: I've looked inside <string> and it seems that it mainly contains a bunch of other includes, for example #include <bits/c++config.h>. All of these seem to resolve, but I am going to see if I can find them and determine where std::string actually lives.
EDIT 2: I can find std::basic_string, but not std::string (yet).
EDIT 3: std::basic_string is not apparently visible to my source code either.
Im not sure if this will be an answer for you. My experiences are different, I'm on Windows, and I was only trying to get C (not C++) code working. But ran into exactly the same issue. And my solution could seemly be used to work for C++ as well. As far as I can tell, Eclipse/ADT on Mac is much the same as on Windows. So that shouldn't be a problem here. Who knows, I could be talking out of my a--.
However, I think the problem is solved two fold. Here is how I solved it. I followed the tutorial: http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/
Things to note:
1) When developing in Eclipse/ADT for Android. It always assumes that your writing in Java. You need to make the project "Mixed Java & C/C++" (not that I've seen it called this outside the tutorial, lol)
2) Your ndk-build should probably work fine from the command line (even tho it might not compile in Eclipse).
3) In the tutorial, the two things that seemed to get it to recognize C/C++ are "Step 5: Convert to a C/C++ Project" followed by Steps 6-8 (which seem like one big step).
4) In Step 7, under "Build command". You might have to use a the complete path (no spaces) to your ndk-build. (*Windows users enter "ndk-build.cmd" here)
5) In Step 8, also include a full path.. no spaces. However, this is where you would put a path in for "GNC C++" instead. (This is my guess for your solution)
6) If all else fails... It should work in C. Try Step 8 exactly, and use only C syntax. Because, at the top of this older tutorial (http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/) it talks about how limited NDK is. It says C++ functionality is limited. Otherwise, this second tutorial is mostly obsolete it seems. Cygwin and command line compilation are not needed anymore, and my Eclipse installation had the C/C++ support out-of-box. However, its all still usable/valid.
PT
(and on a similar note, and for those seeking help with NDK. Also make sure a space-less full path to your NDK folder is entered in at Eclipse > Window > Preferences > Android > NDK > NDK Location)
This is really frustrating
- I can build my native code from command line, but when I build from eclipse(Sequoyah plug-in enabled) its simply through simple compilation errors like headers not found...
EVen when i build the library from command line everytime I try to run from eclipse it rebuuilds and there goes errors again
- I'm frustrated as I ran out of option to locate the issue
Can some one shed some light on this.
The error you are seeing is Unresolved inclusion with error markers at each header that Eclipse's editor cannot find. This is confounding when you see it, because it is expected that after installing Sequoyah and the ADT, pointing the Sequoyah configuration to your NDK, that you'd have everything you need to start coding.
Two things to observe. The process of building in the ADT "Android Perspective" will work until you click on one of your C/C++ files in your jni directory. Once you open one of these, you'll see the error marker and the project will be tagged as containing errors.
Second observation, when you convert the project to C/C++ perspective or to Sequoyah's Android Native perspective (apparently there's two ways to skin this cat), you will have the ability to configure the project settings around NDK toolchain, include paths, and builder settings. This is where you can set the ndk-build to automatically fire off on each change. And funny thing too is that the ndk-build will work fine until you click on one of your C/C++ sources.
So solution, click [here] http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.cdt.doc.user/tasks/cdt_t_proj_paths.htm and you'll get instructions for configuring the CDT's include paths. You want to set your include paths for C/C++ (either, or both) so that you get to the platform folder includes.
Example, I've got my project hello-jni-to-the-world project set to android-9. So configure the include path: android-ndk-r6b/platforms/android-9/arch-arm/usr/include . Now the magic won't show up until you click apply/save and you'll be prompted to rebuild the indexes.
There are two to three other threads on Stackoverflow asking the same question, and I'll have to find them and add them to the comments. Basically, there were no definitive answers and there's a lot of the usual answering a question with a question: which version of NDK do you have, can you post your code, did you install java, is your computer on ?