Unsupported class version number [52.0] (maximum 51.0, Java 1.7)

Xamarin Android Unsupported class version issues

When doing Xamarin Android development, you may have come across the error message after enabling MultiDex:

Error Can't read [C:Program Files (x86)Microsoft Visual Studio2017EnterpriseCommon7IDEReferenceAssembliesMicrosoftFrameworkMonoAndroidv7.1mono.android.jar] 
(Can't process class [android/app/ActivityTracker.class] (Unsupported class version number [52.0] (maximum 51.0, Java 1.7)))

 

This is most likely because of an older ProGuard installation.

Download the latest ProGuard from here (v5.3.3 as of this writing).

Determine the current Android SDK location that Xamarin is using by checking Tools->Options->Xamarin->Android Settings.

In my case it is C:UsersMagnusAppDataLocalAndroidandroid-sdk.

So here is how to to so update the Proguard installation;

In the tools sub folder, rename the current proguard to proguard.old.

Extract the contents of the latest ProGuard zip file to a folder named proguard.

That should do it. Just remember that any changes in the SDK installation (using the Android SDK Manager) will put back the older version, so repeat this after an SDK update.

How to use JRE/JDK v8 with Android Studio v2

I was struggling with a rendering exception in Android Studio v2
Failed to load the LayoutLib: com/android/layoutlib/bridge/Bridge : Unsupported major.minor version 52.0

Apparently this can be fixed by telling Android Studio to use JRE v8 (for the IDE, not compiling).
One could edit the plist to tell Android Studio to use a different JRE than the default v6, but that’s not recommended by Google.

So here’s a workaround; create a shortcut/alias that exports a value to use JRE v8.

Save this to a .command file, for example LaunchAndroidStudio.command:
export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk
open /Applications/Android Studio.app/

Change the icon for the alias.
Open the contents of /Applications/Android Studio.app
Navigate to /Contents/Resources and double click the AndroidStudio.icns, it will open in Preview
Copy the icon (Command+C)
Open the LaunchAndroidStudio.command by the “Get Info” command.
Click the default icon in the top left corner and past the icon (Command+V)

How to post to a Microsoft Azure Service Bus using Intel Galileo

In my previous post, I walked you through on how to Install Python Azure SDK on Intel Galileo.

Let’s now put that Python SDK into some work and post something to an Azure Service Bus Queue.

It’s really rather straight forward:

from azure.servicebus import ServiceBusService, Message, Queue
from azure.storage import QueueService
import base64

service_namespace = '<YOURSERVICENAME>'
key_name = 'MyIoTDevices'
key_value = '<YOURKEY>'

queue_name = 'mytestqueue'
message = Message(base64.b64encode('Hello World'))

sbs = ServiceBusService(service_namespace,
shared_access_key_name=key_name,
shared_access_key_value=key_value)

sbs.send_queue_message(queue_name,message)

The only thing is to Base64 encode your string to be compatible with the other Azure SDK’s, in case you want compatibility with WIndows/Android/iOS etc.

But before we run this, you would need to set the on board clock on the Intel Galilelo, otherwise you will get this error:

azure.WindowsAzureError: Unknown error (Unauthorized)
<Error><Code>401</Code><Detail>ExpiredToken: . TrackingId:12341234-1234-1234-1234-123412341234_G18,TimeStamp:10/27/2014 5:06:24 PM</Detail></Error>

So, they easiest way is to synchronise the clock against a time server:

rdate -s wwv.nist.gov

You will need to do this every time after you have shut down the board, since the clock is not battery backed up. So it might be a good idea to put this in a script and have it run at startup.

There you have it.

 

 

Install Python Azure SDK on Intel Galileo

This  post walks you through the steps to install Python Azure SDK on Intel Galileo.

 

Requirements:

  • An Intel Galileo board (Gen 1 or 2)
  • The full Linux boot image
  • Internet connection (either using the built in Ethernet port or using a mini-PCIe WiFi board)
  • CURL with SSL/TLS support

Step 1 Get the big Linux image

You will need to boot in to the full Linux image, which you can download from Intel’s  download page.

Step 2 Boot into Linux

Extract the contents of that compressed file onto a SD card and boot the Galileo from it.

Step 3 Install prerequisites

SSH into your Galileo board as root (no password by default)

>ssh root@192.168.1.136

Make sure the latest CURL and OpenSSL are installed

>opkg update
>opkg install openssl
>opkg install curl

latest_installed

The Linux image I was using at the time of this writing did not have any Root CA certificates installed. Sure, one could bypass certificate validation using Curl’s -k option, but that’s cheating.

First, create the default certificate directories:

>mkdir /etc/ssl
>mkdir /etc/ssl/certs

Download the latest CA certificates

cd /etc/ssl/certs
curl https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt k -o ca-certificates.crt

(Yes yes, I know about -k, but this is a catch 22 moment, we need to get the certs down  from an SSL/TLS connection in the first place)

Step 4 Download and install PIP

Download and install the Python PIP

curl https://bootstrap.pypa.io/get-pip.py | python

install_pip

 Step 5 Install the Python Azure SDK

pip install azure

pip_install_azure

 

 Step 6 Verify

Now we can verify that Python can access the Azure SDK

python
>>>import azure
>>>azure.__version__

 

verify_azure

There you have it. So, what cool things can we do with Microsoft Azure and an Intel Galileo? Let me know in the comments below.

Xamarin Studio java.lang.OutOfMemoryError

Xamarin Studio is a very buggy and flaky product. Having being used it on an every day basis, it’s getting rather frustrating to deal with Xamarins inferior QA.

Here’s one example that keeps on coming up on the “Stable” channel. (I have to bite my tongue really hard not to say what I think about their definition of “Stable”)

This is the dreaded java.lang.OutOfMemoryError:

XamarinStudioOutOfMemory

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Tool exited with code: 3. Output: 
UNEXPECTED TOP-LEVEL ERROR:
java.lang.OutOfMemoryError: Java heap space
	at java.util.BitSet.initWords(BitSet.java:164)
	at java.util.BitSet.<init>(BitSet.java:159)
	at com.android.dx.ssa.SsaMethod.bitSetFromLabelList(SsaMethod.java:137)
	at com.android.dx.ssa.SsaBasicBlock.newFromRop(SsaBasicBlock.java:161)
	at com.android.dx.ssa.SsaMethod.convertRopToSsaBlocks(SsaMethod.java:173)
	at com.android.dx.ssa.SsaMethod.newFromRopMethod(SsaMethod.java:103)
	at com.android.dx.ssa.SsaConverter.convertToSsaMethod(SsaConverter.java:44)
	at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:98)
	at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:72)
	at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:299)
	at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:139)
	at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:94)
	at com.android.dx.command.dexer.Main.processClass(Main.java:682)
	at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
	at com.android.dx.command.dexer.Main.access$600(Main.java:78)
	at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
	at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
	at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
	at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
	at com.android.dx.command.dexer.Main.processOne(Main.java:596)
	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
	at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
	at com.android.dx.command.dexer.Main.run(Main.java:230)
	at com.android.dx.command.dexer.Main.main(Main.java:199)
	at com.android.dx.command.Main.main(Main.java:103)

 

