Added a repo to GitHub

In preparation of my workshop during Herbstcampus in Nuremberg later this summer, I pushed a repo to GitHub. Currently the repo contains two versions of a small sample app I call OpenWeatherMapWeather. Here is what we have so far:

I will add a version using Gluon and Windows 10 soon. So stay tuned.


Getting just a little more productive

Sometimes entering a command is just the fastest way to get something done. That's why Terminal or shell windows in IDEs come in so handy. Here is how it looks in Android Studio.

Just make sure all the tools you might need are found. I suggest a regular housekeeping of the PATH environment variable. For example, Android devs may wish to include $ANDROID_HOME/tools and $ANDROID_HOME/platform-tools. Java developers need $JAVA_HOME/bin. Of course, $ANDROID_HOME and $JAVA_HOME must point to the installation directories of the Android SDK and the Java Development Kit.

NetBeans offers a Terminal window, too.

There is a plugin called Terminal Extras. It helps setting a base directory upon invocation of the Terminal. You can download it through the Plugin Manager.

Just pick a project and hit Alt-.

Simple yet great.


A few tipps on finetuning lubuntu

I am currently preparing a Linux installation (VirtualBox client) based on Lubuntu. Though Lubuntu (as far as I know) is not specifically focussed on developers, its beauty lies in the fact that the distro is reasonably small. In this post I will share a few tips on finetuning it regarding developer needs.

Lubuntu after a couple of small changes running inside VirtualBox
Lubuntu after a couple of small changes running inside VirtualBox

As I need a really up-to-date Java development kit, I decided to download it directly from the Oracle website. Though this is mere personal taste, I like to put it in /opt and add a symbolic link without a version. This is convenient as I encourage you to include its bin directory in PATH. Switching Java versions can then be done be changing the link, rather than modifying PATH. This brings us to the question of where to change this environment variable. I chose .xsessionrc in my home directory. Why? Well, if another user doesn't want or need a JDK, I think he shouldn't see it.

 # Java (JDK)
export JAVA_HOME=/opt/jdk1.8
export PATH="$PATH:$JAVA_HOME/bin"

As I need Android Studio and the Android SDK as well, I set it up in .xsessionrc, too.

# Android
export ANDROID_HOME=/home/workshop/android
export PATH="$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools"

ANDROID_HOME comes in handy if you plan to use Gluon Mobile. Well, and access to the tools and platform-tools directory provides quick access to, for example, adb and emulator.

I did not know that I could have installed NetBeans through apt-get, so I downloaded it from the NetBeans homepage. The installer kindly put an entry in the Lubuntu desktop menu. As I wanted this for Android Studio, as well, I added that entry on my own. Here is how to do that. Provided, you have installed Android Studio to /opt/android-studio, just create a file called studio.desktop with the following contents and save it to /usr/share/applications.

[Desktop Entry]
Name=Android Studio
Exec=/bin/sh "/opt/android-studio/bin/studio.sh"

Finally: I am a big fan of Sublime Text 3. Here is how to install it.

sudo add-apt-repository ppa:webupd8team/sublime-text-3
sudo apt-get update
sudo apt-get install sublime-text-installer

That's it. Happen to have any other tips regarding Lubuntu? I'd love to hear them.


My upcoming workshop: Java on mobile devices

From Aug 30 til Sep 1 2016 Nuremberg once again will be home to the Herbstcampus, a conference for software developers, architects and managers focussing on Java, .Net, Mobile, Web and the enterprise.

I will have both the pleasure and honor of hosting a full-day workshop about Java on mobile devices. Titled Ménage à trois, we will be taking a closer look at how to build Android and iOS apps using Java and JavaFX. Based upon the open source project JavaFXPorts and its commercial sibling Gluon Mobile, we will build a few real-world apps and deploy them to both emulated and physical devices.

Interested? Take a look the the schedule:

Introduction of the participants
A little bit of history... Java on mobile devices
A first glimpse at the tools: emulators, simulators and virtualization

Coffee break

Setting up the development environment #2
Creating a project
Running the demo
Looking under the cover (walkthrough)

Lunch break

Gluon Mobile and its components
Using device functions #1
Artefact archeology - what finds its way on a device?
Using device functions #2

Coffee break

If something goes wrong (debugging)
What will not work (missing functions)
What's up? Profiling and performance

Coffee break

Taking a look at alternatives (including demos)
Reality check and wrap up

