I just cannot seem to export a .aab using apk level 31.

I have been pulling my hair out with this problem. I’ve been trying to upload an android .aab to the google play console and I seem to be getting stuck at every possible solution.

Typically, all that I should be doing is File > Build Settings > Player Settings > Player > Settings for Android > Other Settings:
Set Minimum API Level to 31
Set Scripting backend to IL2CPP
Set Target Architectures to ARM64

and in Publishing Settings:
Set the key store path, password, Project key alias and password.

Go back to Build Settings,
Switch Platform to Android,
Select Build App Bundle (Google Play)

So here is where the issues begin.
I get a popup saying “Required Level API 31” with an option to press “Update Android SDK” Which I do.

User Account Control pops up asking if it wants me to allow PowerShell to make changes to my device, and I click yes. Powershell pops up showing a large string of text, disappears, and then UAC pops up again, I click yes again, powershell pops up etc. and this happens three times.

The popup saying Required Level API 31 shows again.
Now In the unity console, I get these errors:

File C:\Users***.android\repositories.cfg could not be loaded.
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

UnityException: Required API level 31.
Make sure Android SDK path is writable by the Editor.

Error building Player: UnityException: Required API level 31.
Make sure Android SDK path is writable by the Editor.

Build completed with a result of ‘Failed’ in 177 seconds (176669 ms)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

UnityEditor.BuildPlayerWindow+BuildMethodException: 2 errors
at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002da] in :0
at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in :0
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

Okay so that clearly doesn’t work. So instead, I install Android Studio, set the API level to 31, set Unity’s external Android APK to Android Studio and attempt the same process, but all of the same errors pop up.

Instead, I export the .AAB as a Gradle project, open it with Android Studio and try to export the .AAB directly from Android Studio, but then it starts telling me that Either Gradle / the android SDK / JDK is out of date, then I update them. Then it tells me that random code in the .gradle configuration files are out of date or incorrect, I make the suggested changes, and then I continue to get errors.

By this point, my android Studio and (somehow) the built in Unity Android APK are so messed up that I need to uninstall Android Studio and the current Unity version in order to export an APK at all.

I tried doing other things like exporting a .aab from Unity under API level 30 which works, but when I try to upload it to Google Play Console, I get this error:

An error occurred while running bundletool build-apks on your uploaded app bundle. Ensure that your app bundle is valid by running bundletool build-apks locally and try again. Learn more. Error: Invalid uncompressed glob: ‘**[’.[uU][nN][iI]

[yY]3[dD]', '.[rR][eE][sS][sS]', '.[rR][eE][sS][oO][uU][rR][cC][eE]', '.[oO][bB][bB]', '.[bB][uU][nN][dD][lL][eE]', '.[uU][nN][iI][tT][yY][eE][xX][pP]'] + [uU][nN][iI][tT][yY][sS][tT][rR][eE][aA][mM][iI][nN][gG][aA][sS][sS][eE][tT][sS].[tT][oO][kK][eE][nN][iI][zZ][eE](', ')'.

None of this makes any sense to me. I've followed every tutorial I could find to the tee and I just can't seem to get it to work.

Here are some images for reference:



Any help would be greatly appreciated. I am pulling my  hair out at this problem.