How to set custom path for .gradle directory for android build in flutter
Update 1 - Easy way for windows
set environment
- Set
GRADLE_USER_HOME
asD:\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
Burhan Khanzada
I am collage student and interested to learn programming languages.
Updated on December 20, 2022Comments
-
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 almost 4 yearsEditing 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 propertygradle.user.home=(path to directory)
. See Gradle documentation -
Burhan Khanzada almost 4 yearscan you please elaborate your comment further because when I use
gradle.user.home=D:\\android\\.gradle
ingradle.properties
it's not working its creating.gradle
directory in the default directory of user home -
neonidian almost 4 yearsDo 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 almost 4 yearsThe GRADLE_USER_HOME can also be got when you enable the debug flag. E.g.,
gradlew <task> --debug
-
Burhan Khanzada almost 4 yearsno, 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 over 3 yearsstackoverflow.com/questions/56350799/… check this post to to know more on this problem