Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Java 8 aar library requires minimum sdk version 26

Discussion in 'Android' started by abhipray, Nov 11, 2017.

  1. abhipray

    abhipray

    Joined:
    Jan 30, 2017
    Posts:
    2
    I am trying to add an android library with Java 8 features to Unity. I get the following error while trying to build:

    CommandInvokationFailure: Unable to convert classes into dex format.
    /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java -Xmx2048M -Dcom.android.sdkmanager.toolsdir="/Users/abhipray/Library/Android/sdk/tools" -Dfile.encoding=UTF8 -jar "/Applications/Unity/PlaybackEngines/AndroidPlayer/Tools/sdktools.jar" -

    stderr[
    Uncaught translation error: com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
    1 error; aborting
    ]

    I don't see an option for min-sdk-version as 26 via player settings using unity 2017.3.0b8.

    How do I set the min-sdk-version to 26 or is there another solution to this error?
     
  2. abhipray

    abhipray

    Joined:
    Jan 30, 2017
    Posts:
    2
    Found a solution. I fixed this by using the Gradle build option and adding a .gradle file to Plugins/Android/mainTemplate.gradle. The gradle file needs the following:
    compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
    }

    Unity comes bundled with gradle-wrapper 4.0.1 but because 1.8 language features require gradle, I replaced 4.0.1 found in Applications/Unity/PlaybackEngines/AndroidPlayer/Tools/gradle with 4.1.
     
unityunity