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.
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.
My intention is to test some modifications to an OpenCV algorithm, in particular ORB feature detector and descriptor. So I start developing on my desktop with C++ and I copied some .cpp file from OpenCV sources, in particular orb.ccp, fast.cpp, precomp.cpp, fast_score.cpp. The first one is the main file of the algorithm, the second one is the feature detector used by ORB, the third and fourth are necessary as called with "includes" in fast.cpp. Obviously I copied the headers and method declarations from OpenCV .hpp(s), creating my headers. I changed the names of the two classes involved (ORB and FAST -> myORB and myFAST) in all files, so that you can distinguish the calls to my versions of the algorithm from those of OpenCV, since it is still necessary to have OpenCV for all imgproc functions, core, Mat class ... used inside the cpp files modified.
So far so good, it works, I am able to use my version of ORB copied and eventually apply changes to the algorithm.
Problems arise when I switch to Android NDK. What I do, after setting a project with NDK, is to create a JNI method in which I implement the code that will use the algorithm ORB, then I import my files .cpp and .hpp above, set the .mk file and other related stuffs to compile my files, and obviously set up the project to use OpenCV4Android.
The problem is the following: my algorithm works, the code is compiled/builded and launched by Eclipse ADT, and I'm able to call myORB class. However when I open my version of the files, for istance (my)orb.cpp, in the editor of ADT, problems arise: the code has dozens of errors, relative to (opencv) methods non exsisting ("could not be resolved"), (opencv) methods called with invalid arguments ... So after I've opened the file it shows the errors, and then it's impossible to build the project in ADT again, but if I delete and copy back the .cpp file into the project it is compiled again without problems until I open it again...
The problem is due to Android ADT and/or Android NDK. The editor identifies false errors, in fact, the Console indicates that the C code is compiled without errors. However, Eclipse does not allow to run code/apps which, according to him, contains errors. So the fastest way to get around this is to modify the properties of the project in:
Project -> Properties -> C / C + + General -> Code Analysis
changing the "severity" of the "problems" that appear in the editor to "warning" or other types.
I'm just getting started in Android development, and use Netbeans with NBAndroid and SDK 17.
I'd like to use the same Java source code in my Java and Android app.
http://developer.android.com/guide/developing/projects/projects-eclipse.html says how to do it in Eclipse (although it is sketchy on the .JAR connection thing), but I can't seem to make it work in NB.
Based on that link, My understanding is that the correct setup for the Android app is an Android Application project which references an Android Library project which in turn references a .JAR library produced by a Java Library project. I could then also have a Java Application project referring to the same Java Library project.
So, I've set up this project structure... I have an AndroidApp project which is a basic HelloAndroid Activity in a com.ex package. This project includes an AndroidLib library project in the Libraries folder. I also have a LibClass.java file which defines a simple LibClass class which has one function getText() that just returns a String to be displayed. The MainActivity in the AndroidApp calls this to get the String to output.
When I put LibClass.java directly into the AndroidLib project, everything is fine.
But what I want to do is to share the source code with Java.
So I want to move the LibClass.java into the JavaLib library, whose .JAR file is included in the AndroidLib project. However, when I tried that, I get an error in the MainActivity class, complaining it can't find LibClass. Looking at the Projects window, I can see LibClass.class inside the com.ex package in the JavaLib.jar in the Libraries folder of the AndroidLib project. And AndroidLib is visible in the Libraries folder of the AndroidApp project, but it doesn't show any packages or other contents there.
So I feel like I'm just one step away from making this work. Do I need to do something with one or other of the AndroidManifest files perhaps? Or do something with the build.xml files? Or am I on the wrong track altogether?
I'd be really grateful if someone could post a how-to for this.
I'm trying something similar; I've got Java EE projects, built using Eclipse, and I'm trying to utilize some of that code from my Android projects. This should give me a shared codebase rather than a bunch of confusing SVN externals which I've had to endure before.
Rather than creating JAR files I've found that working with the source and building for the platform works best (well, it has been working but I've got a problem with it at the moment). So, what I'm doing is:
c:\MySvnFolderStructure\MyJavaProjectFolder\src\ (and then all the source under that)
c:\MySvnFolderStructure\MyJavaProjectFolder\android\ (and all the Eclipse Android project gubbins)
c:\MySvnFolderStructure\MyJavaProjectFolder\jee\ (and all the Eclipse JEE project gubbins)
The Android and Java EE projects do not have their own src folders, they both link to the src folder in their parent folder. What this means is that each of the Java implementations is building its own byte code version from the source, and using its own external libraries (like the Apache HTTP ones, for example).
Naturally they can't share stuff like awt (as mentioned in another post), but there's plenty of stuff that does cross-over especially if it's core Java classes that are being used.
Also, it's proving a bit tricky writing JUnit tests as there needs to be some duplication of the test code at the moment because the Android ones need extra instrumentation, but I'm working on it.
Also, see this post about relative paths in Eclipse, which means the folders can be checked-out to different places on different machines (like we all do with our version control check-outs) and still be shared.
if I understand your situation correct, you are trying to use a custom java library for both your android and java applications.
For this scenario, you can build the java library first. Instead of adding the java library jar as android library, you can drop the jar directly inside the libs folder of android project and add it to android project's build path.
If you are using ANT scripts for building the java library jar , you can consider adding the source files also as part of jar. This will help you get code assistance when you develop the android part. But this part is purely optional.
The problem is that the Java platform in Android is different from the JDK platform.
In particular, the .JAR library CANNOT refer to anything that is not icluded in the Android platform. An example of things you can't refer to is java.awt.* (except you can have java.awt.fonts).
There is also a difference between JDK String and Android String -- Android does not implement the isEmpty() method.