Android class not found exception

Currently I am working on some Android project at work. Because the application we are developing communicates with server, we decided to pack common entities in .jar. That way our projects (server and android client) can share it and we avoid unnecessary code duplication. It is much easier to make changes as well as we don’t need to apply changes on different places in our code…

In our standard Java EE applications we use Apache Ant for building project and deploying it to server. So I created a task which packed common classes into jar and copied it into libs folder in our android project. Now I was able to use common classes. I refactored some code and started Android project to test it. But build failed with Class not found exception … I checked again, all needed files were in jar, jar was in libs folder, classes were included in “private libraries” … After a bit of googleing I discovered that this might be because files were compiled with java 1.7, which Android doesn’t support, instead of 1.6. I was surprised, because I knew I set my java to 1.6 in eclipse workspace. Then I remembered that Apache Ant uses its own JRE. After changing JRE for Ant, everything worked fine :)

Here are short instructions on how to change ANT’s JRE:

First, right click on ANT task you want to run:


ant_configure

A new window will open. Select JRE tab and here you can set which JRE you want to use.

change_jre

Leave a Reply