Gradle Build Error using Unity on Offline PC

Hello,

For work, I am trying to make an offline build using Unity and the Android SDK’s/NDKs and Gradle, however, I am running into a Gradle build error that I can’t seem to solve.

The error I get is:

FAILURE: Build failed with an exception.

  • Where:
    Build file ‘D:\WKspaces\ProjectName\Library\Bee\Android\Prj\IL2CPP\Gradle\build.gradle’ line: 6

  • What went wrong:
    Plugin [id: ‘com.android.application’, version: ‘7.1.2’, apply: false] was not found in any of the following sources:

  • Gradle Core Plugins (plugin is not in ‘org.gradle’ namespace)
  • Plugin Repositories (could not resolve plugin artifact ‘com.android.application:com.android.application.gradle.plugin:7.1.2’)
    Searched in the following repositories:
    Gradle Central Plugin Repository
    Google
    MavenRepo
  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

Below are the steps I took to set up my project.

On my private PC at home (connected the the Internet), I set up a Unity project, downloaded everything I needed, and build an apk using Unity. i tested the apk on a device and everything works. I then exported the Unity project to an Android Studio project, and used Android Studio to also build. This also caused no errors. I then disconnected my PC from the Internet and build everything again. No errors.

To get the files on my work pc, I grabbed the entire Unity project (this includes the ndk/sdk/gradle/etc), as well as the Gradle cache (I grabbed the entire .gradle folder just in case) and transferred the files via usb to my work pc. I opened the Unity project and pressed build, but the build fails and shows the error mentioned above. Exporting the Unity project to Android Studio and building through there produces the same error. I tried replacing the entire gradle caches folder on my offline pc, just the files-2.1 folder, and even the entire .gradle folder, but nothing works.

Under no circumstances can I connect my work PC to the Internet.

Does anyone know what I am doing wrong and how I can solve this? I have done an offline build this way before (for a different Unity project) but for some reason it doesn’t want to work anymore. From what I understand, Gradle is trying to download the missing package but can’t because the PC is offline. But the files I transferred should hold all the dependencies, right?
Below are the software versions I’m using:

  • Unity 2022.3.11f1
  • Android studio 2022.2.1 Patch 2
  • JDK (openJDK 11.0.14.1+1)
  • Gradle 7.2
  • Android NDK r23b
  • Android SDK 26.1.1

Thank you!

Try running the Gradle build with --offline parameter.

I unfortunately get the exact same error when I do that.

I did manage to find the POM file for the plugin that I seem to be missing but I’m not sure what to do with it (and if I only need the POM file or something more). If I place it manually in the .gradle cache it still can’ t find it.

Maybe your problem is, that you actually moved the whole .gradle directory.
That could maybe work if the machines are identical regarding paths and so on.
Otherwise, you might have a look at Understanding dependency resolution, maybe that helps.