A friendly face on all platforms

Java looks beautiful on all major platforms. Just take a look…

This is an ordinary JavaFX application:

A plain JavaFX application

Here, we see the same business logic with a native Android ui:

Native Android ui

Now, the business logic baked in a Gluon Mobile app… First, on Android:

Gluon app on Android

And now on iOS:

Gluon app on iOS

Awesome, right?

One more thing… Java business logic, with native iOS ui; built with Multi-OS Engine

Java business logic, native iOS ui

Check out the sources on GitHub.

Or, join me at TopConf Tallinn.


Trouble baseline aligning RadioButtons?

Do you want to achieve something like this…

Screenshot: properly baseline aligned RadioButtons

… but keep getting something like this…

Screenshot: not properly aligned RadioButtons

Then, please check out my answer on Stack Overflow.


Activating the demo user

Android 7.1 will bring us a new UserManager-method called isDemoUser(). According to the docs…

Checks if the calling app is running in a demo user. When running in a demo user, apps can be more helpful to the user, or explain their features in more detail.

But… how to I activate a demo user? If this is common knowledge, please feel free to let me know.

Winking smile

Anyway, I figured out how to activate demo mode in the Android emulator:

  1. Activate the developer options by clicking on the Build number on the About emulated device page seven times
  2. Open the Developer options page
  3. Click on Demo mode

This shows a page with the same title:

Screenshot: Demo mode settings page


When a piece of cake is turning round

Not so long ago a couple of Google apps became piece of cake – sort of, that is.


Funny to see that in Android 7.1 icons will turn round. Sorry, but I could not resist the pun.


BTW, Android Studio 2.2.2 helps creating round icons with an updated Image Asset Wizard:

Image Asset Wizard in Android Studio 2.2.2


See me in Tallinn

I have been quite busy the past weeks, finishing works on the 4th edition of my book Android 7 – Das Praxisbuch für Entwickler. It will be in stores before Christmas. But there is more… In a few weeks I will be heading towards Tallinn, doing a workshop and a talk about Java on mobile devices. I am very excited to join awesome people. Click on the following teaser images to get more information about my presentations.

TopConf Tallinn 2016: Thomas Künneth, Java to go. Mobile apps with Java

TopConf Tallinn 2016: Thomas Künneth, Java on mobile devices


macOS Sierra quick tip: temporarily disable MySQL Server starts

After upgrading to macOS Sierra, my MacBook Pro would no longer shut down properly but get stuck with a black screen. Turns out that the issue might be somehow related to MySQL, as unchecking Automatically Start MySQL Server on Startup fixed the issue for me after the next forced restart.

MySQL Server control panel

I am, by the way, running MySQL 5.7.12

Let me know if you experienced this issue, too.


A note on updates

Android Studio updates usually imply having fun. To me this looks like this…

Project needs updating #1

Project needs updating #2

Currently, I am in the process of updating my book. I already have updated 40 of 80 samples, so this nice thing means I enjoy the fun of doing this stuf 80 more times. 40 times for re-doing, and 40 times for the remaining projects. I am excited to see Android 7.1; will bring us a new API level I am sure, implying I could update the 80 samples once more. Winking smile


On editing fxml files with custom components in Scene Builder

Trying to open a .fxml file of a Gluon Mobile sample application in Scene Builder failed...

...for obvious reasons...

com.gluonhq.charm.glisten.mvc.View is no standard JavaFX control.

To make that class known to Scene Builder we just need to put it on its classpath. Right? The following screenshots describe a workaround when using NetBeans. If there are other, less archaic approaches, I'd love to hear them.

First we need the .jar file.

Now comes the interesting part. How to tell Scene Builder?

There is a config file called SceneBuilder.cfg. On my Windows machine it's situated in C:\Users\tkuen\AppData\Local\SceneBuilder\app.

Just quit Scene Builder and then put the fully qualified path right beside app.classpath=

Here is how Scene Builder will render another .fxml file contain Glisten controls. 

I do not consider myself a Scene Builder expert, so I may be missing a simpler solution. Also, it would be great to have custom components in the palette. Need to check that. Again, any hint is greatly appreciated.

Added Gluon-Port to OpenWeatherMapWeather

Yesterday I introduced you to a new repo of mine, which contains the same app for different platforms. Today I have added a Gluon port. The app as such is rather small. What is important about it is to see similarities as well as differences of the implementations.

Next on the agenda is a UWP app.


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.


Something to look forward to: Eclipse Neon

Neon, the Eclipse Foundation's eleventh annual simultaneous release, will be available June 22, 2016. This is something I am really looking forward to, as the platform finally catches up in high dpi environments. As documented in New and Noteworthy (Platform and Equinox):
SWT now automatically scales images on high-DPI monitors on Windows and Linux, similar to the Mac's Retina support on OS X. In the absence of high-resolution images, SWT will auto-scale the available images to ensure that SWT-based applications like Eclipse are scaled proportionately to the resolution of the monitor.
Something I have been longing for, too:
  • Commands and shortcuts to zoom in text editors
  • Pinch to zoom in text editors
And there is a plethora of further improvements and additions. This simultaneous release includes content from 85 Eclipse projects. Quite a few things to check out.

Ten years ago I started working on Einstieg in Eclipse 3.3. The book was published in 2007. Since then I have been watching Eclipse closely. Well, and four editions of the book followed. I hope to maintain this tradition. We will see. In the meantime, it is great to see and old friend healthy and prospering.


A little less clutter

Pondering on new features for TKMacTuning I came across the user settings of Acrobat Reader. Frankly, I don't like its recent files list. Not because my files are secret, but because I just do not need such a list. My machine collects data that simply is not used. Hence why collecting it in the first place? Let's get rid of it.

On a Mac, user settings usually are stored in the defaults database, which is a set of files residing in ~/Library/Preferences and /Library/Preferences. Those files end in .plist. You can display its contents on the command line by entering defaults read, for example defaults read com.adobe.reader | less. Searching for RecentFiles may reveal, to a little surprise, two or more data structures. The defaults database is heavily hierarchical; what is stored, and how, depends on the app that makes use of it. It turns out Adobe Reader has individual trees for different versions of the software. So I had entries for version 11 and DC.

The user interface of Adobe Acrobat Reader allows you to clear the list of recent files. However, this seems to have impact on the current version only. Because if I do so, the recent files list of the older version remains untouched. But why keep the settings for the old version at all? At the commandline I can issue defaults delete com.adobe.reader 11. This rids me of the old waste. The settings for DC are still intact.

To keep the app from storing the recent files lists does not require the commandline. In the Document settings you can just enter 0 as the number of recent files.


A glimpse at Android Studio 2.0 and the new emulator

Google has finished Android Studio 2.0 and has made it available in the stable channel.

In this post I will show you a few screenshots.

An update of the Gradle plugin is needed

An update of the Gradle plugin is needed

Revamped Deployment Target Dialog

Revamped Deployment Target Dialog

Emulator window with a control sidebar

Emulator window with control sidebar

Enhanced emulator settings

Enhanced emulator settings