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…

One Week With IntelliJ IDEA

A week has gone since JetBrains announced the free and open source IntelliJ IDEA Community Edition.

I have been giving it a try and is actually pretty satisfied with it. Even though I am not as familiar with all the shortcuts as I am with NetBeans, it feels comfortable. It does not differ that much. The only problem I have encountered with the default setup is the shortcut for comment/uncomment code (Shift+/). But this is mainly because I am using Swedish or Norwegian keyboard setup where the / is entered by hitting Shift+7. This was easily fixed by adding Ctrl+Shift+7 as a shortcut combination.

I could not find a live template for test methods, but it was easy to create a new one. Here is a simple example:

public void test$NAME$(){
   $END$
}

I am not sure if I like the way multiple projects are handled. If you work with multiple projects in IDEA, each project is opened in a separate frame. In NetBeans you can choose to have multiple projects open in the same workspace and/or group them in project groups. It is probably just a matter of habits, but I like the flexibility to be able to decide that myself and not be forced to open every new project in a new frame.

To conclude, I really like IDEA Community Edition, an will most probably choose use it when I am working on a project where I am in no direct need of Java EE support in the IDE. Otherwise, NetBeans is still my favorite IDE. Eclipse is still out of the question as long as Maven is involved.

IntelliJ IDEA – Now Free and Open Source

Despite the fact that it comes with a price tag, IntelliJ IDEA from JetBrains has since long been a very popular IDE in the Java community. The news that they now provide a free and open source community version was therefore very welcome.

If you have been reading this blog, you probably know that I am quite a big fan of NetBeans and have written quite a few comments about the areas it excels over Eclipse. I have not really tried IntelliJ IDEA yet, but now the Community Edition has been downloaded and installed. JetBrains has provided a detailed comparison between the Community and Ultimate edition.

First Impression
The first impression is that it is fast. The startup time is significantly faster than NetBeans. The editor is responsive, shortcuts and refactorings just as you expect them to be. It sure is ugly, menus and dialogs looks like some left over AWT student project hack from the 90’s, but who cares. After all we are here to code, not to enjoy the view.

Maven
The next test is to open one of my existing multi-module maven projects. Just as with NetBeans, it is just to select the root pom.xml file and open it. All sub-modules and dependencies are resolved just as expected. It scatters a lot of .ipr, .iwl and .iml files all over the place, but I can live with that as long as it updates them with changes from the pom.xml files.

When I check the Module Settings, it seems like the compiler output is set to /classes and not /target as normally by the maven convention. But when i build the project, it uses the maven configuration and puts the compiled classes under target. Why? Well, as long as it works it is okay with me…

Web and Enterprise
As the comparison table shows, there is no support for any web, mobile or enterprise frameworks in the Community edition. Nor are there support for application servers. You would have to buy the Ultimate edition for this. Fair enough, they have to make money somewhere.

Conclusion
The Community Edition of IntelliJ IDEA is the perfect choice if you are building a simple java application. It lacks support for development using web, mobile or enterprise technologies. If you want an IDE that is comparable to for example Eclipse Gallileo or NetBeans you would have to go for the Ultimate Edition. In my view NetBeans is the better choice.

Disclaimer: I  have only scratched the surface here and will continue explore the Community Edition. My opinions may change as I go…

Some Thoughts in General

I have been kind of lazy writing this blog lately. After keeping it up pretty okay during summer, the pace has now slowed to a minimum. I think it can be partly explained by the fact that I have been using Twitter for some of the stuff I used to write here and that my new HTC Hero Android phone made tweeting more convenient than ever…

My intentions are to use this blog for subjects that cannot easily be said in 140 characters and twitter for the short, more daily stuff…

Well, so what has happened since last time. Since I have solely been using NetBeans the last couple of years for Java development, I decided to give Eclipse Gallileo a chance. It took me an hour of frustration to conclude that it still sucks for Maven based projects. Why it should be so hard is beyond my comprehension! In NetBeans, you just choose open project, selects the pom.xml file and everything is fine. Dependencies are resolved as they are defined in Maven, no stupid .classpath, .project and .settings rubbish created that makes Eclipse to totally hick-up if a dependency is changed.

Apart from my unsuccessful flirt with Eclipse, I have continued development of KanbanFX. It has been converted to a maven project and besided the information on Kenai, I have created a page for it here where you can try it out. Kanban is increasing in popularity, @henrikkniberg had 300 people on his Kanban vs Scrum session at JAOO this week.

KanbanFX

I really like the simplicity in Kanban. It should be enough for most small projects, and especially AO teams. Even though all you really need as tool support is a white-board and a couple of post-it notes, larger organizations often require you to hook into existing tools for requirement management, issue tracking etc.

I have not been able to find any tool fulfilling this need, so I decided to create on myself. Thereby, KanbanFX was born!

KanbanFX is a JavaFX implementation of a Kanban board. Source code and a very limited demo version is available on Kenai:

http://kenai.com/projects/kanbanfx.

Please join the project if you want to contribute. I am pretty sure that I will need help with at least the graphical elements when we get to that…