I’m trying to use a class of another project in an app. In Eclipse I’ve added in the project properties under Java Build Path the other project and under Libraries the the class folder of the project. In the Package Explorer at Referenced Libraries the referencend class is visible under (default package).
While writing the code I could use the referenced class without problems and compiling the app throws no warning or errrors, but when the app starts, logcat shows the following:
dalvikvm(16174): Could not find class 'de.project.myproject1.myclass', referenced from method de.project.myproject2.myActivity.onCreate
AndroidRuntime(15570): FATAL EXCEPTION: main
AndroidRuntime(15570): java.lang.NoClassDefFoundError: de.project.myproject1.myclass
AndroidRuntime(15570): at de.project.myproject2.myActivity.onCreate(KeyGenActivity.java:45)
AndroidRuntime(15570): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
AndroidRuntime(15570): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
AndroidRuntime(15570): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
AndroidRuntime(15570): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
AndroidRuntime(15570): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
AndroidRuntime(15570): at android.os.Handler.dispatchMessage(Handler.java:99)
AndroidRuntime(15570): at android.os.Looper.loop(Looper.java:123)
AndroidRuntime(15570): at android.app.ActivityThread.main(ActivityThread.java:4627)
AndroidRuntime(15570): at java.lang.reflect.Method.invokeNative(Native Method)
AndroidRuntime(15570): at java.lang.reflect.Method.invoke(Method.java:521)
AndroidRuntime(15570): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
AndroidRuntime(15570): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
AndroidRuntime(15570): at dalvik.system.NativeStart.main(Native Method)
ActivityManager( 971): Force finishing activity de.project.myproject2/.myActivity
ActivityManager( 971): Activity pause timeout for HistoryRecord{4407ee10 de.project.myproject2/.myActivity}
So has someone a hint, what to do to solve the problem, I’ve spent the whole day without a solution?
I would suggest trying to export the Eclipse project as a jar, and add the jar to the build path of your Android project. Otherwise, if you have control over the other Eclipse project, then try creating an Android Library project and moving the code into that instead.
Finally, you should be able to add the source from the Eclipse project as a path in your Android project. This way, the Android project will compile and include the sources.