---
author: "Jim Bennett"
categories: ["xamarin", "Technology", "xamarin.android", "java", "binding", "aar", "jar", "COMPILETODALVIK", "invalid opcode ba", "invokedynamic"]
date: 2018-09-10T11:22:55Z
description: ""
draft: false
slug: "binding-the-cognitive-services-android-speech-sdk-part-3-java-8-fun"
tags: ["xamarin", "Technology", "xamarin.android", "java", "binding", "aar", "jar", "COMPILETODALVIK", "invalid opcode ba", "invokedynamic"]
title: "Binding the Cognitive Services Android Speech SDK - Part 3 - Java 8 fun"
images:
- /blogs/binding-the-cognitive-services-android-speech-sdk-part-3-java-8-fun/banner.png
featured_image: banner.png
---
In the [first part](/blogs/binding-the-cognitive-services-android-speech-sdk) of this post, I showed how to get started binding the [Microsoft Cognitive Services speech API](https://docs.microsoft.com/azure/cognitive-services/speech-service/?WT.mc_id=speech-blog-jabenn). In the [second part](/blogs/binding-the-cognitive-services-android-speech-sdk-part-2-making-the-code-more-c-like) I showed how to make the code look more C#-like. In this part, I'll show how to use it and fix up a nasty issue with the Android compiler and using jars created with the latest versions of Java.
## Using the SDK
To use the SDK, you will need an Android app. Create a new single-view Android app, and reference the SDK binding project. Then build the app and try to run it.
Then marvel, as your app spectacularly fails to compile with a really weird error message.
```sh
COMPILETODALVIK : Uncaught translation error : com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
```
WooHoo, invalid opcode ba. Ba indeed! What is this gibberish?
Well the issue comes down to Java versions. Android in the past only supported Java code up to version 7. They are now adding support for later versions but Xamarin doesn't have this yet, and this is only available on newer versions of Android (>= 26). To make your code work on earlier versions and with Xamarin you have to do a thing called desugaring (yes, really), and this alters the Java bytecode to convert Java 8 bytecode to a version that is supported by Java 7.
At the moment there isn't a nice IDE way to turn on desugaring, instead it has to be set inside the `.csproj` file of the client application. Open up the `.csproj` file for your newly created Android app inside [VSCode](https://code.visualstudio.com/?WT.mc_id=speech-blog-jabenn) (other editors are available, but hey - why would you), or by editing the file inside Visual Studio, and add the following to the default `PropertyGroup`:
```xml
Had a successful day. Created a #Xamarin binding for the @Azure #CognitiveServices Android speech SDK, and built a sample app that translates me voice into spoken German. pic.twitter.com/Bg4XDvhBjv
— Jim Bennett ☁️ (@jimbobbennett) August 31, 2018