Archive for the ‘Android’ Category

I return to school at noon, but before then, I’d like to share my evening project: agcc.bash, a rewrite of agcc and agcc2.pl that works with revisions 6 and 7 of the Android NDK.

The NDK is a GCC-based cross-compiler that lets you embed object code in a traditional Android app. It also works as a standalone cross-compiler, though it is not advertised as such. It is quite rough when used by itself, and agcc wraps the complexity in a little script. While agcc and agcc2.pl are written in Perl, agcc.bash is a Bash script. It also supports the latest revisions of the NDK, though r7 is slightly buggy.

With agcc.bash, building native Android software feels almost like working with GCC. As a quick example, let’s try the classic hello world:

AGCC_NDK=~/android-ndk-r6 ./agcc.bash hello.c -o hello

That wasn’t too exciting… but what happened there? I have the NDK installed at ~/android-ndk-r6 and I told agcc.bash where to look for it, using the AGCC_NDK environment variable. I then invoked agcc.bash as if it were GCC. Let’s see what agcc.bash did behind the scenes:

AGCC_NDK=~/android-ndk-r6 AGCC_ECHO=yes ./agcc.bash hello.c -o hello

=> ./agcc.bash hello.c -o hello
<= /home/jyio/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc -o hello -I/home/jyio/android-ndk-r6/platforms/android-8/arch-arm/usr/include -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -DANDROID -DSK_RELEASE -DNDEBUG -UDEBUG -march=armv5te -mtune=xscale -msoft-float -mthumb-interwork -fpic -fno-exceptions -ffunction-sections -funwind-tables -fmessage-length=0 -march=armv5te -mtune=xscale -msoft-float -mthumb-interwork -fpic -fno-exceptions -ffunction-sections -funwind-tables -fmessage-length=0 hello.c -Bdynamic -Wl,-T,/home/jyio/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/arm-linux-androideabi/lib/ldscripts/armelf_linux_eabi.x -Wl,-dynamic-linker,/system/bin/linker -Wl,–gc-sections -Wl,-z,nocopyreloc -Wl,–no-undefined -Wl,-rpath-link=/home/jyio/android-ndk-r6/platforms/android-8/arch-arm -L/home/jyio/android-ndk-r6/platforms/android-8/arch-arm/usr/lib -nostdlib /home/jyio/android-ndk-r6/platforms/android-8/arch-arm/usr/lib/crtend_android.o /home/jyio/android-ndk-r6/platforms/android-8/arch-arm/usr/lib/crtbegin_dynamic.o -lc /home/jyio/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a -lm -ldl

See how it transformed our innocent little command into a monster! This might be overkill for a hello world program, but it provides pretty good support for more complex software such as OpenSSL, cURL, and Python. It would be a good idea to add the NDK toolchain and agcc.bash to $PATH before trying to build a big program. In my case, the toolchain resides in ~/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin. If you want to build some software that come with configure scripts, you might start with:

CC=agcc.bash ./configure

Do try this at home! Relevant links:

Some of you might remember this lowly device. Once upon a time, it was the talk of the town. When the mobile carriers stopped issuing updates, CyanogenMod became one of the predominant variant distributions. But now, with official support dropped from the Android Open Source Project, even Cyanogen and his team are having trouble keeping up. I am, of course, talking about the HTC Dream; this review will cover a number of ways to keep this device up to date, and may apply to the HTC Sapphire/Magic as well.

Read on »

Opkg is not limited to using packages from files; it is also capable of using apt-get style repositories, vastly simplifying the job of fetching dependencies and updating packages. I already have a repository set up, and it could be added as such

echo "src/gz inportb-android-froyo http://repo.inportb.com/android/froyo" > /cache/etc/opkg/inportb.conf

After doing that, we could refresh the package list

opkg update

Installing a package then becomes as easy as

opkg install name-of-package

And we could keep all our packages up-to-date using

opkg update; opkg upgrade

It’s also quite simple to set up a repository for distributing packages.

Read on »

Now that we have Opkg for Android, we could use it to install packages from local files or off Web servers. Installing a package is as simple as

opkg install path/to/package.opk

or, if it’s on the Web

opkg install http://host/path/to/package.opk

And to remove the package, we would go

