I need to create an Android library which I can include as a jar in any Android application. I use NetBeans 6.8, the nbandroid plugin, and the Android SDK.
The steps I took so far are:
1) Create the library project, with android.jar included to have access to Android classes (the library uses android.util.Log and other Android classes).
2) Compile the library as a jar.
3) Add the library's jar to the Android application (right-click on Libraries under the project node and add the jar).
4) Add <uses-library> to the Android manifest. (erroneous and unnecessary)
Step 3 at least allows me to reference the library's classes in the application's source code, but the classes don't seem to actually be included at compile time. When I run the application, I get the following error in the log.
I/dalvikvm( 349): Could not find method mylibrarypackage.MyClass.myMethod, referenced from method myapplicationpackage.HomeActivity.onCreate
W/dalvikvm( 349): VFY: unable to resolve static method 985: Lmylibrarypackage/MyClass;.myMethod ()V
D/dalvikvm( 349): VFY: replacing opcode 0x71 at 0x000a
D/dalvikvm( 349): Making a copy of Lmyapplicationpackage/HomeActivity;.onCreate code (160 bytes)
D/AndroidRuntime( 349): Shutting down VM
W/dalvikvm( 349): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
E/AndroidRuntime( 349): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 349): java.lang.NoClassDefFoundError: mylibrarypackage.MyClass
E/AndroidRuntime( 349): at myapplicationpackage.HomeActivity.onCreate(HomeActivity.java:58)
E/AndroidRuntime( 349): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 349): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
E/AndroidRuntime( 349): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2470)
E/AndroidRuntime( 349): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
E/AndroidRuntime( 349): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
E/AndroidRuntime( 349): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 349): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 349): at android.app.ActivityThread.main(ActivityThread.java:4310)
E/AndroidRuntime( 349): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 349): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 349): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime( 349): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime( 349): at dalvik.system.NativeStart.main(Native Method)
Do I have to add the library to the build path somewhere else? Am I missing something?