Java8 class file not found when building Cordova plugin?

I’m trying to access a 3rd party Android SDK from my Ionic app.

The 3rd party Android SDK imports “java8.util.concurrent.CompletableFuture”, and I was able to get it to work from Android Studio using a test native app.

However, when accessing the SDK from my Ionic app via a Cordova plugin (which I built referencing instructions at How to write Cordova Plugins. Cordova Plugins are one of the dark… | by Max Lynch | Ionic | Medium), I get a build error:

“error: cannot access CompletableFuture”
“class file for java8.util.concurrent.CompletableFuture not found”

Ideas on how to fix this build error?

1 Like

You will need to wrap that library inside a Cordova plugin. This is the only way to interact with native libraries.

Thanks for the response!

To make sure I understand: I’m already building a Cordova plugin to wrap the 3rd party Android SDK (and this SDK references the java8 class file that is appearing the build error). Are you saying that I should try to include the “java8.util.concurrent.CompletableFuture” class file into the existing plugin somehow?

Maybe something like this https://github.com/cvuser0/cordova-plugin-java7 for Java 8 might help?

Also: When exactly do you get this error? What command do you execute to get this error? What is your ionic info and other environment information for this?

Thanks for the link! I’ll have to see if I can get Java8 to be recognized by Cordova today. If not, I will have to take a different (non-preferred) approach without a Cordova plugin.

I got the Java8 error with the command “ionic cordova build android” after adding my plugin.

My computer has Java 1.8 and I’m using the latest version of ionic etc. Note that the same SDK that uses Java8 works fine from Android Studio.

java -version

openjdk version "1.8.0_112-release"
OpenJDK Runtime Environment (build 1.8.0_112-release-b06)
OpenJDK 64-Bit Server VM (build 25.112-b06, mixed mode)

ionic info

global packages:

    @ionic/cli-utils : 1.3.0
    Cordova CLI      : 7.0.1 
    Ionic CLI        : 3.3.0

local packages:

    @ionic/app-scripts              : 1.3.7
    @ionic/cli-plugin-cordova       : 1.3.0
    @ionic/cli-plugin-ionic-angular : 1.3.0
    Cordova Platforms               : android 6.2.3
    Ionic Framework                 : ionic-angular 3.3.0

System:

    Node       : v6.9.1
    OS         : macOS Sierra
    Xcode      : Xcode 8.3.3 Build version 8E3004b 
    ios-deploy : 1.9.0 
    ios-sim    : 5.0.11

Ok, I think I’m giving up on trying to get Java8 to work with a Cordova plugin for today. Found too many versioning issues, which I will summarize below.

I tried creating “cordova-plugin-java8” based on https://github.com/cvuser0/cordova-plugin-java7, and then adding in my other plugin that references Java8 code (e.g. the “java8.util.concurrent.CompletableFuture” class). I got an application build error Jack is required to support java 8 language features. Either enable Jack or remove sourceCompatibility JavaVersion.VERSION_1_8. When I enabled Jack, I got another application build error com.android.jack.api.v01.CompilationException: Failed to compile. All these issues might be because the Jack toolchain is deprecated as per https://developer.android.com/studio/preview/features/java8-support.html#disable_jack.

I looked at the build.gradle file for my native test app created with Android Studio, and it was clean and works with the Java8 features. The generated build.gradle file for the Cordova/Ionic Android app still references JavaVersion.VERSION_1_6, and trying to change it to JavaVersion.VERSION_1_8 with “cordova-plugin-java8” and other attempts led to the errors previously mentioned.

I had same trouble. I fixed. Thanks for responses. :tv:

@insta724, can you describe more what error(s) you ran into, and how you fixed them? Thanks!