Monday, June 27, 2011

NetBeans is now Android friendly

Some time ago I have heard of an attempt to develop an Android app in NetBeans. It sounded a lot like a story of a masochist though. I believe it was done like that. The resources didn't work, there was no support for editing layouts or other XML files. It wasn't a pleasant way to code but some prefered that to switching from their favourite IDE.

Well, I have some good news for NetBeans users - yesterday, on official Oracle blog, there has been posted a Dummy Guide to NetBeans Android Developement. Quickly followed by 5 Step Procedure For an Android Deployment.

The method described on the blog uses a set of plugins called NBAndroid, which have been developed for some time now (the beta label was officialy removed on May 21th in a version 1.7). 
As far as I can tell and as is described on NBAndroid blog, currently it supports code completion in XML files, attaching a debbuger at runtime, building singed APKs, some support for test project and more.

While I prefer to do my work in Eclipse, I am curious about the NetBeans implementation and I will defenitely check it out.

Thursday, May 26, 2011

Tools of an Android developer

LogcatImage by Gubatron via Flickr

Being an Android developer for about 9 months I have collected a number of tools, methods and solutions that help with some of the problems and challanges when creating on Android apps.
Some of them were found on the Internet, some of them in books others by accident or cracking my head against some issues again and again.
In a series of posts I'd like to share some of them with you.

Let's start with some tips on Logcat which is a powerful logging tool and can help you greatly in daily developement.
  •  Resetting logcat - Logcat does not like too long log entries. When given such it stops displaying other logs and informs :
  • Logcat read - invalid argument error 
  • There is a simple solution for that - be careful what you log. ;)
  • Clearing (flushing) the log solves works well to and it can be done by running :
  • adb logcat -c
  • Note that this works for a logcat run from a command line but unfortunately Eclipse needs to be restarted after that.
  • 'Where' did I log ? - I have encountered two ways of getting meaningful messages on logs :
    • Define a public static final String field that will be instantiated with YourClass.class.getName() - and use it as first Log.* argument, the method name and 'what' can be the second argument.
    • Create a class with a static method that would throw an exception, catch it, log its stacktrace and log your message, if any.
  • If you are using a lot of logs to check what's happening, perhaps you might want to use Android's debbugger which works very well or better yet - write some tests.
  • Try to be as consistent as possible when chosing your log level (debug, info etc.) because when you use Proguard to remove some of them on your production version (this will be explained later on) you might lose some useful information.

That would be all on Logcat at this point. My next posts will show you how to work with a mavenized Android project in Eclipse, how can you use Spring for Android, some different Proguard configs (to remove Logcat for example), some hints on persisting data, especially the data you use in your current task and more.

Also you might want to check out my other post (in polish) on a Android-themed meeting in my company. We were talking about Android's success from both user's and developer's perspectives.


Thursday, January 27, 2011

Setting up Grails project on Oracle XE database

If you have some code already working on another database, say Postgres, and you want to set it up on Oracle XE database, there are some things to consider.

You have to change the application data source (conf/DataSource.groovy) and move the Oracle jdbc driver to /lib - all that is explained pretty well here.

Basically the result will be something like this :
production {
   dataSource {
       dbCreate = "update" // or create, create-drop
      boolean pooled = true
      driverClassName = "oracle.jdbc.driver.OracleDriver"
      username = "[the username]"
      password = "[the password]"
      dialect= "org.hibernate.dialect.Oracle9Dialect" // or "org.hibernate.dialect.OracleDialect"
      url = "jdbc:oracle:thin:@127.0.0.1:1521:XE"
  }
}
You might have some troubles with the url, here is a little explanation :
I was running the XE database on my local host, hence the address 127.0.0.1.

XE is the default SID for Oracle XE.

The 1521 is the default database listener port for Oracle XE.

Oracle XE and port setup

While we are talking about ports. The default http interface port for Oracle XE management through APEX is 8080 and it might be in collision with other software you are running, like our grails app.

You can read on here to find out the way to check default ports and those set on your configuration and also how to change them.

Oracle XE and reserved words

If you are seeing a lot of stack traces while running your grails app on the new configuration, chances are that your domain classes use field names that are reserved in a Oracle database. Try to stop the start up before all the stacktraces. If you see something like "table could not be created" and "ORA-00904 Invalid identifier" run  "select * from v$reserved_words" and check if your domain names or field names collide with the reserved words.