Unable to generate JNI .c file using javah -stubs - java

I am trying to generate JNI code from my Java class.
I was able to generate the header without a problem using javah
Whenever I run javah with the -stubs command I get this error:
Error: JNI does not require stubs, please refer to the JNI documentation.
Does anyone know if there is a way to generate a JNI .c file for a class.
I can make the file from my header by hand, but it seems like something a tool should be able to do.
I found an unresolved bug request about this from 2000 so I'm not too hopeful.
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4368114

-stubs is a leftover from a long-obsolete first cut at JNI. It never generated anything useful for any version of Java used in the current century.
Just copy the header file into your .c file and add a function body to each function.
Or perhaps have a look at http://jna.java.net/.

Related

NDK build in command line to rebuild my application

My project use native library. when I change the package name , I got following error.
code:
Native method not found:
com.nooshindroid.yastashir.controller.JNIServer.get_number_of_processors:()I
at com.nooshindroid.yastashir.controller.JNIServer.get_number_of_processors(Native Method)
at com.nooshindroid.yastashir.controller.JNIServer.runServer(JNIServer.java:27)
at com.nooshindroid.yastashir.game.FreebloksActivity.startNewGame(FreebloksActivity.java:520)
at com.nooshindroid.yastashir.game.FreebloksActivity$16.onClick(FreebloksActivity.java:774)
at com.nooshindroid.yastashir.game.ColorListDialog.onItemClick(ColorListDialog.java:79)
when I sreach the net I understand that I must rebuil my JNI folder in command line.
In command line I don't know how to give project path.
I read somewhere that I must write like this .
cd <project>
$ <ndk>/ndk-build
I don't know the steps to do that job.
it show my project path and when I write Dir , it shows me all of things that exist in my folder.
but nothing change.
WHen you use JNI, unless you specify otherwise, the package name is part of the function name it looks for in the C code. So if you change the package name in Java, you also need to change all your C code JNI function names.
As #GabeSechan has said, you need to edit the C or C++ code to match the new package name. When you change the package name, the directory structure changes. If you don't edit the C or C++ code to match, the methods won't be found.
You need to change your JNI methods from
Java_com_old_package_name_methodName
to
Java_com_new_package_name_methodName
See the JNI documentation for an example.
Rebuild your native code after renaming the methods.

Linux Java: load .so dynamically without dlopen

I have 2 libs (first.so and second.so), and I need to call a function from 'second.so' in the 'first.so'.
Now in my case I don't want to do static link to second.so.
I need to call it dynamically.
So what I need is to use
System.loadlibrary("first.so")
System.loadlibrary("second.so")
Now in the c++ code of "first.so" I need to call a function from the second.so.
Can I do this without dlopen?
When you compile the C++ code and build your first.so you instruct the linker to use external symbols from the second library. The second library must be on the library search path at run time so that the systems dynamic linker can find it.

Is there a basic sample DLL build for a jagamp:gluegen dll out there?

I am working on a system where I am using part of the JOGL OpenGL bindings to Java. I find the basic idea behing the "gluegen" C to Java binding generator good but the docs are thin and I havn't been able to locate a simple sample of gluegen usage consisting of:
A C module the does something like modify a string or print a string to stdout (ie: easily tested from java code) an expanded version one with multiple methods that handle each data type handled by gluegen.
the appropriate "cfg", ".h" files needed to power gluegen for the sample source.
A build script - ideally simple not factored out too much into an endless chain to follow generic makefile or shell script :)
the result of running the build script gives you the generated and sample code for a complete native side DLL with DLL main, export tables, and whatever else is needed to load into java on a windows box (.lib for unix)
A C compile of the code with MSVC and/or GCC to compile and link the code and generated code to produce the DLL.
The generated java class or classes that mate with the DLL including initialization.
In a sense sort of a "hello world" in C to be called from Java as a place to start.
PK

Add a new class to an existing JAR File(which contains source code)

I'll try to illustrate the problem as simple as I can.
I have a JAR file, which I extracted using Winrar. (The jar file contains an open source android library).
I want to modify this JAR file by adding a new class to the library.
So here are my steps:
First, I created a class using Eclipse and set the package name same as the android's library package name.
Second, I copied this java File to the folder of the other java files in the library.
Third, I tried to compile the JAVA file via the CMD using javac.
The path of the new java file and the other .JAVA and .CLASS files of the library is: C:\com\example\core\
The name of the new java file would be: "MyNewClass.java"
The command I run via the CMD is: javac C:\com\example\core\MyNewClass.java
But, during the compilation I get many errors saying: Cannot find symbols.
I've been looking up for a solution of this problem but couldn't figure how to solve it and make the new JAR File having another class that I created seperately.
What am I missing?
As per earlier comments:
Rather than trying to modify the JAR, you can get access to the full source code of the Universal Image Loader library by cloning the repository using git or hitting "Download ZIP" on the righthand side of the page you linked.
Once you have the source, import the library in your IDE. From there on you'll be able to build the whole thing from scratch, make any adjustments/modifications you like, etc.
Your classpath might be wrong or there might be some mistake in package name.
When a Java program is being compiled the compiler it creates a list of all the identifiers in use. If it can't find what an identifier refers to it cannot complete the compilation. This is what the cannot find symbol error message is saying, it doesn't have enough information to piece together what the Java code wants to execute.
Try:
javac -cp com/* C:\com\example\core\MyNewClass.java
That should make the compiler aware of all the other classes under com/...

how to call lib.so from eclipse juno

java and I have its own .so file, I made a new android project and I import the class.java and the so file under lib\armeabi\lib.so I tried to compile it but I got errors about can't find the library.
I did many searches and found to make a new so file. I have the header file and I gone to androidtools add native support and created empty cpp. I copied the header content to the cpp then in android.mk I matched the nessecary and then I compiled i am getting some errors
java.lang.UnsatisfiedLinkError: Couldn't load FXTEST from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.example.fxtest-.apk,libraryPath=/data/app-lib/com.example.fxtest-2]: findLibrary returned null
I created jni_onload method and still got errors Any Idea? Let me know if you want some pictures, I will attach
I suppose you might try to provide Java with the path to you native library with the following java option:
-Djava.library.path=/Path/To/You/File
I am not an android developer though, so I might be wrong.

Categories

Resources