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.
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.
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!
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:
Preferences
-> Java
-> Compiler
) and the individual project settings. Choose 1.6 as the compiler compliance level.Properties
-> Java Build Path
-> Projects
. Add all Java projects you want to use in your Android project.libs
subdirectory (and this is the step which lets Android know your .class files!). See below for the code.Here is the code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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"/>
</jar>
</target>
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:
<?xml version="1.0" encoding="UTF-8"?>
<project name="CommonsCopy" default="copy" basedir=".">
<target name="copy">
<copy todir="bin/classes">
<fileset dir="../Commons/bin" includes="**/*.class">
</fileset>
</copy>
</target>
</project>
2 things to remember:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With