Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Gradle Error: Problem with Gradle build

Discussion in 'Editor & General Support' started by marcos4503, Jun 29, 2018.

  1. marcos4503

    marcos4503

    Joined:
    Nov 1, 2015
    Posts:
    76
    Hi guys how are you?

    I'm having a build problem at Unity with gradle, I've been trying to solve this problem for some time, but I have not been able to do anything at the moment. I would appreciate some help, really!

    Problem occurs when I try to build my apk with gradle, that's the problem




    And this is the log

    Code (CSharp):
    1. CommandInvokationFailure: Gradle build failed.
    2. C:\Program Files\Java\jdk1.8.0_162\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2018.2.0b10\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.2.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx2048m" "assembleRelease"
    3.  
    4. stderr[
    5.  
    6. FAILURE: Build failed with an exception.
    7.  
    8. * What went wrong:
    9. A problem occurred configuring root project 'gradleOut'.
    10. > Could not resolve all files for configuration ':classpath'.
    11.    > Could not find gradle.jar (com.android.tools.build:gradle:3.0.1).
    12.      Searched in the following locations:
    13.          https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.jar
    14.    > Could not find layoutlib-api.jar (com.android.tools.layoutlib:layoutlib-api:26.0.1).
    15.      Searched in the following locations:
    16.          https://jcenter.bintray.com/com/android/tools/layoutlib/layoutlib-api/26.0.1/layoutlib-api-26.0.1.jar
    17.    > Could not find apksig.jar (com.android.tools.build:apksig:3.0.1).
    18.      Searched in the following locations:
    19.          https://jcenter.bintray.com/com/android/tools/build/apksig/3.0.1/apksig-3.0.1.jar
    20.  
    21. * Try:
    22. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    23.  
    24. * Get more help at https://help.gradle.org
    25.  
    26. BUILD FAILED in 54s
    27. ]
    28. stdout[
    29. Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
    30. ]
    31. exit code: 1
    32. UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    33. UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    34. UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1 progress, System.String error)
    35. UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1 progress)
    36. Rethrow as GradleInvokationException: Gradle build failed
    37. UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1 progress)
    38. UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
    39. UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
    40. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    41.  
    Already tried

    - Update the JDK
    - Downgrade JDK
    - Use another version of Unity
    - Reinstall the JDK and SDK
    - Only let the SDK 26/27 or 28 installed
    - Update Android Studio
    - Reinstall Unity
    - Install all SDK tools using the Android Studio SDK Manager

    None of these things helped me...

    I'm using
    - Unity 2018.2.0b10
    - Android Studio 3.1.3
    - JDK 1.8.0_172
    - Android SDK 27
    - A completely clean project on Unity
     
    Last edited: Jun 29, 2018
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    What Unity version are you using?
    Also, are you using a custom gradle template file (for your main app or for any other libraries you include) ? please share those files as well.
     
  3. marcos4503

    marcos4503

    Joined:
    Nov 1, 2015
    Posts:
    76
    Hi!

    The Unity version is 2018.2.0b10, and I'm not using any custom gradle files. The project also does not have any type of plugin..
     
  4. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Can you try creating a new empty project and build that for Android. See if you get the same results ?
     
  5. marcos4503

    marcos4503

    Joined:
    Nov 1, 2015
    Posts:
    76
    I created a new project and Unity made the same mistake!
     
  6. RMGK

    RMGK

    Joined:
    Sep 30, 2011
    Posts:
    75
    if you are using a custom Gradle file, make sure that it includes:

    repositories {
    jcenter()
    google()
    }
     
    WikiZhao likes this.
  7. MechEthan

    MechEthan

    Joined:
    Mar 23, 2016
    Posts:
    166
    Did you ever solve your problem?
     
  8. hbs_manoj

    hbs_manoj

    Joined:
    Feb 11, 2021
    Posts:
    3
    did you solve it?
     
  9. marcos4503

    marcos4503

    Joined:
    Nov 1, 2015
    Posts:
    76
    Unfortunately I was unable to solve the problem, so I just configured my Unity (at the time) to use the Internal compiler instead of Gradle ...

    After having this problem I spent some time without using Unity, but when I returned, the problem just didn't happen anymore. I heard that this has to do with the versioning of Gradle, but as the problem no longer occurred, I was unable to identify it :/
     
  10. hbs_manoj

    hbs_manoj

    Joined:
    Feb 11, 2021
    Posts:
    3
    thanks worked for me after downgrading to unity 2018 and using internal compiler .
     
  11. samrichardsch

    samrichardsch

    Joined:
    May 7, 2020
    Posts:
    1
    I clicked Development Build on, in the build settings and it solved. I didnt get any such errors.
     
    prasanthk46 likes this.
  12. nalturk565

    nalturk565

    Joined:
    Jan 7, 2014
    Posts:
    2
    In my case it was caused by a non-ASCII character in project path... Fixed the path and prblem was gone
     
    LuigiDreemurr likes this.
  13. bashaa17721

    bashaa17721

    Joined:
    May 22, 2021
    Posts:
    1
    i use Unity 2020.3.9
    The problem is still there and I can't solve it yet
    If any of you have the problem, please help me
     
  14. OribeWareGames

    OribeWareGames

    Joined:
    Jan 25, 2015
    Posts:
    24
    I'm having the same problem on Unity 2020.3.15f2... been a pain to install a lot of things to compile in aab and this is almost the last step, and can't find a way to work it out :(
     
  15. tonnynevel

    tonnynevel

    Joined:
    Oct 19, 2018
    Posts:
    5
    same problem 2019.4.29f stucked on 2 days...

    FIX: move project folder from downloads, because in my user name was non latin letters
     
    Lks426 likes this.
  16. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    470
    OK, how are you?

    I know it isn't much of a solution, but a reboot fixed this for me. I did not see a gradle process in Mac OS Activity Monitor, but likely something like that could be killed instead of rebooting, until there is a Unity Editor fix.
     
  17. Athomield3D

    Athomield3D

    Joined:
    Aug 29, 2012
    Posts:
    193
    A reboot indeed got it back to work correctly. Cheers
     
    fareedtahir likes this.
  18. sebastiansegura92

    sebastiansegura92

    Joined:
    Sep 13, 2020
    Posts:
    1
    could you fix it?
     
  19. Faucheur_de_chattons

    Faucheur_de_chattons

    Joined:
    Sep 4, 2017
    Posts:
    3
    What worked for me was to update Unity to the latest LTS version. I also noticed when I built first that Avast blocked some file execution which caused the build to fail. I manually added an exception. You might want to check that your anti virus didn't block any executable.
    Also I noticed that gradle failed to build when not connected to network as it needs to pull some data sometimes.
    Hope it helps
     
  20. abd56aljakani

    abd56aljakani

    Joined:
    Apr 14, 2019
    Posts:
    2
    For me the solution was enabling USE R8 in my unity 2020.3 inside publishing settings Minify
     
    michealcaj likes this.
  21. fareedtahir

    fareedtahir

    Joined:
    Nov 2, 2020
    Posts:
    4
    yes it works for me. Thanks alot.
     
  22. hammadkhan642

    hammadkhan642

    Joined:
    Sep 3, 2019
    Posts:
    3
    Same Issue please help me....
     
  23. shacharoz

    shacharoz

    Joined:
    Jul 11, 2013
    Posts:
    98
    reboot of the pc?
     
    PropertyRealtors and Aca like this.
  24. ELNexs

    ELNexs

    Joined:
    Dec 20, 2020
    Posts:
    1
    I just fund this fix and worked for me

    For Windows
    1. go to the location

      "C:\Program Files\Unity\Hub\Editor\2021.1.24f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\build-tools\31.0.0"

    2. find a file named d8.bat. This is a Windows batch file.

    3. rename d8.bat to dx.bat.

    4. in the folder lib ("C:\ProgramFiles\Unity\Hub\Editor\2021.1.24f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\build-tools\31.0.0\lib")

    5. rename d8.jar to dx.jar
    Remember AppData is a hidden folder. Turn on hidden items to see the AppData folder.


    Now run your project...
     
    Akz0, Agio24, Karma976 and 6 others like this.
  25. hammadkhan642

    hammadkhan642

    Joined:
    Sep 3, 2019
    Posts:
    3
    Install Unity from unity hub with his recommended Sdk,Ndk,Jdk and Gradle he will start working.
     
  26. carpe_die_m

    carpe_die_m

    Joined:
    Dec 21, 2018
    Posts:
    2
    I have Unity 2020.3.20f1 and had problems with SDK, NDK, JDK and finally with the Gradle Build.
    Thanks to this post I finally got it to work and build to my phone.
     
    lanceroy likes this.
  27. ogreanrazvan

    ogreanrazvan

    Joined:
    Jan 12, 2021
    Posts:
    1

    THIS WORKS GUYS!! THANK YOU MAN!
     
  28. Pgames3D

    Pgames3D

    Joined:
    Dec 3, 2016
    Posts:
    2
    Everytime when new version of SDK arrives we need to do same process, first time I fixed with same method then after updating sdk to 32 same error faced. doing same method issue resolved
     
  29. Neyxium

    Neyxium

    Joined:
    Jan 8, 2022
    Posts:
    1
    I have same problem now.
    I did what this guy said but I already have dx.bat and dx.jar file. (I have both d8 and dx).
    Can anyone help?
     
  30. nx-sm

    nx-sm

    Joined:
    Jul 4, 2015
    Posts:
    10
    I had the same problem and enabling the Release flag under Project Settings > Player > Publishing Settings > Minify on Unity 2020.3.23f1 worked for me.
     
  31. Kheremos

    Kheremos

    Joined:
    Dec 13, 2017
    Posts:
    17
    I was hit with this, maybe because my computer crashed with Unity (2020.3.16f1) open (not building). I clicked "Development Build" and that worked, but only to finish the build. It creates a large unsigned APK, so doesn't work for all purposes. I then disabled the flag and went to build again, still fails. So then I upgraded to 2020.3.27f1 and that... didn't work either.

    [Update 1]: I rebooted the system and the build still failed with the same message.
    [Update 2]: Then I checked "Use R8" in Player -> Publishing Settings under Minify.
    [Update 3]: Actually, one of the above did work, but after reboot the Project Key Alias had the wrong app selected, so it was still failing for a more obvious reason. Also, my builds are WAY faster (because of reboot, I guess?).
     
    Last edited: Mar 9, 2022
  32. NoamKU

    NoamKU

    Joined:
    Dec 13, 2020
    Posts:
    1
    I had the same error and I just checked and unchecked "development build", in the Build Settings and it worked for me
     
  33. Lks426

    Lks426

    Joined:
    Feb 19, 2021
    Posts:
    1
    It's work for me. I have been struggling for 2 days. Thank you so muchh..
     
  34. ElegantUniverse

    ElegantUniverse

    Joined:
    Sep 13, 2018
    Posts:
    78
    Solved!
    my SDK folder wasn't on the recommended path(Preferences/external tool/SDK) I moved the SDK to the recommended path and it was solved.
    I have to add this tip after I used android studio the mentioned error was displayed.
    if you guys encountered the mentioned error, try to change the SDK path.
     
  35. Orr10c

    Orr10c

    Joined:
    Sep 11, 2016
    Posts:
    45
    For me the problem was unallowed characters on the path, maybe this helps
     
  36. adrianfrancisco

    adrianfrancisco

    Joined:
    Jul 29, 2021
    Posts:
    14
    Nothing of the above worked for me, except upgrading from unity 2020 to 2021 (And fixing the corresponding errors of compatibility). It drove me crazy and made me very miserable for one day because I tried everything mentioned, and even after upgrading I had to face other errors (I had to delete like a temporary folder that was creating problems, and suddenly the physics felt much clunkier I don't know why), which I could solve so far. Anyways with the new 2021 LTS so far no problems exporting to .apk and .aab
     
  37. Hashim-J

    Hashim-J

    Joined:
    Aug 10, 2021
    Posts:
    3
    Solved... Consulted countless videos, unity forums after a lot of suffering I got my build ready to play. Thank GOD it worked, hopefully it will work for you guys to...)).

    Open your project in unity then go to Edit/Project Settings.../Player and then find identification (like in the image)
    Now finally tick that box (Override Default Package Name), go back hit Build and Booooom... Ready to play your APK.

    Well if this does not work for you so don't blame me because I don't even know how this works. Originally I was totally fed up, couldn't find any solution and started doing random changes in project then somehow got the success...)))
    If someone knows what this option does let me knew. Thanks.

    Unity version 2021.3.0f1
     
  38. cecepssblog

    cecepssblog

    Joined:
    May 25, 2022
    Posts:
    1
    WOW! Finally im solved my problem with this step tho. Try this guys if u still failed to compile ur project.

    Thx mate!
     
    Hashim-J likes this.
  39. MrvKrt7

    MrvKrt7

    Joined:
    Jun 9, 2022
    Posts:
    2
    I use 2022.1.20f1 and still get this error? Any other solution?
     
  40. iozluturk

    iozluturk

    Joined:
    Feb 16, 2021
    Posts:
    1
    guys just change the file path, probably there is a problem with the file name of the project,this is how my problem was fixed
     
  41. TheSticky

    TheSticky

    Joined:
    Jan 28, 2021
    Posts:
    1
    I resolve this problem by downloading a new SDK using android studio, and using that SDK in my project later i deleted the debug.keystore and debug.keystore.lock that is generated
     
    Last edited: Nov 9, 2022
  42. Knub

    Knub

    Joined:
    Feb 8, 2017
    Posts:
    2
    My fix was: Under Edit->Preferences->External Tools, I had the box unchecked for Android SDK Tools Installed with Unity (recommended). Once I checked it and built, it started working again.
     
  43. imrankarimi009

    imrankarimi009

    Joined:
    Dec 10, 2020
    Posts:
    3
    how to fix gradle build failed with unity version 2022
     
  44. yolo222

    yolo222

    Joined:
    Dec 28, 2022
    Posts:
    1
    i have the same problem !
     
  45. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    759
    I using Unity 2023.1.0b3 But still having this issue, at first I using 2022.2.5f1 But it also can't build to iOS so I upgrade to this version 2023.1.0b3 it can build to iOS without any issue But for the Android, it still having issue.
     
  46. Omid7L

    Omid7L

    Joined:
    Jun 10, 2018
    Posts:
    14
    After updating the firebase plugin from version 8.6.1 to 10.5.0, I faced a Gradle failed error in unity 2020.3.43f1.
    I deleted all files of \Assets\Plugins\Android folder then run the menu item "Assets->External Dependency Manager -> Andriod Resolver -> Resolve" which works for me.
     
  47. CharlesMcFigus

    CharlesMcFigus

    Joined:
    Mar 15, 2023
    Posts:
    2
    With a fresh install of Unity 2021.3.19f1 (on Windows) I was running into a gradle build error. The issue I had was that the default keystore format was invalid because I already had Android Studio installed prior. I basically had to recreate a keystore in a custom location (as to not override my Android Studio one).

    Quote from SO post: "You need to click on Player setting: Under Player, click on Publishing Settings, then click on Keystore Manager."



    Source: https://stackoverflow.com/questions...o-read-key-from-keystore-invalid-keystore-for
     
    blackdeng likes this.
  48. The_programer212

    The_programer212

    Joined:
    Feb 27, 2023
    Posts:
    3
    i try all of these but could not solve why im using unity 2020.3.23
     
  49. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    This is a very old thread - could you please post your full error message ?
     
  50. The_programer212

    The_programer212

    Joined:
    Feb 27, 2023
    Posts:
    3