How to avoid Android compilation/building issues – Setting up the Eclipse Buildpath correctly

This post is the product of about 48 hours of not being able to work on what I was supposed to be working because I had to deal with build issues in Eclipse.

Hopefully If you follow these steps you will be able to solve some of the issues you may be facing right now with your build.

Some of these issues are:
– Class not found errors, even though your app was built and uploaded to your device.
– R.java not being compiled.
– *.aidl interfaces not generating .java files.

Screen Shot 2013-05-20 at 6.09.53 PM
1. Make sure your project’s compiler is set (as of the current android release) to be Java 1.6 compliant.

If you work on several java projects outside of Android, you may probably need to work with Java 1.7 compiler specs and by mistake you may have set it as the default for all projects.

This may cause a lot of stuff to break on your Android projects, including the generation of .java files out of .aidl files.

Make sure your Android project is using Java 1.6 (which is sadly all of what Android supports as of this writing)

2. Make sure the .jars you want to export are CHECKED in your Java Build Path > Order and Export settings

Screen Shot 2013-05-20 at 6.24.00 PM

After updating my Android SDK tools last friday, I wasted a whole day trying to figure out why on earth my application was giving me runtime Class Not Found errors on classes that exist inside android-support-v4.jar, even though I had all my jars placed on the proper standard “libs/” directory in my project.

The culprit was that the checkboxes along the .jars in my Order and Export tab were not checked.

3. Make sure your source folders are placed in the right order in your Java Build Path > Order and Export settings

Screen Shot 2013-05-21 at 12.13.46 PM

That right order for me has been:
1. My source folders at the top.
2. The “gen” folder right after the source folders.
3. My jars and Android dependencies at the the bottom.
4. Make sure “Android Dependencies” and “Android Private Libraries” are all the way at the bottom. I found out having them before the .jars causes issues when you want to attach source code to your .jars, eclipse will try to browse the .class inside the “Android Private Libraries” which does not allow for source code attachments, therefore not letting you see the source code you’ve attached on the build settings.

3. Make sure the .jar dependencies you need are saved inside the libs/ folder in your project.

That’s all I have for you.
Clean and Rebuild.

Submit a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.