Android project referencing “normal” java project in eclipse since sdk tools update 17

前端 未结 5 2316
甜味超标
甜味超标 2020-12-15 19:57

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

5条回答
  •  无人及你
    2020-12-15 20:56

    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:

    
    
    
        
            
             
            
    
            
        
    
    

提交回复
热议问题