7

So thats what I have tried:

  • Building different projects (same thing)
  • Reinstalling sdk, jdk, and Unity Editor (newbie gotos)

I have also found very similar problem from today: Android Studio - Could not find intellij-core.jar yet the only gradle.build file that I found was the one generated with Unity in Temp folder that overwrites itself after every build start.

Unity 2018.2.13f1, Windows 10 x64, Fresh Android Studio 3.2.1, jdk1.8.0_192

Here is a console log:
Short

A problem occurred configuring root project 'gradleOut'.
> Could not resolve all files for configuration ':classpath'.
   > Could not find intellij-core.jar (com.android.tools.external.com-intellij:intellij-core:26.0.1).
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/tools/external/com-intellij/intellij-core/26.0.1/intellij-core-26.0.1.jar

Long

CommandInvokationFailure: Gradle build failed. 
C:\Program Files\Java\jdk1.8.0_192\bin\java.exe -classpath "C:\Program Files (x86)\Unity Editors\2018.2.13f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.2.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx2048m" "assembleRelease"

stderr[

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'gradleOut'.
> Could not resolve all files for configuration ':classpath'.
   > Could not find intellij-core.jar (com.android.tools.external.com-intellij:intellij-core:26.0.1).
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/tools/external/com-intellij/intellij-core/26.0.1/intellij-core-26.0.1.jar

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

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

BUILD FAILED in 1s
]
stdout[

]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1 progress, System.String error)
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1 progress)
Rethrow as GradleInvokationException: Gradle build failed
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1 progress)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
Cardstdani
  • 4,999
  • 3
  • 12
  • 31
Jakub Kicmal
  • 73
  • 1
  • 1
  • 5

5 Answers5

9

Here's what worked for me, as reported here:

  1. Go into the Player Settings
  2. Under Publishing Settings tick the box for Custom Gradle Template (Unity then creates a build.gradle template for you)
  3. The template is in Assets > Plugins > Android > mainTemplate.gradle
  4. Open that file in something like Notepad
  5. Change ONLY THIS:

    repositories { jcenter() google() } to repositories { google() jcenter() }

  6. Save the file then try the build again. Not a perfect solution but it should work until Unity/Android fixes the issue. I'm not sure whether this can become undone by upgrading Unity, but I do know that it has to be done per project.

Glen Despaux Jr
  • 1,064
  • 7
  • 19
3

Here's the only solution that worked for me since I'm behind a proxy.

  1. Go to the .gradle folder (default is under C:\Users\<name>\).
  2. Create a file called gradle.properties under this folder.
  3. Add the following:

#http proxy setup
systemProp.http.proxyHost=<your proxy URL>
systemProp.http.proxyPort=<your proxy Port>
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost

#https proxy setup
systemProp.https.proxyHost=<your proxy URL>
systemProp.https.proxyPort=<your proxy Port>
systemProp.https.nonProxyHosts=*.nonproxyrepos.com|localhost
  1. Reopen unity and build !
Koby Douek
  • 16,156
  • 19
  • 74
  • 103
2

If Glen's answer did not work for you, do his steps again (https://stackoverflow.com/a/52958384/6046022) with some edits:

  1. change repositories in Assets > Plugins > Android > mainTemplate.gradle to this:
repositories {
    google()
    jcenter()
    mavenLocal()
    mavenCentral()
    maven { url 'https://maven.google.com' }
    maven { url "https://www.jitpack.io" }
    flatDir {
        dirs 'libs'
    }
}
  1. I guess this was my problem: make sure your internet connection to repositories is ok! in some countries there are restrictions. In that case you need a VPN.

  2. Last step restart Unity

Build took a few minutes but it worked

I also updated gradle: https://answers.unity.com/questions/1490992/change-version-of-gradle-to-46.html
but not sure if it helped.

Saleh Hosseini
  • 482
  • 4
  • 11
0

in my case, the Assets > Plugins > Android > mainTemplate.gradle is already with jcenter() call, so I just check 'Custom Gradle Template' and works!

0

I got it working! Got the same error, using Firebase also, so the mentioned fix here wouldn't help because Firebase keeps overwriting my gradle template. Here is the answer:

https://forum.unity.com/threads/commandinvokationfailure-gradle-build-failed.573040/

Best of luck!