Eclipse can't read code format of RenderScript .rs file - android

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.

Related

Android Studio JNI: cannot compile JPEG c-library

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!

Android Eclipse can't see jni symbols

In my Android project I can see all android java symbols in my java code. Now when I do "System." then it suggests all the functions it supports. I can select say "LoadLibrary". or if I use a symbol then, eclipse tell me which java class to import.
But, in my ndk project (it generates .so and then also jar both), in jni cpp file, I can't see symbols if I do "env->". It just becomes like ordinary text editor without any hint.
any solution or explain why?
rather than android project when I converted to C++ project then it worked by adding symbols manually.
However after sometime java files stopped seeing java symbols.

Mac Eclipse not resolving C++ lib functions in NDK

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)

C files get an error using the NDK

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.

What is an Android.mk file

A project that I am trying to build has one of these, and I want to know exactly which tools are needed to build the project. I see some reference to NDK when I search but is that the only tool? It appears that this file is making a jar file, I see no reference to native code ( c++ )
The Android.mk files in the SDK samples are required to properly include the samples in the SDK build (if you are actually venturing into that territory). These have no bearing on what you are doing when you use the sample. To the OP, I'm not sure if you are using a sample project, but if you are, you can ignore this file.
the best answer to your question is reading this article:
Android.mk file syntax specification
https://android.googlesource.com/platform/ndk/+/4e159d95ebf23b5f72bb707b0cb1518ef96b3d03/docs/ANDROID-MK.TXT
after reading it you can figure out the idea behind the android.mk file.
cheers
I've seen some of the Android sample code come with an Android.mk file for no apparent reason -- maybe this gets auto-generated upon project creation if you happen to have the NDK installed or something. Android.mk does seem to be an NDK-specific thing.
So if there's really no native code involved, then if you're looking to build from the command line, make sure you have the JDK, Ant, and Android SDK installed.
Then take a look at
http://developer.android.com/guide/developing/projects/projects-cmdline.html#UpdatingAProject
After you run the "android update project ..." step, you should hopefully be able to do an "ant debug" to build the application.

Categories

Resources