Gradle does not point to specified version - android

I am trying to upgrade the gradle wrapper version in my react-native android project.
I did not install gradle globally in my Mac, I just use the wrapper that comes with react-native, it was version 2.14.1. I want to use a library and it requires gradle 4.4+ and I followed the official tutorial. Off the bat, I got this Issue.
I found that whenever I type ./gradlew -v it will always refer to the /Users/rexlow/.gradle/wrapper/dists in my user directory, although I already did specify that I want to use gradle-4.4-all.zip which is the newer version. The zip file is now in my project wrapper folder, (I followed this thread)
As you can see from the image below, I tried to check for the gradle version but it will always show 2.14.1.
Then, I tried deleting the 2.14.1 gradle folder from /Users/rexlow/.gradle/wrapper/dists and run the version checking command again, and for heaven sake, it went on and download the 2.14.1 version because the folder wasn't there.
How can I altogether use a new gradle version in my project? Altering gradle-wrapper.properties does not work in my case. Let me know if you need to have a look at other files.
Thanks!

The gradle folder should be located inside android instead of app.

Related

Can't compile Unity Project with ARCore SDK - Problem with Gradle

I am trying to solve this problem for a few days now. Whenever I import ARCore SDK, to Unity, I cannot compile my project.
The error I am facing now is:
Minimum supported Gradle version is 5.6.4. Current Version is 5.1.1. If using the gradle wrapper, try editing the distributionUrl.
I did so, I saw in my eyes a new version is imported but I am keep getting this error.
Here are some other things I tried:
Trying to import the SDK to multiple versions of Unity.
Using a different computer.
Not changing the minimum API Level to 24.
Building the app without scenes.
trying to use different Gradle versions besides 5.6.4. In particular, 6.7, 6.1.1
Creating a system variable under Path: C:\Gradle\gradle-6.7\bin
Removing 5.1.1 folder from the Temp folder of the project, whenever I compile it (Although it keeps appearing of course)
Following the guide found at:
https://developers.google.com/ar/develop/unity/quickstart-android
Ensuring JDK, JVM and all required components are installed.
All to no avail. The project is not compiling.
Any help would be greatly appreciated!
EDIT:
I believe the root of the problem is that I haven't changed the Gradle version somewhere, despite doing so at the wrapper. The reason I stuck at 5.1.1 has something to do with the default Gradle version of my Unity version.
https://docs.unity3d.com/Manual/android-gradle-overview.html
Question is, how to solve it.
I can think about two ways to solve it (but they are pretty similar):
First Option:
Download the gradle version you want, navigate to where Unity's gradle is located in:
C:/{UnityEditorsDirectory}/{UnityVersionDirectory}/Editor/Data/PlaybackEngines/AndroidPlayer/Tools/gradle
Then replace lib folder with your new gradle lib folder.
Second Option:
In case this doesn't work, you can also try to:
Open Unity Editor, go to the menu tab Edit->Preferences->External Tools
Scroll down and find this toggle:
If you uncheck the toggle, the editor will allow you to browse where your gradle is located, paste your new directory and try if it works.
TAKE CARE: Unity's gradle version is the one that Unity's people have tested so...something can explode unexpectedly!

What's the proper way to upgrade gradle in Android Studio?

Most resources online say that you update gradle by simply updating the distribution URL. This is the answer all over Stack Overflow and all over.
Codepath also just says that a url update is enough: https://guides.codepath.com/android/Getting-Started-with-Gradle#upgrading-gradle
I've seen scattered throughout a couple of answers that to upgrade gradle you need to run a gradle update script from the command line ./gradlew wrapper --gradle-version x.x.x.
I haven't been able to find documentation that says "This is how you update gradle". On gradles website you can see, "This is how you add the gradle wrapper". I guess I'm not sure what is enough, and I feel like a lot of people are doing it the wrong way, and maybe are not benefiting from performance and speed increases in gradle.
Any canonical answer on this? Someone from the tools team want to comment?
If your project is using the Gradle wrapper then Android Studio will automatically use it. The correct way to upgrade Gradle (via the wrapper) is to run
$ ./gradlew wrapper --gradle-version x.x.x --distribution-type all
The --distribution-type option is supported since Gradle 3.1 and allows to use the all distribution instead of the default bin distribution to get proper IDE support for Gradle build files.
If you are unsure what the latest version x.x.x is, or you are setting up a project from scratch, you might be interested in my gradle_bootstrap.sh helper script which is able to install / update the Gradle wrapper without having Gradle installed. Use it like:
$ gradle_bootstrap.sh all
Just updating the Gradle distribution URL in gradle-wrapper.properties as described in the official docs is not enough in cases where gradle-wrapper.jar itself got updated.
Finally, if you do not use the wrapper yet, Android Studio will prompt to "Click 'OK' to use the Gradle wrapper, or 'Cancel' to manually set the path of a local Gradle distribution", where the latter can point to the Gradle version that ships as part of its installation. At the example of Android Studio 2.2.3 that would be Gradle 2.14.1, which is a bit dated.