opkg remove name-of-package

But what if we wanted to share our own software with others? In this case, we would create our own packages. An Opkg package is essentially a Debian package with fewer control fields. If you know how to make a Debian package, you should be well on your way. In general, a package is an ar archive containing a control tarball, a data tarball, and a debian-binary file. For example let’s have a look at the opkg-hello package:

Read on »

Well, almost. While one could theoretically install Debian packages on Android phones, it is generally a bad idea to install software designed for one system onto a different system. However, the Debian package manager is excellent for keeping track of software, and it would be nice if it could be used on Android as well. iPhone users already have access to this mechanism in the form of Cydia, so why not put it on Android too?

Read on »

Recently, I rewrote from scratch a two-year-old project of mine. Imagine, a browser-based image editor, had been sitting around collecting dust, so I figured I’d delete all the legacy code (almost all of it) and create something better. I’ve also been evaluating the possibility of integrating Imagine into Google Wave.

Read on »

A recent trick floating around the xda-developers forums involves using UnionFS to layer the microSD storage on top of the existing data partition, effectively allowing the microSD storage to be used for data. This technique originated from MarcusMaximus04 and has made its way into the firmware builds of TheDudeOfLife and JesusFreke.

While most users were playing around with the easy “apps2SD” feature, I decided to explore a different aspect of UnionFS — stackable snapshots. The goal was to be able to make snapshots of the filesystem that could be rolled back at any time, undoing any changes. While this may sound like server-oriented technology, it could be useful on a mobile platform that is collecting a sizable hacker community.

Read on »

Really, there is no need for this post… because Cupcake (an updated version of Android found on the HTC Magic and ported over to the G1) is quite friendly to users without data service. The ability to skip activation allows the user to delay activation until the WiFi connection can be initialized. And since rooting is required, the modified recovery image and engineering SPL makes backup-and-restore trivial.

Read on »

Haykuro has recently released a series of Android builds. This is the software for the HTC Magic, ported to the G1. Since I have not had time to fully explore this new operating system, I’ll just list some of the most obvious changes:

  • activation not required! (can set up account later)
  • new theme
  • new camera options, such as video recording
  • lock-screen background
  • 3G notification icon says H
  • smooth transitions by default
  • automatic screen orientation flipping
  • no more voice search in search widget
  • on-screen keyboard
  • … among other things …

Now, it is actually pretty simple to get this software. There’s even a nice guide for this, which was pretty straightforward for me to follow. Nevertheless, since I had not rooted my phone and I have no data plan, I had a couple of extra steps.

Read on »

The Market cache has been a source of grievance for many Android/G1 users. Applications under Android store data in caches that are cleaned up when memory is running low. The G1 has an unimpressive amount of onboard memory, and the Market browser has a cache that cannot be manually cleared. This has lead to many individuals performing factory data resets on their phones just to reclaim the sequestered memory.

The factory data reset is not the best approach. In fact, I would say that the best approach is to do nothing at all about the problem. By virtue of Android’s memory manager, caches are cleared automatically when memory is needed. For example, if the foreground task needs to do something memory-intensive and there are some background tasks and caches, some of the tasks could be killed or caches could be cleared to make room. So… the problem solves itself.

One does not need to manually reclaim the memory, but what’s wrong with doing it anyway? I mean, it does get rid of the low-memory warnings that are so distressing to some. However, the biggest problem with clearing caches is the act itself. Caches perform the useful function of storing objects so that they need not be computed or fetched again, saving processor, networking, and power resources. One can even say that memory exists mainly for the purpose of caching. Therefore, it would be optimal to fill the memory as much as possible with cache. The system that Google set up is almost perfect — it allows the memory to fill with cached data, clearing bits at a time only when needed for a foreground task.

But why isn’t it perfect? Well, I had mentioned the low-memory warnings earlier. When the average user sees one of these, he/she thinks that the phone is about to explode. It’s not; rather, it’s a sign that the memory manager is doing its job. The psychological aspect of the problem can be resolved by either removing this warning or making it appear more benign, reserving the real warning for when the memory is really running out.

In the interim, I’m going to hang onto my caches and encourage you to do the same. There is no harm in taking the need-based memory management approach. Remember, unused memory is wasted memory.