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. Dismiss Notice

Bug How to successfully SDK30 and Gradle 7.x?

Discussion in 'Android' started by zumwalt, Sep 13, 2021.

  1. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Does anyone know how to build to SDK30 and Gradle 7.x since now the Play Store requires SDK30 and it will only compile with Gradle 7.x and above? I can compile just fine to SDK29 with Gradle 4.x that Unity ships with, but when deploying to the Play Store it says I must be SDK30, So far I have spent about 4 days straight trying every which way to Sunday to get this to work, the only success I have had thus far, which is only minor success, is to export the project and upgrade it to SDK30 in Android Studio with Gradle 7, however, a signed APK from a Unity build is the only thing I can do in Android Studio which is clearly missing my components, and doing a package won't upload do to it using deprecated packages that are not allowed it seems.

    So if you have steps you perform to make the latest build of Unity being 2020.3.18f1 as of this post, it would be highly appreciated.
     
  2. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    I've already replied here https://forum.unity.com/threads/gradle-build-fails-with-build-tools-31-0-0.1154834/#post-7494002 but I'll repeat that you don't have to use SDK build-tools 30. Google Play requires that apps target API level 30, which requires platforms API 30 to be installed. If your Unity editor installation uses SDK installed with the editor, there is a sdkmanager tool in editor's installation directory PlaybackEngines\AndroidPlayer\SDK\tools\bin. You can run that tool like this
    Code (CSharp):
    1. sdkmanager "platforms;android-30"
    to install API level 30 (make sure you have administrator privileges, so that sdkmanager can install things). Alternatively you can use Android Studio and install only Platforms component with API level 30.

    Edit: just in case, I have to mention that after installing API level 30 you must also specify it has to be used. In Player Settings you have to set "Target API Level" to "Automatic (highest installed)" or "Android 11.0 (API level 30)" to actually target API 30 and satisfy Play store requirement.
     
    Last edited: Sep 14, 2021
  3. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    I appreciate your help JuliusM, the problem literally is that Gradle 6.1.1 even (which is what is in the list for Unity version I am using, doesn't work for API level 30, or hasn't so far for me. I will test this above thing your are mentioning to see if that fixed me, I pray it does, but so far, no real luck in this, it would be nice if Unity had the API level 30 already available and tested within the Unity builds. I know that has to be a pain though.
    ============================================
    Running as the command prompt-Administrator, tried in several iterations of the engine
    ============================================
    Code (CSharp):
    1. D:\Unity Editors\2020.3.18f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\tools\bin>sdkmanager "platforms;android-30"
    2. Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
    3.         at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
    4.         at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
    5.         at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
    6.         at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
    7.         at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
    8. Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
    9.         at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
    10.         at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
    11.         at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
    Code (CSharp):
    1. D:\Unity Editors\2020.3.16f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\tools\bin>sdkmanager "platforms:android-30"
    2. Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
    3.         at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
    4.         at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
    5.         at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
    6.         at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
    7.         at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
    8. Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
    9.         at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
    10.         at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
    11.         at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
    12.         ... 5 more
    Also on the whole "build tools 31 corrupt thing" there is a fix:
    Code (CSharp):
    1. https://stackoverflow.com/questions/68387270/android-studio-error-installed-build-tools-revision-31-0-0-is-corrupted
     
    Last edited: Sep 14, 2021
  4. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    Maybe I'm mixing a few things up. I've re-read through your posts i this thread https://forum.unity.com/threads/android-build-from-unity-not-64-bit-compliant.1169471/ and now I'm not sure what error is still left for you. Could you specify what exact error you still get in Unity editor now?
    Oh, the error that you get seems to be caused by the fact that sdkmanager only supports JDK 8, but there is a newer JDK version installed on your machine.
    This also raises a question, do you use a custom JDK in Unity, or the one that comes with Unity? Android tools currently used by Unity don't work with newer JDK versions than 8, so maybe that is also somehow related to your other issues.
    There was this post about JDK versions https://forum.unity.com/threads/java-9-jdk-9-support-by-unity-android.499354/ it was pinned for a long time, but now I see it is not pinned anymore, even though it is still relevant for now.
     
  5. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    I am using the built in Unity SDK/JDK, not the external, it is the default on the "edit" the "preferences" then "external tools", all of the Android are checked off to use the internal unity items. Last error I got was that gradle was not compatible with the current build tools, i finally got Unity to upgrade to Android 11 (API Level 30), after I opened the folder where the binary was and set it to run this program as administrator (compatibility tab on file properties)
    "D:\Unity Editors\2020.3.18f1\Editor\Unity.exe"

    This then did the install without arguing with me, I have also set the project to IL2CPP ARM64 bit build (play store only wants 64 bit now, the rest could probably just be removed as options honestly)
    I created a brand new mobile 3d game, and brought in only the 3 main game entry video's, created a plain old gui canvas with 1 line of text and 1 button that triggers the videos to launch, still working on this. If I can get that to work cleanly, then I need to figure out the hosted build solution with Unity and see if that would be best.

    I had also attempted to export the project and build in Android Studio to no avail.
    So, this has been tried many ways, I guess I will eventually find one that works.
     
  6. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Here is the list of what goes wrong when building now since Android 11 installed via Unity installer:
    Code (CSharp):
    1. CommandInvokationFailure: Gradle build failed.
    2. D:\Unity Editors\2020.3.18f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\bin\java.exe -classpath "D:\Unity Editors\2020.3.18f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-6.1.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "bundleRelease"
    3.  
    4. stderr[
    5. Note: D:\Projects\Game\Android\Temp\gradleOut\unityLibrary\src\main\java\com\unity3d\player\UnityPlayerActivity.java uses or overrides a deprecated API.
    6. Note: Recompile with -Xlint:deprecation for details.
    7.  
    8. FAILURE: Build failed with an exception.
    9.  
    10. * What went wrong:
    11. Execution failed for task ':launcher:assetPackReleasePreBundleTask'.
    12. > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
    13.    > Required array size too large
    14.  
     
    crekri likes this.
  7. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    These errors seem similar to this issue https://issuetracker.unity3d.com/is...-or-more-files-in-the-streaming-assets-folder
    Do you have many files in the streaming assets directory? Do those files have extensions?
    In Unity 2020.3.18f1 if certain criteria are met, we should specify only extensions instead of full paths. If you have custom gradle templates you might have to update them based on the default gradle templates present in Unity 2020.3.18f1.
     
  8. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    No custom gradle templates, no streaming assets at all, zero actually. So my array is zero for streaming assets.
    So maybe lacking that folder is the problem? I have never used it.
    All my videos are in a folder I called Videos under my Scenes folder in my assets folder. I use the video player to play them.
     
  9. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    No, lacking streaming assets should definitely not be a problem :) you can try increasing java heap size (though this is a blind guess). The heap size is specified in Editor's preferences -> External Tools tab. The setting is called "Maximum JVM heap size". But I'm really not sure if that will help you.
    How big is your project? Do videos take a lot of space?
     
  10. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    I increased the heap size, didn't help any, my project size is the problem it seems, at lease google play takes up to 1 GB of a game in size, I literally unchecked level after level until the game would successfully compile. The maximum heap size for 64 bit JVM is 8192. But that doesn't get rid of the message for the array. I saw in the asset store someone wrote a plugin to get all the details on assets as to how much space they take up, looks like i need to purchase that, my overall game is 2GB in size, I was trying to figure out how to use a patching system with Unity now, the game is in internal tested on the play store now, first 2 entire regions are in the 1 GB package, but the last 5 regions simply won't fit in the 1GB, hopefully I can do something about that or somehow stream the last 1 GB of assets as a patch, just not sure how yet, Unity build doesn't have a built in build that says to use thing as patch files. The videos take up about less than 200MB, but I might have to downstream them a little, i dropped them to 720dpi, can't go any lower.
     
  11. JonathanFri

    JonathanFri

    Joined:
    Jul 3, 2019
    Posts:
    13
    Exactly this happens if you have the Android !12! SDK installed (via Android Studio for example) and its selected in Unity.
    Make sure that you dont select "Use highest api version" but select 30 as highest in Unity. At least that was the issue in my case
     
  12. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Thanks I will give that a try!
     
  13. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Another issue I get during build time is:
    Code (CSharp):
    1.   java.lang.RuntimeException: Duplicate class com.google.android.play.core.appupdate.AppUpdateInfo found in modules com.google.android.play.core-1.8.3-runtime.jar (:com.google.android.play.core-1.8.3:) and core-1.10.0-runtime.jar (com.google.android.play:core:1.10.0)
    So I would like to remove the 1.10.0, but I am thinking that is bundled in a Unity Engine library set as a collection, because I searched my entire project and no where in my project is the jar of core-1.10.0-runtime.jar, it doesn't exist, this entire part started after I installed the kit by Easy Mobile, I have tried to email them for over a week, they responded 1 time asking for proof I purchased (actually I purchased 2 licenses from them) and I did supply them with proof I purchased it, but zero support, so other than asking for a refund and removing easy mobile pro for current lack of support, I figured if I could just get rid of one or the other it might work, but the plugin puts it back in every time I delete 1.8.3, I guess it needs it for the most recent tools. Anything else I can do other than just never use easy mobile pro?
     
  14. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    Unity specifies "implementation 'com.google.android.play:core:1.10.0'" dependency in unityLibrary/build.gradle file, however it first checks if play:core dependency is not yet specified. You could enable a "Custom Main Gradle Template" in Player settings and then add "implementation 'com.google.android.play:core:1.8.3'" dependency in there. This should add the same version dependency as in the plugin.
     
  15. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,832
    @JuliusM
    May I know what unity versions are affected with this dependency inclusion?
    Any reason for hardcoding this dependency? From quite sometime, play:core got some significant changes and they split review feature from core library and made it's own artifact (ex: com.google.android.play:review:2.0.1).

    When we include play:review dependency, now it says some of the classes already exist in the dependency unity adds (com.google.android.play:core:1.10.0) which is a very old version. Earlier review feature was shipped with play:core v1 and now it has it's own aar file leading to play:core-common file.

    We tried fixing by adding com.google.android.play:core-common dependency along with play:review but it didn't work either.

    Anyways to avoid this issue or stop unity from adding com.google.android.play:core:1.10.0 completely?
     
  16. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,832
    @JuliusM Can you please share your thoughts on the above?
     
  17. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,832
    For the time being, here is a post processor to remove the entry added by Unity (for PAD auto built-in support) if your project uses latest play core libraries.

    Place the attached file in Editor folder.

    But still would request @JuliusM to consider upgrading to 2.x or remove if any of the 2.x libraries are being used to avoid duplicate errors.
     

    Attached Files: