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.

Google App Engine

It is amazing what a month in South Africa does to you. Things like Twitter, Facebook and blogging becomes pretty distant… But now I have been home for a while, Sun+Oracle has been approved by EU, I have finished (almost) my kitchen renovation and celebrated yet another birthday, so it is time to get started again!

After a discussion with a colleague at a coffee break this morning, I decided to try out Google App Engine. The getting started guide is a great place to start. It gives you a great walk-through setting up the development environment and creating a sample application. Since I am no big fan of Eclipse, I installed the Google App Engine Plugin for NetBeans. After resolving a small issue regarding path settings (see solution here), it was up and running perfectly.

Next steps will be to figure out what changes that has to be made to my existing applications to be able to deploy them on app engine. Probably the server side of YouOweMe will be the first candidate. Or maybe the KanbanFX server. I haven’t decided yet…

Company Internal Twitter – good or evil?

This week Yammer was introduced to the entire company. Simply put, Yammer is a company internal twitter where coworkers can connect and share information by posting messages.

At first, I was skeptical to the whole idea thinking it would generate an overload of noise for a couple of weeks until dying slowly like most initiatives to share knowledge within companies. But after having thought about it, I really hope that will not happen. It is actually a brilliant way of building a knowledge base within the company. Everyone who has tried to establish some form of knowledge exchange know how hard it is to get people to contribute.

But by “hiding” it behind some familiar technology like twitter, people actually contribute without knowing it. If you think about it, only the things people are interested in will be posted and discussed in such a forum. People will only put energy in discussions they have strong feelings for. The things most people have feelings for are probably pretty relevant things for your organization. And it is by default fully searchable with the newest items most visible.

So with my limited experience of yammer (have used it two days), I will conclude that it is actually a good thing. Now we just have to hope that it does not die a silent death when it is not that new-and-cool anymore…

Our Irrational Fear of Real-time Exposure

I made an interesting observation when I was at one of the sessions at the Øredev conference today that struck me as kind of weird…

Even though we are out there exposing ourselves on facebook, blogs and twitter, we are not comfortable sitting next to someone that are watching us typing while we are writing our blog post or tweet. As soon as we hit the submit button everything changes. Now we actually want people to read the stuff. That is why I call this

our irrational fear of real-time exposure

Exposure is fine, which the popularity of facebook and twitter are evidence of, as long as we are not caught doing it. Feel free to tweet, blog or comment on this 🙂

Øredev 2009 – Day 3

I was not present at the conference yesterday, so this is actually my second day here, and that also explains why there were no post from yesterday. Another explanation could have been that I was lazy, but that is not the case this time… 🙂

Well, over to what this post is all about: the conference. The keynote was held by Scott Hanselman. He gave an excellent talk about effectiveness and efficiency. Some really good stuff to bring back from that speech. Will try to list some of the techniques and tools he mentioned in a later blog post.

I will also summarize the rest of the sessions I attended today very soon here…

Great conference!

Øredev 2009 – Day 1

The conference was opened with a keynote by Marc Lesser. He talked about how to accomplish more by doing less. It was a kind of usual opening of a technology oriented conference, but I guess a bit of zen thinking early in the morning can only do us good.

Ola Bini presented the folding language Ioke. I will definitely download this and play around with it. Hopefully, I can use it in some presentation in near future. Really cool and fun!

The next presentation I attended was Neal Ford’s presentation about XP in practice. Nothing really new there, but more a confirmation that what I feel we are doing right applies to others as well. And, more valuable, tips and techniques for how to improve on what we are doing not so right. At last a kind of nerdy way of looking at pair programming:

  • 100 eyes
  • 010 brains
  • 001 mind

Continuing on the agile track, Dan North gave an excellent talk about our obsession with efficiency. The three key points to remember from his talk is:

  • You get what you measure
  • Not all vendors are bad guys
  • Efficiency isn’t effective

Back to the languages track, I attended a talk by Neal Ford where he compared Groovy and JRuby. It gave me a pretty good comparison of the benefits and drawbacks of both languages.

The only session on the Java track was a disappointment. The only thing I really got from this presentation was that I could charge my netbook’s batteries. Still running OpenSolaris on it, by the way, and is generally happy with it!

Last technical presentation today was about clojure. Kind of tough thing to jump into this late in the afternoon, but the presenter, Stuart Halloway, did a great job.

In the afternoon keynote, Cameron Purdy did a comparison of Java and C++.

Overall experience from the first day of the conference is good. It is impressive that they have gathered so many international speakers. If I should pick on something, it has to be that the opening of the conference would benefit from being a little more flashy. Maybe have the opener learn his speech and practice on the English pronunciation…?

And now, it is time for mingle and beer!