Sounds good? Remember the early bird offering ends tomorrow, Jul 22. Book now.


Yes it works

Have you tried to deploy a JavaFX app as a Web Start app and failed? Fear no more. The issue is easy enough to fix.

When I started my app as a Web Start app, I was greeted with these two fellows:

Screenshot: Runtime Error

Screenshot: Part of a stack trace

The error message seems obvious. Java is unable to find a resource. To be more precisely, it fails to find an fxml document. The usual diagnosis is... The resource is not there. Or... you are doing that getResources() wrong. 


To put a long story short. Not being able to find the resource here means not being able to access it. My Web Start app was sandboxed. As soon as I requested all_permissions, everything was fine.

So, for example, in a NetBeans project just request unrestricted access. Wham!

Screenshot: Granting a Web Start app unrestricted access


On analyzing Android class and package dependencies

Recently I had to analyze the class and package dependencies of an Android app. Jens Schauder maintains an awesome tool called Degraph. Its purpose is to test, visualize and manage dependencies of classes and packages in JVM byte code. So, I asked myself, why not use it?

Although the Google toolchain used to rely on standard Java byte code as an intermediate step, this may no longer be the case in the future. Its final artifact (the end of the toolchain if you like) consists of one or more Dalvik executables. If you take a look at an Android application package (.apk), you will find a file named classes.dex. Depending on the size of the app, there may be other, similarly named ones, too. As application classes as well as any dependent library are put there, I decided to use the .dex files for my dependency analysis.

The Android SDK contains a tool called dexdump. Its purpose is to provide a (nicely) readable representation of .dex files. Hence, all I needed to do was to bake a small tool that interprets dexdump output. You can find this tool here. It is written from scratch and is completely unrelated to Degraph. Still, I feel the need to credit Jens, especially for his idea to visualize the output of his tool using yEd.

You can extract classes.dex using tar xf. The screenshot shows a small portion of a dexdump output. To use it with my tool, you should create a text file as follows:

dexdump -l plain -f classes.dex > classes.txt

Let's see what DexAnalyzer can make out of it.

As you can see, by default analysis is based upon packages. The following screenshot shows how to distinguish classes and produce a file that can be opened in yEd.

I am going into more detail later. For now I encourage you to play with my tool. Please keep in mind that it is in its infancy. If you encounter any misbehavior, please feel free to let me know. Passing command line arguments seems to not work as expected if options appear after filenames. Also, please note that checked exceptions currently do not count as dependencies. I plan to add this later.


Developing inside the matrix

The Mac is still a lovely machine for developers. I enjoy the beauty of macOS, its slick ui and versatile commandline interface alike. Don’t get me wrong. I love Windows, too. That is why I have a Windows 10 running inside VirtualBox. This allows me to work with Visual Studio, for example in order to write Xamarin-Android-Apps. There is one issue, though. The current version of VirtualBox does not allow me to run Hyper-V, the Android Emulator utilizing HAXM, or any other virtualization technology. Para-virtualization is not easy to implement, I am sure. Other products appear to offer this feature, but one of the beauties of VirtualBox lies in being free.
So, what can we do about this?
As a VirtualBox client shares the network with its host, I asked myself why the Android Debug Bridge should not be able to find an emulator running on… the host.
So, I fired up Android Studio and Android Emulator on the Mac. Here is what I got.
Error message regarding VirtualBox
So while we may see a resolution in the future this does not help us now.
Other Android emulators appear to face the same fate.
Trying to run BlueStacks
So, are we left without options? Far from it… If VirtualBox is the only virtualizer that may run at a time, why not run Android inside VirtualBox? Just get an Android x86 image from the Android x86 project homepage, configure a client and install Android from the iso image. Make sure to configure a bridged network.
Once you have finished setup, you will be able to debug Android apps running inside VirtualBox from within another VirtualBox client.
Almost. A few steps remain to be taken.
First, get the ip adress of the emulated Android device. Open system settings, navigate to About Phone/Tablet and click on Status.
Second, open up the Terminal Eumlator app and enter the following command: adb tcpip 5555
The Terminal Emulator app
Third: On the virtualized Windows client, issue the following command: adb connect <device-ip-address>
Finally, use adb devices to verify that the connection has been established.
Executing adb commands
That is it.
Debugging an Android app inside VirtualBox from within VirtualBox on a Mac
Welcome inside the matrix.