When you build your Android project using GradleAn Android build system that automates several build processes. This automation means that many common build errors are less likely to occur. More info
See in Glossary, you might run into build errors, especially if you’re using additional Android libraries or a custom AndroidManifest.xml. Gradle considers certain issues as errors and stops the build process. These issues include duplicate symbols, references to resources that don’t exist, or a library project that sets the same attribute as the main application.
You can resolve most of these issues by editing an AndroidManifest.xml file, either the main application manifest file, or one in a library your project uses.
The following sections include common Gradle build errors you might experience and how to resolve them.
If you experience any issues not covered in these sections, export your Android project as a Gradle project and build it from the command line. Building from the command line provides detailed error messages and helps you diagnose complex issues more quickly.
The AndroidManifest.xml file, either the main application manifest file or one in a library, references a resource, such as an application icon or label string that doesn’t exist in your project.
The build fails with an error message indicating a non-existent resource referenced in the AndroidManifest.xml file.
This can occur when you copy your main manifest to a library project without removing resource references.
To resolve a missing resource error, follow these steps:
AndroidManifest.xml file and locate the attribute that references the missing resource.
The android:minSdkVersion attribute is declared in an AndroidManifest.xml file instead of in the build.gradle file. This can occur in the main manifest or in the Android library directory manifests. This doesn’t apply to aar plug-insA set of code created outside of Unity that creates functionality in Unity. There are two kinds of plug-ins you can use in Unity: Managed plug-ins (managed .NET assemblies created with tools like Visual Studio) and Native plug-ins (platform-specific native code libraries). More info
See in Glossary.
The build fails with an error indicating that the android:minSdkVersion is declared in a manifest file.
Android builds require you to define the minimum SDK version in the build.gradle file and not in the manifest file. The build fails if the <uses-sdk> element remains in the main manifest or in a library directory manifest.
To fix this issue, follow these steps:
AndroidManifest.xml file.<uses-sdk android:minSdkVersion> element from the manifest.build.gradle file.
Note: If you don’t use a custom Gradle template, Unity automatically handles the minSdkVersion. If you use a custom Gradle template, ensure that you specify the minSdkVersion in the defaultConfig section of the template.
The same file name exists in multiple locations, either in your main application and a library, or across multiple libraries.
A build error indicating duplicate file names.
The build process copies all files into the same APKThe Android Package format output by Unity. An APK is automatically deployed to your device when you select File > Build & Run. More info
See in Glossary package. Therefore, any duplicate file names cause a build failure.
To resolve duplicate file name issue, remove the duplicate file from one of the locations.
A library uses the same Java package name as the main application or another library.
The build fails with an error message indicating a Java package name conflict.
Gradle doesn’t allow you to use the same Java package name in both your main application and a library, or across multiple libraries.
To resolve conflict between package names, follow these steps:
A library attempts to override attributes from the main AndroidManifest.xml file, such as the application icon or label string.
A build error indicating an attribute conflict during the build process.
A library attempts to override attributes from the main AndroidManifest.xml file causing a merge conflict during the build process.
To resolve conflicting attributes, use either of the following approaches:
tools:replace attribute to the application tag to specify how Gradle should resolve the merge conflict.