Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

JDK 11 support

Discussion in 'Android' started by Voxel-Busters, Mar 31, 2022.

  1. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,834
    Starting API 31, JDK 11 is a requirement due to addition of new annotations used by some of the dependencies.

    If I try to target api 31, it fails with the below error
    Code (CSharp):
    1. java.lang.AssertionError: annotationType(): unrecognized Attribute name MODULE (class com.sun.tools.javac.util.UnsharedNameTable$NameImpl)
    If I unselect unity's recommended openJDK and try to use system's JDK 11, its not picking it up. Unity still fails saying jdk 1.8 is being used.

    When I try to set Jdk 11 path from external tools in unity preferences, its throwing an error saying Unity don't support other than JDK 8/1.8

    @JuliusM @Yury-Habets Do you guys have a list of unity versions which support JDK 11?
     
    Last edited: Apr 1, 2022
    xinatcg likes this.
  2. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
  3. giantkilleroverunity3d

    giantkilleroverunity3d

    Joined:
    Feb 28, 2014
    Posts:
    383
    My question is 'Why is this information located in the 2022.2 when it should be in the other version docos.'
    I didn't look there or here before as I am not in those versions and this answer came far into the failure chain I am experiencing by upgrading to 2020.3.30f1, and all the DKs. The analysis process in finding the fix leads one into myopic searches where one can not even entertain looking outside the box or newer versions(because logically they shouldnt apply) or deciding not to chase squirrels down the rabbit holes.
    I also have 5 projects that I have to repair for APK push that fixing breaks another and the spiral decline never seems to stop add to that any VR headset issues. I have been in the habit of pushing my Andy apks to Oculus to test because that is where the community is going and it is a great debug and UX test.
    I will use the answer here to attempt to make headway into my latest debacle and report back. The internet is rife with apk effort failures and probably because I see a lot of posters not prefacing their build posts all software versions, i.e. Unity, Android, Gradle, DKs, Machine platform, OS's and the like. Having to look at future documentation presents a whole other nightmare when in a production failure/ crunch at testing or distribution time.

    The greatest piece of advice is when starting up a Unity project create an Oracle VM and put everything in there and lock it down when the project works. If you need to upgrade then copy the VM and try the work in there. Source versioning is not the answer to this DK debacle as the platform across the machine type was altered.
     
    Last edited: Apr 5, 2022
    theodhoribeka likes this.
  4. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,834
    Thanks for the response @JuliusM

    Can you please confirm if there is any way to make builds with target api as 31 on versions lower than Unity 2022.2?

    There is actually lot of confusion regarding this. I even made builds earlier on 2019.4+ with target api as 31. But recently I see one main error regarding MODULE annotation attribute which is only available in jdk 11.

    As a plugin publisher, we need a clear info on which versions api 31 works so that we can plan accordingly. If jdk 11 is supported only on 2022, what about older LTS versions for targeting api 31+? Will they be backported by any chance?
     
  5. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    When you compile your plugins, do you use jdk 8 or jdk 11? You might need to specify "-source 1.8 -target 1.8" if calling javac directly, and specify
    Code (CSharp):
    1. compileOptions {
    2.      sourceCompatibility JavaVersion.VERSION_1_8
    3.      targetCompatibility JavaVersion.VERSION_1_8
    4. }
    in the build.gradle file for your plugin.

    By compiling java code for java version 8, I can use API level 31 without any issues in all currently supported Unity versions.
    Currently we don't plan to backport jdk 11 support to older Unity versions, because there are interconnected dependencies between Android Gradle Plugin, SDK and Java versions. We consider such change too big and too dangerous for the LTS release. But as mentioned above, this does not prevent to target API level 31.
     
  6. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,834
    The required compiler options already exist. But until I install JDK 11 the error didn't go through.
    Anyways, thats the case on 2019 unity.

    But yesterday on one of our customer's project, it didn't work out and it was more like a deadlock as its expecting jdk 11 but unity isn't allowed to set other than jdk 8.

    I will monitor the scenario once again and update if I see the same problems.
     
  7. Bac_ByoungHyoun

    Bac_ByoungHyoun

    Joined:
    Sep 18, 2015
    Posts:
    1
    Can't reproduce?
    Try following these steps.

    1. Create a Unity 2020.3.13f1 empty project.
    2. Switch the platform to Android.
    3. Set 'Target API Level' to 31.
    4. If necessary, install platform-31. (Unity Editor automatically executes the command.)
    5. Click 'Build'.
    6. The following error occurs.

    ---
    An exception has occurred in the compiler (1.8.0-adoptopenjdk). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
    java.lang.AssertionError: annotationType(): unrecognized Attribute name MODULE (class com.sun.tools.javac.util.UnsharedNameTable$NameImpl)
    at com.sun.tools.javac.util.Assert.error(Assert.java:133)
    ---

    upload_2022-6-16_17-54-39.png

    I'm surprised by your comment that you don't get any build errors.
     
    xinatcg likes this.
  8. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,834
    @JuliusM We noticed this issue again and it din't resolve after using the 30.0.2 build tools too with Api 31.

    We tried upgrading the android gradle plugin version to 4.0.1 but its triggering other issues on 2019.4.

    we request Java 11 support soon.
     
  9. xinatcg

    xinatcg

    Joined:
    Sep 30, 2020
    Posts:
    19
    google only accept build with target 31 now. so what we should do now?

    Your app currently targets API level 30 and must target at least API level 31 to ensure that it is built on the latest APIs optimised for security and performance. Change your app's target API level to at least 31.​
     
    theodhoribeka likes this.
  10. xinatcg

    xinatcg

    Joined:
    Sep 30, 2020
    Posts:
    19
    Yes , get the same error.
     
    theodhoribeka likes this.
  11. xinatcg

    xinatcg

    Joined:
    Sep 30, 2020
    Posts:
    19
    we need a solution for the previous LTS unity version to support Android target API 31.
     
    Last edited: Aug 9, 2022
  12. xinatcg

    xinatcg

    Joined:
    Sep 30, 2020
    Posts:
    19
  13. xinatcg

    xinatcg

    Joined:
    Sep 30, 2020
    Posts:
    19
  14. IsaacGamePlay

    IsaacGamePlay

    Joined:
    May 16, 2021
    Posts:
    1
    does jdk 11 work on unity 2022.2.0b
     
  15. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,834
    AFAIK, Unity supports JDK 8 only.
    However, 2022.2 seems to come with JDK 11 support.
     
    Last edited: Aug 18, 2022
  16. colorengame

    colorengame

    Joined:
    Dec 9, 2019
    Posts:
    1
  17. giantkilleroverunity3d

    giantkilleroverunity3d

    Joined:
    Feb 28, 2014
    Posts:
    383
    I am trying to create an android apk. I have done this for many years so this is not new to me but the environment has changed. Is this forum thread for posting this and is there hope going this route?
    The build completes and the transfer to the phone completes.
    But when the apk is launched I get a momentary black screen then the app disappears but is still in the execution as the background running screen shows it there.
    I do not want to push to any app store. I do not have ads. I do not capture date. This app is for me and me alone as I am creating an exercise app for the Stealth exercise board which wears a phone. There will be a public version in the future.
    Where do I look next?

    Here is the logcat from within Unity while phone is connected.
    I am targeting android 10 api 29.
     
    Last edited: Sep 27, 2022
  18. rohitvishwakarma1819

    rohitvishwakarma1819

    Joined:
    Feb 15, 2018
    Posts:
    14
  19. jacobfnl

    jacobfnl

    Joined:
    Jan 18, 2018
    Posts:
    4
    Attempting to build an update for a legacy project on the Google Play Store using Unity 2019.4.40f1. I'm in a bind because:
    1. Google Play store requires a minimum target of API level 31 for a previously existing app.
    2. To build for API level >= 31 requires a minimum JDK 11
    3. Unity 2019.4.40f1 won't allow me to use a JDK that isn't 8
    4. Plugins used in the app are dependent on Unity 2019.
    So does that mean the LTS version won't allow us to build for the Play Store?
     
  20. jacobfnl

    jacobfnl

    Joined:
    Jan 18, 2018
    Posts:
    4
    xjjon likes this.