[Solved] 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:

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

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

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

  4. 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, but 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 reinstall 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 screenshots for reference[IMG]https://answers.unity.com/storage/temp/206941-whatsapp-image-2023-05-03-at-170503.jpg[/IMG] [IMG]https://answers.unity.com/storage/temp/206942-aaa.jpg[/IMG]

Why are you setting Minimum SDK to 31 ? You do know you’ll skip most of the devices out there? Maybe you wanted to set Target SDK instead?

Nevertheless, those errors are not expected, could you:

  • Attach Editor.log with those errors
  • Try invoking sdkmanager from console yourself (with the command line shown in powershell) and see if it install the required API level.

Hi Tomas, thank you very much for your reply.

You’re right about the target SDK. I have changed it to what you suggested.

I am, however, still getting the errors.
I wasn’t able to attach a .log file so I attached it as a txt

Regarding the invocation, are you referring to Android Studio, from within Unity, or directly in the PowerShell?
if in Powershell, are you referring to this text below?

Arguments are “C:\Program Files\Unity\Hub\Editor\2021.3.24f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\tools\bin\sdkmanager.bat” “C:\Program Files\Unity\Hub\Editor\2021.3.24f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK” “platforms;android-31” “C:\Users\joshm\My Drive\Programming\Unity\Ballistic Blast\Temp\AndroidSDKTool”

If so, I did this in cmd:

C:\Windows\System32>cd C:\Program Files\Unity\Hub\Editor\2021.3.24f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\tools\bin\

And then

C:\Program Files\Unity\Hub\Editor\2021.3.24f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\tools\bin>sdkmanager.bat "platforms;android-31’

and received this response:

ERROR: JAVA_HOME is not set and no ‘java’ command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

So I went into System Environment Variables and added JAVA_HOME with the variable value C:\Program Files\Unity\Hub\Editor\2021.3.24f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK, restarted my pc and tried running the cmd again.

I received this:

Warning: File C:\Users\joshm.android\repositories.cfg could not be loaded.
Warning: Failed to find package platforms;android-31’
[=== ] 10% Computing updates…

And then then it stopped.
It’s probably worth noting that I don’t have a repositories.cfg file in .android\ folder, and i’m not sure why.

So instead, I downloaded the package manually from https://dl.google.com/android/repository/platform-31_r01.zip and extracted it to Unity’s Android SDK folder under the platforms folder, and it seemed to pick up that I had API level 31, thereby bypassing the popup saying “Required Level API 31” with an option to press “Update Android SDK”.

It began building the .aab and after some time (about 6 minutes) seemed to have successfully completed the build. After attempting to upload the .aab to the google play console, I received this error:

Your Android App Bundle is signed with the wrong key. Ensure that your App Bundle is signed with the correct signing key and try again. Your app bundle is expected to be signed with the certificate with fingerprint:
SHA1: 94:F7:93:FA:11:CD:77:03:23:44:77:28:08:FB:7F:1E:6B:F0:F7:smile:1
but the certificate used to sign the app bundle that you uploaded has fingerprint:
SHA1: 06:E3:91:82:smile:4:8E:1A:31:F0:CA:55:FF:5A:B0:65:8D:87:CF:13:46

I assume this is an error regarding setting the key store path, password,
Project key alias and password in the Publishing Settings,
So I went to Project Settings > Player > Android Settings > Keystore Manager > Keystore… > Create New > Dedicated Location, and saved it in a “Key” folder in my Unity Project folder as user.keystore.

I set the Password, Confirm Password, Alias to jmza, Password and Confirm Password, I set the Validity (years) to 50, and Organization as DefaultCompany.

I selected Add Key and it gave me the popup asking “key “jmza” created in “user” keystore. Do you want to set them as your project keystore and project key?” then I selected “yes”.

Then, in Publishing Settings, I set the path to Key/user.keystore, typed in the password I set, set chose the jmza project key, typed in the password, rebuilt the .aab and attempted to upload it again, however, I still received this error:

Your Android App Bundle is signed with the wrong key. Ensure that your App Bundle is signed with the correct signing key and try again. Your app bundle is expected to be signed with the certificate with fingerprint:
SHA1: 94:F7:93:FA:11:CD:77:03:23:44:77:28:08:FB:7F:1E:6B:F0:F7:smile:1
but the certificate used to sign the app bundle that you uploaded has fingerprint:
SHA1: 8C:23:52:36:66:3D:AB:AD:66:19:84:14:65:1C:49:AA:11:89:93:10

So, on the Play Console, I selected ‘Change Signing Key’ and that seemed to solve the problem.

Now, after going to the next page on the Play console, I am met with these 3 errors:

Warning
You must complete the advertising ID declaration before you can release an app that targets Android 13 (API 33). We’ll use this declaration to provide safeguards in Play Console to accommodate changes to advertising ID in Android 13.

Apps targeting Android 13 or above and using advertising ID must include the com.google.android.gms.permission.AD_ID permission in the manifest.

2 MESSAGES FOR VERSION CODE 1

Warning
There is no deobfuscation file associated with this App Bundle. If you use obfuscated code (R8/proguard), uploading a deobfuscation file will make crashes and ANRs easier to analyse and debug. Using R8/proguard can help reduce app size. Learn more

Warning
This App Bundle contains native code, and you’ve not uploaded debug symbols. We recommend that you upload a symbol file to make your crashes and ANRs easier to analyse and debug.

8995063–1238698–Editor.log.txt (112 KB)

It seems sdkmanager fails for you for some reason, but I don’t know why.

You can enable obfuscation in PlayerSettings->Publishing->UseR8/Release/Debug

In Build Settings window, there’s create symbols zip option, which you can use to produce native symbols for your app.

Not sure about advertising id.

Thanks so much, @Tomas1856 . Your assistance has helped a great deal.

Now all that’s left to do is figure out the advertising id thing.

For anyone had the same issues and are wondering how I fixed it,

I downloaded the package manually from https://dl.google.com/android/repository/platform-31_r01.zip and extracted it to Unity’s Android SDK under the platforms folder, and it seemed to pick up that I had API level 31, thereby bypassing the popup saying “Required Level API 31” with an option to press “Update Android SDK”.