What is the purpose of gradle-wrapper.properties in Android Studio?

I have updated my gradle-wrapper.properties to 2.10 from 2.8. But I want to know that what its purpose in Android Studio. As we didn't see any gradle-wrapper properties in eclipse.
Gradle Wrapper is a type batch or shell script that downloads and automatically configures Gradle to execute tasks. Imagine that you want to run a Gradle build, well you need to download and install Gradle in your computer, so this concept allows is to distribute our project and build configurations with no need to have Gradle installed.
Also their official gradle webiste says :
Most tools require installation on your computer before you can use
them. If the installation is easy, you may think that’s fine. But it
can be an unnecessary burden on the users of the build. Equally
importantly, will the user install the right version of the tool for
the build? What if they’re building an old version of the software?
The Gradle Wrapper solves both these problems and is the preferred way
of starting a Gradle build.

How do you find out what versions of gradle is used in Android Studio

In the build.gradle files, sometimes (I'm not sure when) you'll have to specify what version of gradle is used. The last few updates of Android Studio kept breaking some build files which listed the gradle version in use. I would have to update the gradle version number to fix the build file. I wanted to know if there's a way to figure out what version of gradle is included with Android Studio, instead of having to guess. I haven't been able to find out how to do this through Android Studio.
On Windows you can navigate to C:\Users\<user>\.gradle\wrapper\dists and you can see which gradle versions have been downloaded
If you're using gradle wrapper then you can change (or just check) gradle version number in gradle-wrapper.properties file. In order to do this you have to modify distributionUrl

Gradle version 1.6 is required. Current version is 1.8-20130730220035+0000

Just updated Android-Studio to version 0.2.7 an now I get the error message from the title:
In the log window there is link to the grade setup:
No matter which option I use the error message stays the same.
I deleted my ~/.gradle directory and projects **/.gradle directories.
It seems that nothing helps.
Nitpick: compile on the command-line using \opt\gradle\1.6\bin\gradle.bat build works fine.
Go to Preferences > Project Settings > Gradle and choose "Use gradle wrapper" instead of the bundled option
Open your gradle-wrapper.properties and change the distributionUrl to use 1.7 if it is not already (mine was 1.6), i.e. distributionUrl=http\://services.gradle.org/distributions/gradle-1.7-bin.zip
I managed to fix my project through some combination of invalidating Android Studio cache, deleting .idea and .gradle directories and .iml files, restarting Studio, and reimporting the project:
on Mac OSX using Homebrew, brew install gradle then pick local gradle distribution and point to /usr/local/Cellar/gradle/1.7/libexec for gradle home:
You do not want to manage gradle at a system level, it is better handled per project. Android Studio projects already setup gradle wrapper handling when creating new projects but if you have an older one you can add the same file that Android Studio does. Think of this as an gradle bootstrap file that will download the correct gradle version per project. You can also read up on Gradle Wrapper and generate a shell script called gradlew that will provide gradle-free bootstrapping.
In gradle/wrapper/gradle-wrapper.properties in your project directory make sure you have:
#
#Tue Oct 08 13:40:54 CEST 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.7-bin.zip
Then when you go into Gradle you can set it to use the gradle wrapper. This is the default when creating new projects in Android Studio.
There are at least three approaches to migration or adding Gradle properly and using the new project structure Google and Android Studio has introduced.
Create a new project and copy over the code
Export from Eclipse to Gradle (deprecated)
Import code into Android Studio (recommended)
Try to manually get everything in order by creating the correct gradle files and reorganizing the project.
For now I'm copying the files over to a new project until the tools get a bit better.
We have two computers, one of which gave that same message after upgrading to Android Studio 0.2.7. We noticed that the computer which could still build had Gradle installed independently of Android Studio.
Installing Gradle 1.6 downloaded from the Gradle web site fixed this issue on the computer that wouldn't build.
My fix was basically what Abe did but I wanted to give a bit more explanation:
Download gradle 1.6 from the gradle website
Extract somewhere on your pc/mac
Open up android studio, go to Preferences -> Gradle (left panel) -> and chooose Local gradle distribution.
Point Gradle home to the location where you extracted gradle.
This fixed the issue for me. Using the gradle wrapper and the bundled gradle distribution both failed
In my case, i updated gradle to the latest version (1.8) and then changed the gradle.build files (for my project and for the libraries i was using) like these:
dependencies {
classpath 'com.android.tools.build:gradle:0.6.1+'
}
The Synchronize files and Refresh/Invalidate cache. This seems to solve the problem. I think that Gradle in order to determine the minimum required version just reads the above value.
Here's what I did to get my project working:
Installed Gradle 1.7 on my OS (OS X users can use brew for this)
Added this to my local.properties file: sdk.dir=/Applications/Android\ Studio.app/sdk
Created gradle wrappers with gradle wrapper command.
Chose "Use gradle wrapper (recommended)" option in Android Studio.

Categories

Resources