Despite having reported this as a bug, it hasn’t been addressed at all. I am still seeing this on Xamarin Studio for OS X v5.4 (build 420).

Here’s a workaround:

Edit the .csproj file and edit the JavaMaximumHeapSize element and set its value to 1G.

 <PropertyGroup>
   <JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
 </PropertyGroup>

 

Arduino based Blend Micro gives error: Device Descriptor Request Failed in Device Manager

So I started to fiddle around with the Red Bear Lab Blend Micro. All seemed ok, but after I had uploaded a sketch, the device stopped being recognized properly.

The Device Manager in Windows gives me an error message saying Device Descriptor Request Failed:

Device Descriptor Request Failed
Device Descriptor Request Failed

Well, several other blog posts suggests that re-installing the device drivers will help. But that’s really not helping.

The issue seems to be that the device is not responding and communicating properly with the connected USB host for whatever reason when the sketch is running. Let’s see if we manage to revert back to an empty default sketch. The Blend Micro device has a window of 8 seconds from booting until it starts running the loaded sketch. During that time frame, we should be able to upload a default sketch.

First, make sure that the Blend Micro is the selected board in the Arduino IDE:

Blend Micro is selected
Blend Micro is selected

Prepare a sketch with the base minimum code:

void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:

}

Then reboot the Blend Micro device by pressing the reset button.

Reset button on the Blend Micro
Reset button on the Blend Micro

The timing can be critical, so you probably have to try multiple times to get it right. A tip is to click the Upload first, wait a half of a second and then press the reset button.

 

How to hide the status bar in iOS 7 using Xamarin Forms

In order to hide the status bar, one has to add 2 properties in the Info.plist file.

Edit the file and switch to Source view.

Add an entry named UIStatusBarHidden and set the value to true.

Add an entry named UIViewControllerBasedStatusBarAppearance and set the value to false.

The UI editor will translate these into Status bar is initially hidden and View controller-based status bar appearance respectively.

HideStatusBariOS
HideStatusBariOS

How to install VNC server on Raspberry PI

This is a short note on how to install VNC server on Raspberry PI.

Raspberry PI B+
Raspberry PI B+

Step 1

The VNC server is not installed by default in Raspbian, so first install using apt-get:

sudo apt-get install tightvncserver

Step 2

Make a script file to start the VNC server:

nano startVNC.sh

Enter the following:

#!/bin/sh
vncserver :0 -geometry 1920x1080 -depth 24 -dpi 96

Save the file; Ctrl+o , Enter and the Ctrl+x.

Step 3

Make the file executable:

chmod +x startVNC.sh

How to install VNC on Beaglebone Black

Beaglebone Black

A short step through on how to install VNC on Beaglebone Black.

Step 1.

SSH into your Beaglebone.

ssh root@192.168.1.117

(Or whatever your BBB IP address is)

Step 2

Install x11vnc.

Angstrom:

opkg install x11vnc

Debian:

sudo apt-get install x11vnc

 Step 3

Start the VNC server

Angstrom:

x11vnc -bg -o %HOME/.x11vnc.log.%VNCDISPLAY -auth /var/run/gdm/auth-for-gdm*/database -display :0 -forever

Debian:

x11vnc -bg -o %HOME/.x11vnc.log.%VNCDISPLAY -auth /var/run/lightdm/root/:0 -forever

 Step 4

Create a script file to make life easier to start the VNC server.

nano startVNC.sh

Add this to the file:

#!/bin/bash
x11vnc -bg -o %HOME/.x11vnc.log.%VNCDISPLAY -auth /var/run/lightdm/root/:0 -forever

Save the file using commands Ctrl+o press Enter and the Ctrl+x.

Make the script executable:

chmod a+x startVNC.sh

Execute the script:

./startVNC.sh