How to set custom path for .gradle directory for android build in flutter

2,509

Update 1 - Easy way for windows

set environment

  • Set GRADLE_USER_HOME as D:\gradle\.gradle

Solution for this is to add this line set GRADLE_USER_HOME=(D:\android\.gradle or your custom path) // remove that brackets in android\gradlew.bat file at the first line and that's it now you can use your old gradle download files

Share:
2,509
Burhan Khanzada
Author by

Burhan Khanzada

I am collage student and interested to learn programming languages.

Updated on December 20, 2022

Comments

  • Burhan Khanzada
    Burhan Khanzada over 1 year

    I want to use custom path for .gradle folder instead of $USER_HOME/.gradle because i am already developing android apps and changed this path to custom path from which it does not affect if whenever i install new windows so i can save me from downloading all that files and different version of gradle wrapper again and again so when now i start learning flutter i realize that its always creating that folder in my $USER_HOME/.gradle directory and there is no option in flutter to change this behavior and i also tried to open the android folder of flutter project from android studio and try to change the path from there but this doesn't help either

  • neonidian
    neonidian almost 4 years
    Editing gradlew.bat file is not a good practice since it is a wrapper file and when you upgrade your Gradle wrapper this change would not be retained. Instead, create a gradle.properties file in the project's root directory and set a system property gradle.user.home=(path to directory). See Gradle documentation
  • Burhan Khanzada
    Burhan Khanzada almost 4 years
    can you please elaborate your comment further because when I use gradle.user.home=D:\\android\\.gradle in gradle.properties it's not working its creating .gradle directory in the default directory of user home
  • neonidian
    neonidian almost 4 years
    Do you have any other gradle.properties file defined on the command line or in the .gradle directory in user's home directory. If so, gradle.user.home property set in those property files will override the value in gradle.properties in project directory. See how gradle properties file picks up the values from Gradle documentation.
  • neonidian
    neonidian almost 4 years
    The GRADLE_USER_HOME can also be got when you enable the debug flag. E.g., gradlew <task> --debug
  • Burhan Khanzada
    Burhan Khanzada almost 4 years
    no, I haven't defined any file even I have deleted the default .gradle folder from my home directory or probably I am not setting the path format correctly but I have searched this should be a valid format in windows
  • Burhan Khanzada
    Burhan Khanzada over 3 years
    stackoverflow.com/questions/56350799/… check this post to to know more on this problem