Version: 2021.1
Troubleshooting Android development
Reporting crash bugs under Android

Gradle troubleshooting

If you just switched to export your Android project using Gradle instead of the old system, you may encounter build errors, especially if you are using additional Android libraries, or if you have added a custom AndroidManifest.xml.

The Android Gradle plug-in is much more picky than the old ADT/Ant system. It does not accept anything it considers an error, whether it’s duplicate symbols, references to resources that don’t exist, or a library project that sets the same attribute as the main application.

In most cases, fixing the problem involves editing an AndroidManifest.xml file; either the main one, or one from a library your project uses.

In a non-trivial project, or if the project has issues not described by the troubleshooting section below, export the project as a Gradle project (from Build Settings) and build from the command line. Building from the command line gives you more detailed error messages, and makes for a quicker turnaround when applying changes.

Specific problems

Resource not found

An AndroidManifest.xml file, either the main one or in a library, references a non-existing resource. Often it is the application icon or label string that is set by a library. This can happen if you have copied your main manifest to a library project without removing those references.

Remove the attribute from one of the Android Manifests – normally the one from the library.

MinSDK in Manifest

The android:minSdkVersion attribute is specified in the AndroidManifest.xml file. It can be in the main manifest file, or in a file in one of the directories which Unity treats as Android libraries. .aar plugins shouldn’t cause this issue.

The solution is to remove the uses-sdk android:minSdkVersion element from the main manifest and / or manifests in library directories. Instead, you should specify the minimum SDK version in the build.gradle file instead. If you don’t have a custom Gradle template, Unity automatically handles this. If you do have a custom Gradle template, make sure the minSDK is specified in the defaultConfig section of the template.

Duplicate files in APK

You have a file name collision between your main application and a library project, or between two library projects. Keep in mind that all of the files are copied into the same APK package.

You need to remove one of the files.

Colliding package names

A library can not use the same Java package as the main application, or any other library.

Usually, you should change the package name of the library to something different. If the library contains a lot of code, it may be easier to change the main package name (from the Player settings).

Colliding attributes

A library can not freely override attributes from the main AndroidManifest.xml file. Often this error is caused by a library setting the application icon or label string, similar to the Resource not found problem above.

Either remove the attribute from the library, or add a tools:replace attribute to your application tag, to indicate how the merge conflict should be resolved.

Troubleshooting Android development
Reporting crash bugs under Android