1

I have created .so file using android NDK. In xxx.java class I added some native methods to call from c/c++ files. these native methods I am calling in my own methods for example like below,

static
    {
    System.loadLibrary("print");
    }
    public native String print(String pM,int len);
    public native int openPrint();

The above native methods are calling in my method so that other android application developer can use as an API's.

public static void foo(){

         openPrint()
    }

Is this right way ?

For this reason I created one myprint.Jar file. it includes the libprint.so file also.

I added above jar file in another application, It's importing the class from xxx.java but whenever I tried to run the application its throwing an error saying that

  FATAL Exception,
  java.lang.UnsatisifiedLinkerror....

How to solve the above problem?

Thanks in advance

Prasad
  • 1,375
  • 5
  • 17
  • 31

2 Answers2

1

The libprint.so needs to be put in the libs folder, and then loaded using:

System.loadLibrary("print");

May be you have java.lang.UnsatisfiedLinkError because, the c function name didn’t match the fully qualified name of your java class.
i suggest to follow this link: http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/

Nermeen
  • 15,883
  • 5
  • 59
  • 72
  • Thanks for ur rply. I added System.loadLibrary in xxx.java. and created myprint.jar. Is it necessary to add in android application also where I am adding .jar file?? – Prasad Sep 24 '12 at 08:06
  • http://stackoverflow.com/questions/8434529/how-to-load-a-native-shared-object-in-a-jar-from-an-android-application – Nermeen Sep 24 '12 at 08:09
1

The .so file should be place in libs-->armeabi-->xxx.so folder of eclipse. then create build.properties file in eclipse and mention the path of xxx.so file by doing like this

open build.properties file. 

   then click on Add Library button. 

   then one edit box will appear write below line in the edit box.



external.libs.dir=libs 
Prasad
  • 1,375
  • 5
  • 17
  • 31