Take the 2-minute tour ×

Since the latest android sdk i am unable to run my android applications from eclipse anymore because they cant find classes which i have in other eclipse projects, which are references via the 'normal' build path.

this has definitely worked before. and there are no compile errors in eclipse.

could it be that, now you have to mark those projects as android library projects in case they are referenced by an android project.

edit: it seems that this is the reason why it is broken: http://tools.android.com/recent/dealingwithdependenciesinandroidprojects

but i still have to figure out how i should now reference my "normal" java projects to the android app project.

share|improve this question
What is the runtime error? ClassNotFound, or ClassDefNotFound? –  Ogre_BGR Mar 27 '12 at 14:04
java.lang.NoClassDefFoundError –  clamp Mar 27 '12 at 14:28
this has definitely worked before, I don't know how you make it work. I also have android project that reference other regular java project, and the apk works only if I explicitly add the regular java project generated jar into android project build path, Looks like the latest SDK r17 completely screw this behaviour and now only accept library jars from the predefined libs folder. I haven't found a workaround yet. –  yorkw Mar 28 '12 at 2:50
It's odd that this used to work for me, too, and now broke. –  ashes999 Jun 24 '13 at 1:45
This seems to work now - adt version 22.6.1. –  AlikElzin-kilaka Apr 7 at 13:59

5 Answers 5

up vote 17 down vote accepted

In the link @clamp provided there is the following sentence:

The container will now also be populated with Java-only projects that are referenced by Library Projects.

This means, that we can use a empty library project as a "glue" project between the android project and the regular eclipse project. Just set it up like this:

android --> "glue" project --> regular project

--> means depends on

The glue project has to export the regular project and has to be marked as library. In the android project only the library project has to be referenced.

Now using a regular eclipse project works again for me with the minimal overhead of the "glue" project.

share|improve this answer
while i dont like this solution, i will still accept it as the answer, since it works. –  clamp Dec 27 '12 at 13:19
This does not work for me. Since I upgraded to version 21 I can't manage to add external Java projects to Android projects. Tried the direct approach and this indirect one, but without any luck, still getting the error, and .apk file doesn't contain required classes. –  Andras Balázs Lajtha Mar 18 '13 at 16:02
Does this still work for you? I couldn't get it to work. I create an Android GlueProject which requires my Java LibProject (under Properties>Java Build Path>Projects tab). I also ensure I export the LibProject by checking it (under Properties>Java Build Path>Order and Export), and have the GlueProject marked as a Library project by checking "Is Library" (under Properties>Android). In my Android project where I want to use LibProject, I add a reference to GlueProject (under Properties>Android). My Android project compiles, but gets a NoClassDefFoundError when it runs :/ –  nissemand May 26 '13 at 21:36
Scratch that, your solution works perfectly :) The problem was that my Java project was using Java 7 not 6. Switching to 6 made everything work. –  nissemand May 26 '13 at 22:11
This just doesn't work for me. The glue project's jar file doesn't contain the the class files of the referenced Java project and consequently a NoClassDefFoundError. I even tried to reference the bin folder directly - still no success. And Yes - I checked the boxes in the 'Order and Export' tab. Can someone post the .classpath file? –  AlikElzin-kilaka Oct 19 '13 at 18:57

Since the latest update to the eclipse build tools you have to also tick the referenced projects in the 'Order and Export' tab in 'Java Build Path'. This fixed the same problem for me. Hope that helps!

share|improve this answer
didnt fix it for me, still the same problem. thanks anyways. –  clamp Mar 27 '12 at 15:14
Ah shame, i was sure that was it. Do you definitely have all your referenced java projects in 'Projects', and have them all ticked in 'Order and Export' along with 'Android Dependencies'. Also make sure any library jars you are using in your project are in a folder called 'libs' (as long as they are in there you don't need to include them manually in the build path, the new eclipse tools will include them automatically). –  kingraam Mar 27 '12 at 15:21
yep, i just doublechecked that and actually i would be surprised if this would have any influence on the issue. since order and export is only for projects which should forward their dependencies to any other projects that have it references. (like a 2-layer dependency hierarchy) –  clamp Mar 27 '12 at 15:26
I think the solution you suggested only work for Java Project referenced by Android Library Project, as stated in the changelog, but not in this case: Java Project directly referenced by the main Android Project. –  yorkw Mar 28 '12 at 2:52
After banging my head finding a solution with no luck, this simple step worked for me. Thanks. –  Federico Cristina Feb 15 '13 at 11:03

As already mentioned, Android will not directly compile and use your Java project files. Instead it takes only precompiled class files.

Here is my workaround, which I prefer because I need no "glue" project just for Android libraries. The main idea is to provide a pre-built JAR to Android, while still using the source code of the libraries while working in Eclipse:

  1. First of all make sure, that the library projects are compiled using Java 6. Java 7 will not work, Android will silently ignore those libraries. So check both the workspace settings (in Preferences -> Java -> Compiler) and the individual project settings. Choose 1.6 as the compiler compliance level.
  2. Right click your Android project -> Properties -> Java Build Path -> Projects. Add all Java projects you want to use in your Android project.
  3. Now, Eclipse knows the classes (but not yet the final Android build), so build errors are resolved and jumping into a class leads directly to the original source file of your Java project.
  4. Add an ant buildscript in the directory of your Android project. This buildscript will create a JAR containing all the .class files of your projects into the libs subdirectory (and this is the step which lets Android know your .class files!). See below for the code.
  5. Now, and always when the Java projects have changed, rebuild the JAR file by executing the buildscript. This can also be automated, see for example "Want an eclipse java project to run ant build files automatically"

Here is the code:

<project default="create_jar" name="Create Jar with classes from Java projects">
<target name="create_jar">
    <jar destfile="libs/java-projects.jar">
        <!-- "bin" is the class output folder -->
        <fileset dir="path/to/first/java/project/bin"/> 
        <fileset dir="path/to/second/java/project/bin"/>

        <fileset dir="path/to/last/java/project/bin"/>

share|improve this answer
Individual projects > Java compiler > JDK compliance for the particular project should suffice, no ? And setting the compiler to a 1-6 execution environment (pointing to an actual 1.6 JVM). You may gave some insights for my question : stackoverflow.com/questions/18981837/… –  Mr_and_Mrs_D Sep 24 '13 at 13:24

I added an ant project builder that copies the class files from the dependent project. The ant file resides in the android project and copies the class files from the referenced project. Here's the ant:

<project name="CommonsCopy" default="copy" basedir=".">
    <target name="copy">
        <copy todir="bin/classes">
            <fileset dir="../Commons/bin" includes="**/*.class">

2 things to remember:

  1. Find a way to copy the jar files that the referenced java project uses, or just put them directly into the Android libs folder.
  2. The referenced project must be compiled with in the 1.6 compliance level.
share|improve this answer
Mind that the big disadvantage here is that that if you change the java project, you'll need to change some file in the Android project to initiate the ant builder. –  AlikElzin-kilaka Apr 7 at 14:00

You can define two projects (one Android, one vanilla Java) and have one refer to the other project's source files using mklink command in Windows to create a directory junction or a file hard link. I don't know the linux equivalent but there must be one. If you edit a source file from one project then the other project will be out of sync and you just have to refresh it. This way you don't have to mess with jars or the Eclipse build process.

share|improve this answer

Your Answer


