"You cannot use API level 30 and below"
You just need to set the API level to 31+ in
Edit/Project Settings/Player/Other Settings/Identification/Target API Level
Google made breaking changes with how Unity builds the Android projects. The solution is to download a gradle that is v6.1.1+ and below v7 in https://gradle.org/releases/. This YouTube video explains it clearly. I'll list down the things he did to get his project working. Note: His steps didn't work for me; hence, the succeeding solutions may help you.
- Download gradle from link whose version is greater than or equal to 6.1.1 and less than 7.0.0. (why not below 6.1.1, because Unity said so.)(why not 7+, see section below). Extract it to a folder. Copy the folder path. The folder path should contain the
lib folder which Unity will be needing.
Edit/Preferences/External Tools, untick the gradle checkbox and paste the folder path to your gradle you've extracted.
Edit/Project Settings/Player/Publishing Tools, check these 5 items.
android:export="true" in the first Activity tag in
Assets\Plugins\Android\AndroidManifest.xml. (In my case, this didn't work but, for some, it worked for them. Just try doing it first)
Assets\Plugins\Android\baseProjectTemplate.gradle, make sure the version in this line is
Assets\Plugins\Android\gradleTemplate.properties, comment out the
android.enableR8 by placing a
# at the start of the line.
- Attempt to build.
If not working, proceed to next section.
- Make sure you downloaded a gradle between 6.1.1 and the last version before it becomes 7. Here's a reference
- Attempt to build. If not working, proceed to next step.
AAPT: error: attribute android:export not found
android:export=true in the first Activity tag in
- Attempt to build. For me, the Unity project was already able to export the game.
Gradle Build Failed. Android resource linking failed...
- If still not working, see below content which is from here
- Another solution is to go to the Editor folder in your project, create a file called
AndroidManifestPostGenerateGradleProject.cs, and then paste the following script into it:
public void OnPostGenerateGradleAndroidProject(string path)
Debug.Log("Build path : " + path);
string gradlePropertiesFile = path + "/../gradle.properties";
if (File.Exists(gradlePropertiesFile)) File.Delete(gradlePropertiesFile);
StreamWriter writer = File.CreateText(gradlePropertiesFile);
- If there's still a problem, see conversation regarding unicode characters
These are pretty much my research over the past week. Hopefully, this helps some devs.