I know it seems like it’s all Android every day around here, but don’t fret will be back on Apple’s Johnson in time enough for their September 10th announcement. One of our projects involves porting a large chunk of useful legacy code from Windows to Android. Lord knows the toolset for Android is primitive enough, but debugging is like taking a walk in the Paleolithic era.
If you have the guts to boldly go where No Man has Gone Before follow these simple steps to make your NDK experience worthwhile.
This week on theSync, the critical steps to get you rollin with the NDK.
1. Stick to an NDK Build
Decide on an SDK version and stay there. Once you get the ADT installed it’s hard to keep your toolsets intact if you’re constantly updating. On our project, we’re using a bespoke build of the Crystax NDK. If you need wide character (wchar) support you’re not going to find it in the factory available build of the Android NDK. If wchar_t support isn’t a deal breaker for you, don’t go aftermarket and stick with the build available from Android’s site. There’s isn’t enough extra in Crystax to justify using it beyond wide char support. That is unless you’re using something like Boost, another custom library that we built for Android.
2. Get Cygwin
Download and install Cygwin if you’re on Windows. You’re going to need it to generate the GDB server and device description that’s used to link the Android Debugger with the compiled processor-dependent code. If you’re on Mac or Linux, you already have everything you need. Our brothers on Windows are the only ones suffering this slight.
Once you have Cygwin installed, add to your system’s PATH environment variable the fully qualified path to your NDK build’s SDK folder. When Cygwin starts, this path will be exported. Next, add your NDK build’s toolchain subdirectory to your system path. We will need this path added to run the ndk-debug command.
3. Only Debug on a Real Device
Plug in your device, you should only debug android apps if you have a device. DO NOT EVEN ATTEMPT TO USE THE EMULATOR. The emulator is notoriously slow and you will suffer through the debugging experience. Android devices are cheap; so, if you are venturing into Android development do yourself and get a device. Once you have the device we need to setup.
- Open up a shell and change directories to your project path
- Next, execute the ndk-debug tool, this will drop the device description and ABI
- Now you’re really ready to debug
4. Debug a Native Android Application
Back-in-the-day, a year ago, you would need to create a custom debug configuration that would spool off the ndk-debug task, load the server file, and magically hook into Eclipse. Enough game devs lobbied Google to add native debugging to Eclipse. Go ahead and set a breakpoint. Because Eclipse sucks, right-click your project, cross your fingers, and select Debug As >> Native Android Application. In the so called modern era, Eclipse will create a new Debug Configuration for your project automatically, the internals will traverse your project tree and find the debug description and ABI configuration. It takes a moment, but when the server kicks in and your break point is triggered, Eclipse will automatically throw you into the Debug perspective.
5. Email Google and Cuss Them Out
I’ve kept my feelings to myself for a long time, but I can’t stand it anymore. I’ve been writing software professionally since 1994. I’ve written software for satellite, telecom, data processing, and mobile systems. I’ve used a number of platforms, written software for a number of targets, and used numerous IDEs from Visual C++ 1.52 to Visual Age to JBuilder to XCode to Studio and now Eclipse. And I have to say, the Eclipse development experience is the worst experience I’ve had since Borland Pascal. It’s hard for me to bestow the same level of respect to Android as other platforms I’ve worked on because the software writing experience is so poor. I have the ADT installed on Mac OS X and Windows machines for development, and I’ve had Eclipse zero out files, I still don’t understand why I can’t terminate applications from the debugger, watches are slow as molasses, and it’s generally unstable. I’ve had marathon coding sessions in Eclipse only to find out that logcat no longer works or copy/paste operations happen in the wrong files. Our project is comprised of C++ and Java and there are times when the NDK build is successful, but the C++ Indexer detects include errors preventing a debug session to start. Seriously Google, with all of your billions and talent, you can’t put together a scratch team and build an IDE worthy of the platform? Yeah, I get it, an IntelliJ IDE is coming out soon, but I can’t help but think that you may drop this platform like a hot potato if you won’t dedicate resources to creating a solid experience for your developers. I’ll say it here, the best development experience is Visual Studio, and yeah, no one uses Windows Phone, but at least Microsoft cares enough about their developers to give them the tools to succeed.
Email Google and tell them that if they really believe in the Android OS to support their developers with a properly architected and modern toolset respective of their company’s status.
I’d like to hear about your experiences working with the Android NDK. Please add in tips and tricks in the comments.
Thanks for listening, and reading. You’ve been synced.