Question

First of all, I realise that similar questions have been posted a lot here. But I've been through all of the answers I can find to similar problems, and nothing has worked yet, so was wondering if someone could help me.

I'm trying to develop a simple chat app with an Android client and a server app sitting running on my laptop. This includes a regular Java "common" project that holds the class that is used to pass messages via the socket.

First I tried to reference the "common" project in the Android project, but after a bit of reading abandoned that idea.

Now I have exported the jar file for the common project, and imported it into my Android project by copying it into the "libs" folder, and then selecting Build Path > Add To Build Path. I have also gone to Properties > Java Build Path > Order and Export and checked the library and moved it to the top of the order.

I have also moved the "gen" project above the "src" one in that build order.

Android Private Libraries is also checked. Everything is checked.

When I debug as an Android Application to my Samsung S3, I see a "Could not find class error" in logcat when advancing to the Activity that contains a reference to a class in the "common" project. Stepping through to the point where a class in the "common" project is referenced then causes a ClassNotFoundException to be thrown.

If I try to put the name of the library in the Android Manifest, like:

<uses-library android:name="com.johndarv.chatproj.common" />

I get:

Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY
Please check logcat output for more details.
Launch canceled!

Upon trying to install.

I have the following versions: Eclipse Standard SDK 2.0.0 Android SDK 22.3

Android project is compiled with Android 4.2.2.

Any help would be much appreciated! If I can give any more info that would be useful, please ask!

Was it helpful?

Solution 2

I managed to solve this by deleting the common project and then creating a new Java project with "Use execution environment" set to Java SE 1.6. And rewriting (copy-pasting) the old classes.

There must have been something wrong with my previous project, and looks like it was the Java version used to compile. I had tried to set the compliance version to 1.6 on the old project. In any case, creating a whole new 1.6 project, pasting the classes in, re-exporting, and copying into my Android project did the trick.

Thanks to everyone who tried to answer this for your help. Hope someone finds the above useful one day!

OTHER TIPS

The uses-library tag means that your app expects the library to be available on the system. This is to prevent installation on devices which do not have some expected third-party software installed. Consider phone manufacturer who ships his devices with some specific api. So this is not your case. Forget about this tag this time.

And as to your problem. The jar is not exported into the apk. Ensure in Project Settings > Java Build Path > Order and Export that the library jar is checked to be exported.

If you put a jar into /libs dir of android project it is automatically added to the build path. You do not need to do this manually (as you did). Then you can see it (this jar) under Android Libraries entry in under Project Settings > Java Build Path > Libraries. This entry is also checked as exported (by default in android project) in Order and Export tab.

Maybe your problm occurs due to the fact that the jar is actually exported twice (once manually and once as private library). Just remove manually added entry from build path. You will have it added once - but to be honest I do not expect this caused the problem. But for sure the problem is in your project settings. Maybe paste a screenshot with Java Build Path > Order and Export and Java Build Path > Libraries.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top