Troubleshooting Gradle build issues for Android
Solve common Gradle issues when developing for Android using Unity.
Read time 4 minutesLast updated 21 days ago
When you build your Android project using Gradle, you might run into build errors, especially if you're using additional Android libraries or a custom . 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.
AndroidManifest.xmlYou can resolve most of these issues by editing an file, either the main application manifest file, or one in a library your project uses.
AndroidManifest.xmlThe following sections include common Gradle build errors you might experience and how to resolve them.
- Missing resource referenced in manifest
- Minimum SDK version declared in manifest
- Duplicate file names in APK
- Multiple libraries using the same package name
- Conflicting manifest attributes
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.
Missing resource referenced in manifest
The 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.
AndroidManifest.xmlSymptom
The build fails with an error message indicating a non-existent resource referenced in the file.
AndroidManifest.xmlCause
This can occur when you copy your main manifest to a library project without removing resource references.
Resolution
To resolve a missing resource error, follow these steps:
- Open the file and locate the attribute that references the missing resource.
AndroidManifest.xml - Remove the attribute from one of the Android manifest files, typically the one from the library.
Minimum SDK version declared in manifest
The attribute is declared in an file instead of in the file. This can occur in the main manifest or in the Android library directory manifests. This doesn't apply to plug-ins.
android:minSdkVersionAndroidManifest.xmlbuild.gradleaarSymptom
The build fails with an error indicating that the is declared in a manifest file.
android:minSdkVersionCause
Android builds require you to define the minimum SDK version in the file and not in the manifest file. The build fails if the element remains in the main manifest or in a library directory manifest.
build.gradle<uses-sdk>Resolution
To fix this issue, follow these steps:
- Open the main manifest file.
AndroidManifest.xml - Remove the element from the manifest.
<uses-sdk android:minSdkVersion> - Check the manifests in library directories for the element and remove it if present.
- Specify the minimum SDK version in the file.
build.gradle
Duplicate file names in APK
The same file name exists in multiple locations, either in your main application and a library, or across multiple libraries.
Symptom
A build error indicating duplicate file names.
Cause
The build process copies all files into the same APK package. Therefore, any duplicate file names cause a build failure.
Resolution
To resolve duplicate file name issue, remove the duplicate file from one of the locations.
Multiple libraries using the same package name
A library uses the same Java package name as the main application or another library.
Symptom
The build fails with an error message indicating a Java package name conflict.
Cause
Gradle doesn't allow you to use the same Java package name in both your main application and a library, or across multiple libraries.
Resolution
To resolve conflict between package names, follow these steps:
- Identify the library with the conflicting package name from the build error.
- Rename the library's package to something unique. If the library contains significant code, rename the package through > Android > Package Name.Player Settings
?
Conflicting manifest attributes
A library attempts to override attributes from the main file, such as the application icon or label string.
AndroidManifest.xmlSymptom
A build error indicating an attribute conflict during the build process.
Cause
A library attempts to override attributes from the main file causing a merge conflict during the build process.
AndroidManifest.xmlResolution
To resolve conflicting attributes, use either of the following approaches:
- Remove the conflicting attribute from the library's Android manifest file.
- Add a attribute to the application tag to specify how Gradle should resolve the merge conflict.
tools:replace