Unable to Export Unity Project to Android - Gradle Errors and Dependency Conflicts

Hello everyone,

I am unable to export my Unity project to Android due to several Gradle errors and dependency conflicts. Below are the details of the issues I’m facing:


Main Errors:

  1. Error 1: compileSdkVersion is not specified
  • During the build process, I get this error:
A problem occurred configuring project ':unityLibrary'.
> com.android.builder.errors.EvalIssueException: compileSdkVersion is not specified. Please add it to build.gradle
  1. Error 2: Incorrect dependency configuration
  • Another error states that Gradle cannot recognize the following dependency:
Could not find method androidx.lifecycle:lifecycle-common-java8:2.4.1() for arguments ...
  • However, I’ve added the dependency in mainTemplate.gradle like this:
implementation 'androidx.lifecycle:lifecycle-common-java8:2.4.1'
  1. Warnings about repositories
  • Gradle warns me about repositories being added in unityLibrary/build.gradle improperly:
Build was configured to prefer settings repositories over project repositories but repository 'maven' was added ...

What I’ve Already Tried:

  1. Setting compileSdkVersion in mainTemplate.gradle:

gradle

android {
    compileSdkVersion 33
    buildToolsVersion "33.0.0"
}
  1. Forcing dependency versions to resolve conflicts:

gradle

allprojects {
    configurations.all {
        resolutionStrategy {
            force 'androidx.lifecycle:lifecycle-common-java8:2.4.1'
            force 'androidx.annotation:annotation:1.3.0'
        }
    }
}
  1. Cleaning the project:
  • Deleted the Library and Temp folders and rebuilt the project in Unity.

My Environment:

  • Unity version: 2023.2.20f1
  • Gradle version: 7.6 (provided by Unity)
  • Android Gradle Plugin: 7.3.1
  • Android SDK: API 33
  • NDK: Default version provided by Unity

What I Need Help With:

I’m stuck and unable to export my project. If anyone has encountered these issues before or has a solution, I’d greatly appreciate any advice or guidance.

Thank you so much for your time and help! :blush:

You’re using unsupported Unity version, so try updating to the latest available LTS version.
After upgrading - recreate all your gradle templates, that should help.

Well, I already upgraded to the latest version, but it didn’t change anything. I updated everything at the same time, so I reverted to my original version.

Did you recreate templates as well?

yes :confused: I’ve really tried everything, and I don’t understand what’s going wrong.

  • I tried updating Gradle.
  • I re-imported all my assets.
  • I checked the compatibility of plugins and the Gradle files.
  • I even tried forcing configurations in the build.gradle.

The only time I can successfully export the project is when I delete the resolved libraries in External Dependencies.
But doing that removes important features from the game.

From the error messages you’ve shared seems that you didn’t do it alltogether: Update Unity to latest 6000.0.x build and recreate all of the templates. Try that once again and share the errors you’ll get.

Another option - share a simple repro project so that we could take a look.