Android Development - Tips, Tricks, and Information
Google is constantly pushing the envelope with the incredible Andriod platform, and for developers, the rapid changes can also bring on big headaches! For example, recently ICS (Ice Cream Sandwich) and other fantastic improvements to the user experience and development resulted in ADT Plugin for Eclipse "ADT 17.0.0 " and SDK R17 (click or touch here to visit the android SDK web site for specifics). Unfortunately, as mentioned to us by some associates, a number of developers have hit a snag costing hundreds of hours (and for some thousands of dollars!) for a very simple issue related to class resolution - the often dreadful "NoClassDefFoundError" exception.
Here is the basic scenario for a developer:
Everything is working perfectly, the error log is empty except for possibly a couple of key-binding conflicts and one or two trivial warnings unrelated to the app under development. The target for this app is 2.x, and we are now ready to move on to 4.x and install the R17 SDK and Eclipse ADT plugin. Yippee, it is about time for something new and fun! BTW, this part can really be fun for software engineers and developers because often several cool productivity enhancements, bug fixes, and technology sweet spots come about and break the boredom of software construction and the endless slaying of the demon bugs in the code (-;
OK, aside from maybe needing to update the Eclipse IDE (Helios (3.6) is a minimum dependency of R17, as is Java 1.6 ... touch or click here to read more about dependencies and improvements, etc), the update process is very simple and Google keeps improving this with each release. Once the updates are complete, the first thing to do is fire up a project in Eclipse, clean, and run it on a development device. Sweet ... that is until ...
03-24 02:10:38.241: E/AndroidRuntime(1874): FATAL EXCEPTION: main
03-24 02:10:38.241: E/AndroidRuntime(1874): java.lang.NoClassDefFoundError: com.urbanairship.AirshipConfigOptions
... and the list goes on! (-;
The issue here came from a bug fix in R17 and a simple change in the project structure / file location hierarchy related to external libraries (those Jar files we love to use.) In the previous release, the folder name was "Lib" and in R17 it is "Libs" - that is it. What made this difficult for many to figure out is that the project build process and normal consistency checks do not give any indication of the problem. Also, the libraries (jar files) are properly listed in the Java Build Path. However, ADT is not finding them "exported" because R17 automatically exports jar files from Libs and not the previous Lib folder. As you will see above, this caused problems with the Urban Airship push notification instantiation early on, so we never got to the unit tests or other testing. Once all external jars were moved to the Libs folder, and the original Lib folder is deleted, all is good and everything is playing like a fine tuned fiddle [including our customer's Joomla CMS pushing notifications to Android Apps!]
In summary, the solution for NoClassDefFoundError after update to Eclipse ADT R17:
- Create a new folder in the project names "Libs"
- Right click project name > New > Folder
- Folder Name: Libs
- Move jars from "Lib" folder - simply "drag and drop" in Eclipse
- Remove libraries from Java build path :
- Right click project name > Properties > Java Build Path > Libraries Tab
- Remove the Jars that you previously Moved into the Libs Folder (if they are still showing up in the build path setting)
Note: Professor Ed hears about many developer situations like this not to mention his own "challenges" with public and private mobile development projects. Although the "fix" is not always as simple as described in this article, many devs complain of spending countless hours recovering from an otherwise innocuous software update. If you have a scenario you would like to share with us, or if you are stuck and need help, feel free to drop Professor Ed a line! Touch or click here to view the Wise Apps contact page.
The following table and information is a reprint from March 25, 2012 so it may be stale now - click or touch this link to visit the awesome Google Android Developer web site.
|installer_r17-windows.exe (Recommended)||37410775 bytes||5afaf6511ebaa52bd6d1dba4afc61e41|
|Mac OS X (intel)||android-sdk_r17-macosx.zip||33867836 bytes||52639aae036b7c2e47cf291696b23236|
|Linux (i386)||android-sdk_r17-linux.tgz||29706368 bytes||14e99dfa8eb1a8fadd2f3557322245c4|
Here's an overview of the steps you must follow to set up the Android SDK:
- Prepare your development computer and ensure it meets the system requirements.
- Install the SDK starter package from the table above. (If you're on Windows, download the installer for help with the initial setup.)
- Install the ADT Plugin for Eclipse (if you'll be developing in Eclipse).
- Add Android platforms and other components to your SDK.
- Explore the contents of the Android SDK (optional).