1

For one of my project I need to call native c code to my java class. For this I made following steps.

  1. In my java class I declared some native methods which are required for my project. i.e

    public native String print(String pM,int len);
    
    public native int openPrint();
    
  2. I initiated library file like below

    static
    {
        System.loadLibrary("print");
    }
    
  3. After this I created header file with respect java code.

  4. created c file and implemented above methods in c

  5. after this I generated library file i.e libprint.so using ndk-build

  6. library file is created successfully in libs->armeabi->libprint.so

  7. whenever I run that java application it's giving error saying that

    Exception in thread "main" java.lang.UnsatisfiedLinkError: 
      no print in java.library.path
    

How do I solve this problem.?

I want to give this kind of application to other Android developers so that they can create this application without doing Native call and without creating libprint.so file

It means I have to give my own API to application developer. For this I have to create JAR file. which includes java.class, libprint.so (shared library) and etc...

How to create JAR file which includes libprint.so also..

I am doing all above stuffs in ubuntu using eclipse and open-jdk6.

oers
  • 18,436
  • 13
  • 66
  • 75
Prasad
  • 1,375
  • 5
  • 17
  • 31
  • possible duplicate: http://stackoverflow.com/questions/2937406/how-to-bundle-a-native-library-and-a-jni-library-inside-a-jar – oers Sep 18 '12 at 07:15
  • 1
    Might want to take a look at a related Question. [how-to-bundle-a-native-library-and-a-jni-library-inside-a-jar](http://stackoverflow.com/questions/2937406/how-to-bundle-a-native-library-and-a-jni-library-inside-a-jar?rq=1) – asgs Sep 18 '12 at 07:17

1 Answers1

0

In Windows if the jar use a dll, you must copy the dll to the root folder inside the jar. After that the program will find it.

Try it, it maybe help you.

Csujo
  • 507
  • 2
  • 6