Search Unity

Bug Cant build with Target SDK 31

Discussion in 'Android' started by mvaz_p, Oct 28, 2021.

  1. mvaz_p

    mvaz_p

    Joined:
    Aug 22, 2018
    Posts:
    80
    I'm trying to build with target SDK 31 and this error is happening:


    Code (CSharp):
    1. CommandInvokationFailure: Gradle build failed.
    2. /Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home/bin/java -classpath "/Applications/Unity/Hub/Editor/2020.3.20f1/PlaybackEngines/AndroidPlayer/Tools/gradle/lib/gradle-launcher-6.1.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "bundleRelease"
    3.  
    4. stderr[
    5. Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
    6. An exception has occurred in the compiler (1.8.0_312). 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.
    7. java.lang.AssertionError: annotationType(): unrecognized Attribute name MODULE (class com.sun.tools.javac.util.UnsharedNameTable$NameImpl)
    8.     at com.sun.tools.javac.util.Assert.error(Assert.java:133)
    I've tried manually updating JDK 8 to 11, but Unity (2020.3.20f1) doesn't allow it.
    I'm using a Mac for building.
     
  2. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    836
    We can't reproduce this with simple projects. Maybe there are plugins which cause this issue? Please send us the bug report. https://unity3d.com/unity/qa/bug-reporting Thank you.
     
  3. mvaz_p

    mvaz_p

    Joined:
    Aug 22, 2018
    Posts:
    80
    Thanks for taking the time to analyze this.
    I've managed to to build the app, it seems that the issue was the Gradle version.

    Changed it from:
    classpath 'com.android.tools.build:gradle:3.6.0'

    To:
    classpath 'com.android.tools.build:gradle:4.0.1'


    But I still can't run it properly on the device, now it's crashing and throwing this error:
    Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
     
    PokerDawg likes this.
  4. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    836
    Hmm, looking at the answers here https://stackoverflow.com/questions...ersion-31-and-above-requires-that-one-of-flag this looks like something we might have to fix. If you don't create any intents yourself (or via plugins), then it is definitely an issue in our code. Please submit a bug report.
     
  5. mvaz_p

    mvaz_p

    Joined:
    Aug 22, 2018
    Posts:
    80
    I've managed to take a deeper look into it, it seems that the issue is related to some third party package (probably Firebase).
    The fix is to add this into mainTemplate.gradle dependencies, even if you're not using this package directly:

    dependencies {
    implementation 'androidx.work:work-runtime:2.7.0'
    ...
    }


    Everything seems to be working now.
     
  6. Whitmire

    Whitmire

    Joined:
    Apr 11, 2017
    Posts:
    2
    For those who come across this thread b/c of the error
    Code (CSharp):
    1. java.lang.AssertionError: annotationType(): unrecognized Attribute name MODULE . . .
    cited in the original post, this was more than likely caused by Firebase. I was able to reproduce this with a empty 3D scene in Unity 2020.3.14f1 with just the Crashlytics and Analytics packages imported from the Firebase Unity SDK 8.8.0. (and the tester script mentioned in the Crashlytics Unity docs). I suspect Firebase made their latest Unity SDK work with Unity 2021 and is not backwards compatible with Unity2020. To fix the error, you need to increase the android tools build gradle to
    Code (CSharp):
    1. classpath 'com.android.tools.build:gradle:4.0.1'
    as mentioned by Mvaz_p in your projects build.gradle (use base gradle template to fix this value Unity).
    And
    then compile with gradle 6.1.1 (in your gradle-wrapper.properties file, change the line to read like this)
    Code (CSharp):
    1. distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
    I was able to get it to compile with out adding the work-runtime dependency cited above.
     
  7. Webagent

    Webagent

    Joined:
    Feb 26, 2021
    Posts:
    13
    How can you edit the gradle-wrapper.properties? It tells me that it should be in "Temp\gradleOut\launcher\gradle\wrapper\gradle-wrapper.properties" but the Temp folder does not have a gradleOut folder.
     
  8. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,968
    Have a look at Problem 1 and its solution here.
     
  9. Webagent

    Webagent

    Joined:
    Feb 26, 2021
    Posts:
    13
    I did exactly that. Changed the line to "classpath 'com.android.tools.build:gradle:4.0.1'" then downloaded gradle 6.1 and put it in my home directory. However, this is the error I am getting:


    Code (CSharp):
    1. * What went wrong:
    2. Could not determine the dependencies of task ':launcher:bundleReleaseResources'.
    3. > Failed to install the following SDK components:
    4.       build-tools;29.0.2 Android SDK Build-Tools 29.0.2
    5.   The SDK directory is not writable (C:\Program Files\Unity\Hub\Editor\2020.3.12f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK)
    6.  
    7.  
    Any idea? I tried starting Unity as an Administrator but it did not work.
     
  10. unitydeveloper15-xdevs

    unitydeveloper15-xdevs

    Joined:
    Feb 15, 2022
    Posts:
    5
    Run in cmd under Administrator:

    "C:\Program Files\Unity\Hub\Editor\2020.3.12f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\tools\bin\sdkmanager.bat" "build-tools;29.0.2"
     
    Webagent likes this.
  11. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,968
    Well, there is no specific reason for this issue. But here is a quick solution
    1. Find your system's android sdk folder (usually installable via Android Studio -> SDK Installer)
    2. Copy build-tools/29.0.2 from the system's android sdk folder
    3. Paste it in your unity's android sdk folder/build-tools.

    In-case if you are on windows, you can just extract this and rename its internal folder to 29.0.2 and copy it to your unity's android sdk/build-tools folder.

    Keep us posted in-case if you hit any other blocker!
     
    Webagent likes this.
  12. Webagent

    Webagent

    Joined:
    Feb 26, 2021
    Posts:
    13
    Awesome, I think it worked! Thank you very much