Reputation: 1888
While checking out my own projects or others projects from github, android studio first tries to download gradle version mentioned in that project. However downloading so many versions of gradle takes up space, time and I dont want so many versions of them. But I can not find a way to change the gradle version and sync project with newer gradle version. I tried editing the build.gradle file with classpath of newer gradle but that did not work. What can I do to sync projects without downloading an older version of gradle? I understand the possibility of not working or syncing project properly with another gradle version but is this possible?
Below image shows, classpath changed and tried to resync but still downloaded older gradle version mentioned in the file while syncing, so kept as is.
Upvotes: 1
Views: 740
Reputation: 862
While using Android Studio Arctic Fox 2020.3.1 Patch 1
I have faced this problem while trying to use the Codelabs from github. I waited for 45 minutes once and still it didn't finish rebuilding the project. It was impossible to work that way.
What I did to use the project was create an empty project and copy:
layout/*.xml
navigation/*.xml
menu/*.xml
'package'/*.kt
And the .kt Kotlin or java files to the corresponding locations in the fresh project.
Now change the package information in all the .kt files to point to your package.
Add dependencies in the project level and module level build gradle files
Remove unused import from the .kt files
Set viewBinding, dataBinding in the module level build gradle if needed
Finally check the manifest in the downloaded project file to see any changes need to be done.
Now you will be able to successfully build the project and run it. Correct errors if you encounter them.
This is a better way to learn by doing than just copying the project and waiting endlessly.
I did all the 'codelabs' from https://developer.android.com/courses/kotlin-android-fundamentals/toc
using this method. I could never open a project downloaded from the github directly.
Upvotes: 0
Reputation: 1089
What you tried to change is the Android Gradle plugin not Gradle executable itself. To change Gradle's version you need to open file gradle/wrapper/gradle-wrapper.properties
and then change to the version you expect there. Be aware that there's a relation between the Android Gradle plugin and Gradle versions so they might not play nice together, that's why Google did this: https://developer.android.com/studio/releases/gradle-plugin#versioning-update
Upvotes: 0
Reputation: 130
If you want to run that project you need to download that particular gradle build. If you try otherwise it will be waste of your time. Trust me I've tried.
Upvotes: 0
Reputation: 41
You could possibly turn off your internet on your PC before opening this project. There would be a prompt asking you to run the project offline, if you click Yes, it might throw an error saying dependencies not found and that could be the time when you could change the target versions.
But nevertheless, the size of the old gradle versions will be just around 100 mb which should have a huge impact on your storage.
Upvotes: 1