Øredev 2010 – final thoughts

Having attended all previous Øredev conferences I think I am pretty qualified when I say that this year’s conference was by far the best. Great topics, excellent speakers and flawless organization. Even the closing panel debate, which usually is just something you have to suffer through to be able to win prices in the raffle at the end, was interesting this year.

Since it is such a diverse conference, it is difficult to point out a single item that was the main trend at the conference. But if I should pick one thing, I guess it would be that most of the talks I attended more or less circled around the Get Real! theme of the conference. Hopefully this means that the industry is getting more mature. Don’t want to be a self-fulfilling pessimist, so it is just to be optimistic 🙂

See you there next year!

Android Emulator Workaround

Here is a small tip if you are having trouble running the Android Emulator for code that calls native methods and getting an error message similar to this:

JNI WARNING: method declared to return 'Ljava/nio/ByteBuffer;' returned 'Ljava/nio/ReadWriteDirectByteBuffer;'
... ;.nativeAsBuffer ('Ljava/nio/ByteBuffer;' not found)

The simple workaround is to add the following to the onCreate method of your main activity:

ByteBuffer dummy = ByteBuffer.allocate(0); dummy = null;

This way the classloader is “forced” to load ByteBuffer. This is not needed when running on a device, only the emulator as it seems.

Android Development for Google Nexus One

This post is just a repeat of my tweet yesterday, but I feel that it is easier to search it up again here than on Twitter. A good tip can never be repeated often enough anyway…

If you are setting up the development environment for Google Nexus One in Linux by following the instructions on Android Developers you will probably notice that the the device is not listed in vendor id table. One could believe that it could be the same ID as HTC since it essentially is a HTC device, but that is not so. Google has given it a vendor id of its own (’18d1′). Why it is not listed here is a mystery, but anyhow; this is how you solve it:

Add the following line to /etc/udev/rules.d/51-android.rules
(If the file does not exist, create it.)

SUBSYSTEM=="usb", SYSFS{idVendor}=="18d1", MODE="0666"

Restart udev:

sudo reload udev

Then unplug/plug the device, and you should be able to see the device by running

adb devices

NetBeans and Android Tip

Developing Android applications using NetBeans is usually as easy as stealing candy from a baby. But the last couple of days I have been struggling with an application that uses a couple of external libraries. The other developers (using Eclipse) have a couple of scripts that they run to get the .so files included in the .apk file. When I tried running the same scrips on the .apk generated from NetBeans, the application failed to start in the emulator. I nearly switched to Eclipse (god forbid), but then I saw the light again. As it turns out, NetBeans does not include the java api jar-files in the external libs in the dex-file by default which resulted in a ClassNotFoundException.

The solution is as simple as you would expect when you have used NetBeans for a while. Add the following to the build.xml file in the project root (replace the dummy values for the signjar target):

<target name="-pre-jar">
   <copy todir="${build.classes.dir}">
      <fileset dir="${external.libs.dir}">
         <include name="*.jar"/>
      </fileset>
   </copy>
</target>
<target name="-post-jar">
   <zip update="true" destfile="${dist.apk}">
      <zipfileset dir="${external.libs.dir}" includes="*.so" prefix="lib/armeabi"/>
   </zip>
   <zip destfile="tmp.apk">
      <zipfileset src="${dist.apk}">
         <exclude name="META-INF/*.*" />
      </zipfileset>
   </zip>
   <move file="tmp.apk" tofile="${dist.apk}" />
   <signjar jar="${dist.apk}" alias="alias" storepass="secret" keypass="secret2" keystore="my_keystore"/>
</target>

You also need to add external.libs.dir=<your lib folder> to you <project root>/nbproject/project.properties file.

Now you can install the resulting .apk file using adb install or by running/debugging directly from NetBeans. Remember to follow the tip for asset-files in a previous post if you have that kind of resources.

Android Emulator and NetBeans

Whenever you ask or search for help regarding Android development, you end up with some fix related to the Eclipse ADT plugin or the Android SDK tools. My intention is to fix that by repeating parts of a great tip I found at Tim Perry’s blog. It is about how to get hold of the resources placed under the /assets folder in you Android project while running your applictaion in the Emulator from NetBeans. If your application tries to access resources from the AssetManager you will get a FileNotFoundException. The reason for this is that the assets are not packaged with the .apk like it is if you package and deploy it using the SDK tools.

The solution is:

  1. Go into nbproject/project.properties and add ‘assets.available=true

Voila! You will now be able to run, debug and step through your code as you would expect.