Gradle installed but Cordova not seeing it - java

When I install gradle 7.0, it automatically installs openjdk 15 but cordova requires openjdk 1.8. I uninstalled gradle then installed gradle 6.5 but it refuses to install. I also added gradle manually and added it to the environment variable path but cordova keeps insisting gradle is uninstalled. I checked the gradle version on the terminal and it exists. Can someone please help? How else do I install gradle?
/ % brew install gradle 6.5
Updating Homebrew...
==> Searching for similarly named formulae...
These similarly named formulae were found:
cc65 ✔ libde265 x265
To install one of them, run (for example):
brew install cc65 ✔
Error: No available formula or cask with the name "6.5".
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.

Make sure to install Gradle creating the proper environment variable for the binary URL:
CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL
The local path must also be added to the PATH system variable.
Also, do not jump directly to latest Gradle version. Install the one that is required by your Cordova Android/iOS platform version.

Related

Flutter Java error "Unsupported class file major version 63"

"General error during conversion: Unsupported class file major version 63"
I've tried multiple suggestions on here. None have worked. I think I need more of a step-by-step solution because I've tried installing multiple versions of Java (19,16,11), flutter clean, flutter doctor is all good, and I've installed a newer version of Android Studio (just in case). Here is what I see in VSCode:
I encountered this error while trying to run Flutter integration tests on Firebase Test Lab. I was able to solve this by updating a few things in Android Studio.
Update the Project's JDK
Open the Android Studio project settings page (File -> Project Settings) and add the newest JDK version.
Update com.android.tools.build:gradle
In android/build.gradle, update the com.android.tools.build:gradle value to the latest version found here.
dependencies {
classpath 'com.android.tools.build:gradle:7.4.1'
...
}
Update the gradle distributionUrl
In android/gradle/wrapper/gradle-wrapper.properties, update the distributionUrl property to use the latest Gradle version.
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
Other Useful Tips
You can type /usr/libexec/java_home into the terminal to see which version of Java you have installed.
You can find the current value of JAVA_HOME by running %echo $JAVA_HOME in your terminal (source).
You can update JAVA_HOME by following these steps
The problem is that somehow, either deliberately or inadvertently, you've built one or more Java files (or you're using one or more 3rd party .jars) with Java 19 ... but your "build environment" is using an older JRE. Hence the Unsupported class file error.
I, too, am using VSCode for my Flutter IDE; and I, too have Android Studio in my environment. Unfortunately, there are constantly new releases for Flutter, for VSCode, for the Android SDK, for Android Studio (with its own embedded Java/Kotlin!) and - last, but not least - for Gradle and the A/S Gradle plugin. Any one of them falling out of sync can break your entire development environment :(
I just tried to rebuild a project that compiled fine a few months ago... and (as expected) the build failed. None of the source change - but I recently upgraded A/S, and that inadvertently broke the Flutter build :(
SUGGESTION:
See if you can identify which Java class or .jar is using Java 19 ... and back it down to an older version.
In parallel, upgrade EVERYTHING in your build environment:
flutter upgrade => Flutter 3.7.3, Dart 2.19.2
VSCode update, pub upgrade => VSCode 1.751, Dart Code 3.58.0
A/S upgrade => Electric Eel 2022.1.1 Patch 1, Gradle Plugin 4.2.2
Note: Gradle Plugin 4.2.2 => Gradle version => 6.7.1, Default=Java8, AGP dependency 4.2.2
A/S Electric Eel gives you java 11... in (new!) directory "c:\Program Files\Android\Android Studio\jbr"

How to change the Gradle version?

I would like to change the Gradle version to 3.5.1 according to the project version received from git using this eclipse.
So I changed the editing path for the system environment variable, but if you enter 'gradle -v' in cmd, only 4.4 appears.
I looked for various solutions on the Internet, but it didn't work out.
How can I change the version?
And how can I erase the existing version 4.4 completely? I tried to erase it, but it kept popping up even if I deleted all the related files.
gradle -v:
One of the easiest way to change the gradle version is using sdkman. Install the required version you want and change whenever you want. Then hit
sdk install gradle <versionId>
sdk use gradle <versionId>
To check the list of versions installed
sdk list gradle
First, you need to know where Gradle is installed on your device. You can type where gradle in your terminal and the path will pop up.
Then, after you deleted the old version, go to the download page to download version 3.5.1. After download, follow the instructions in Installing manually in the Gradle installation guide.
Make sure that the old version is not included in your environment variables. If so, remove the old version and add the new one.
You can check Windows path variable by typing echo %PATH% in CMD.
Using Gradle Wrapper
To quote the manual:
If your existing Gradle-based build uses the Gradle Wrapper, you can easily upgrade by running the wrapper task, specifying the desired Gradle version:
./gradlew wrapper --gradle-version=7.4.2 --distribution-type=bin

Upgraded to Big Sur 1.6. Now maven shows this Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher

After upgrading to Big Sur 1.6 I had to run Maven. mvn clean install. I got the following error Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
I followed the suggestion offered here. Maven error : Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
No luck.
I tried removing and reinstalling both maven and java to the latest stable releases (Maven 3.8.3 and Java 14). That didn't work either.
I am finding others having these problems, but have not found a solution that works.
Has anyone found a solution.
If you have installed the maven using brew install maven and haven't setup the path variables accordingly you would get these types of issues.
To fix this remove the maven you installed via brew and download the apache maven binary zip and extract it. Then setup the path variables as shown here
Same goes for java. You should remove any sort of JDK you have installed using brew and download and install a JDK from a .dmg file. I would recommend using Oracle JDK if you can.
After doing that setup the JAVA_HOME and add it to the PATH variable.
After that it should work.

General error during semantic analysis: Unsupported class file major version 57

I'm trying to setup libgdx for a desktop game and when I try to generate the project I have this error and the build fails.
I've the latest versions of Java(13.0.2) and Gradle(6.6), both set as environment variables in the path. Can somebody help me?
The error looks like this:
Could not compile settings file 'C:\Users\noemi\Desktop\Test\settings.gradle'.
> startup failed:
General error during semantic analysis: Unsupported class file major version 57
java.lang.IllegalArgumentException: Unsupported class file major version 57
This is not a LibGDX issue. Gradle 5 is incompatible with Java 13. You either need to update Gradle (the wrapped version in your project) to Gradle 6 or later, or you need to use a lower version of the JRE.
To update the wrapped gradle, go to gradle/wrapper/gradle-wrapper-properties in your project and update the version number. I'm using 6.1.1.
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
If you have an older LibGDX project, you might have to modify the build.gradle file in the android module to be compatible with Gradle 6. You can copy-paste to replace the copyAndroidNatives task with the one here.
startup failed:
General error during semantic analysis: Unsupported class file major version 61
how to fix this react native issues
JAVA JDK 17
Go to the android/ directory of your react-native project
Create a file called local.properties with this line:
sdk.dir=C:\Android\sdk
GOTO
android\gradle\wrapper\gradle-wrapper.properties
CHANGE
distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip
TO
distributionUrl=https://services.gradle.org/distributions/gradle-7.3-all.zip
GOTO
android\gradle.properties
add this line
org.gradle.jvmargs=-Xmx1536M --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
This problem occurred when I run my old Flutter project that I coded 2 years ago. I think with Android project will also fix in the same way. I'm use MacOS and Android Studio Bumblebee.
First, need to move to the android folder and check gradle version:
cd android
./gradlew --version
It show Gradle version 6.7.1 and you need attention to the JVM line, and my JDK version is 15.0.2. It is too new for this project. So you must to downgrading from open jdk version to old version or upgrade Gradle version in gradle/wrapper/gradle-wrapper.properties to new version.
If you downgrade JDK version, you can download from this. In my case, I downgraded from Java SE 15 to Java SE 11.
After I open Android of Flutter project
Go to Preferences->Build, Execution, Deployment → Build Tools → Gradle → and choose JDK version 11.
Go to Build -> Clean Project -> Rebuild Project.
Go to Terminal run java --version, if it still show JE version 15 then You must set JAVA_HOME before.
You only need to add the following to your .bash_profile or .zshrc
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.15.jdk/Contents/Home
Save and go to android folder and run again
./gradlew --version
It will show JDK version 11 correct.
Finally, run flutter run.
If you're using eclipse, go to
Eclipse > Preferences > Gradle
Update Java home to point to Java home location
I have downgraded gradle file thats why this error happens so finally I have to change Gradle wrapper file From
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
to
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
Check gradle version and bundle version using the following link
Link https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
If you want to upgrade android/gradle/build.gradle change dependencies classpath 'com.android.tools.build:gradle:[latest version]'

Gradle: Could not determine java version from '11.0.2'

I ran the following comment:
./gradlew app:installDebug
only to be met with the log:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '11.0.2'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
My version of gradle is 5.1.1:
------------------------------------------------------------
Gradle 5.1.1
------------------------------------------------------------
Build time: 2019-01-10 23:05:02 UTC
Revision: 3c9abb645fb83932c44e8610642393ad62116807
Kotlin DSL: 1.1.1
Kotlin: 1.3.11
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.2 (Oracle Corporation 11.0.2+9-LTS)
OS: Mac OS X 10.13.6 x86_64
I'm not sure how to proceed (I tried upgrading/downgrading, but nothing has worked so far).
UPDATE: When I ran ./gradlew --version, I got the following:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '11.0.2'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
My .../gradle/wrapper/gradle-wrapper.properties contains the following including distributionUrl=.../gradle-4.1-rc-1-all.zip:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip
There are two different Gradle applications in your system.
the system-wide Gradle
This application is invoked by gradle (arguments).
the gradle-wrapper
The gradle-wrapper is specific to every project and can only be invoked inside the project's directory, using the command ./gradlew (arguments).
Your system-wide gradle version is 5.1.1 (as the OP explained in the comments, running the command gradle --version returned version 5.1.1).
However, the failure is the result of a call to the gradle-wrapper (./gradlew). Could you check your project's gradle wrapper version? To do that, execute ./gradlew --version inside your project's folder, in the directory where the gradlew and gradlew.bat files are.
Update 1:
As running ./gradlew --version failed, you can manually check your wrapper's version by opening the file:
(project's root folder)/gradle/wrapper/gradle-wrapper.properties
with a simple text editor. The "distributionUrl" inside should tell us what the wrapper's version is.
Update 2:
As per the OP's updated question, the gradle-wrapper's version is 4.1RC1.
Gradle added support for JDK 11 in Gradle 5.0. Hence since 4.1RC does not support running on JDK 11 this is definitely a problem.
The obvious way, would be to update your project's gradle-wrapper to version 5.0.
However, before updating, try running gradle app:installDebug. This will use your system-wide installed Gradle whose version is 5.1.1 and supports running on Java 11. If this works, then your buildscript (file build.gradle) is not affected by any breaking changes between v.4.1RC1 and v.5.1.1 and you can then update your wrapper by executing from the command line inside your project's folder: gradle wrapper --gradle-version=5.1.1 [*].
If gradle app:installDebug fails to execute correctly, then maybe you need to upgrade your Gradle buildscript. For updating from v.4.1RC1 to 5.1.1, the Gradle project provides a guide (1, 2) with breaking changes and deprecated features between minor releases, so that you can update gradually to the latest version.
Alternatively, if for some reason you can't or don't want to upgrade your Gradle buildscript, you can always choose to downgrade your Java version to one that Gradle 4.1RC1 supports running on.
[*] As correctly pointed out in the answer by #lupchiazoem, use gradle wrapper --gradle-version=5.1.1 (and not ./gradlew as I had originally posted there by mistake). The reason is Gradle runs on Java. You can update your gradle-wrapper using any working Gradle distribution, either your system-wide installed Gradle or the gradle-wrapper itself. However, in this case your wrapper is not compatible with your installed Java version, so you do have to use the system-wide Gradle (aka gradle and not ./gradlew).
As distributionUrl is still pointing to older version, upgrade wrapper using:
gradle wrapper --gradle-version 5.1.1
Note: Use gradle and not gradlew
Updating gradle/wrapper/gradle-wrapper.properties with the following version fixed it for me:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
In my case the JAVA_HOME variable was set to /usr/lib/jvm/jdk-11.0.2/. It was sufficient to unset the variable like this:
$ export JAVA_HOME=
tl;dr: downgrade java by running update-alternatives
My system gradle version was 4.4.1, and the gradle wrapper version was 4.0. After running the command given by several other answers:
gradle wrapper --gradle-version 4.4.1
I still had the same error:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '11.0.4'.
It turns out java 11 wasn't supported until gradle 4.8, and my software repositories only had 4.4.1. (Also, upgrading to newer gradle version might have been incompatible with the package I was trying to compile.)
The answer was to downgrade java. My system actually had java8 already installed, and it was easy to switch between java versions by running this command and following the instructions:
sudo update-alternatives --config java
I had the same problem here.
In my case I need to use an old version of JDK and I'm using sdkmanager to manage the versions of JDK, so, I changed the version of the virtual machine to 1.8.
sdk use java 8.0.222.j9-adpt
After that, the app runs as expected here.
To put long answer short, upgrade your gradlew using the system gradle tool. Note that the below upgrade works even if your system gradle version is < 5.
gradle wrapper --gradle-version=5.1.1
Because your wrapper version does not support 11+ you can make simple trick to cheat newer version of InteliJ forever.
press3x Shift -> type "Switch Boot JDK" -> and change for java 8.
Or If you want to work with java 11+ you simply have to update wrapper version to 4.8+
I've had the same issue. Upgrading to gradle 5.0 did the trick for me.
This link provides detailed steps on how install gradle 5.0
I had the same issue in Windows. My gradle configuration was to set use JDK1.8, but JAVA_HOME was configured to use another JDK.
Solution :
Set JAVA_HOME properly based on your configured JDK in gradle
In my case, I was trying to build and get APK for an old Unity 3D project (so that I can play the game in my Android phone). I was using the most recent Android Studio version, and all the SDK packages I could download via SDK Manager in Android Studio. SDK Packages was located in
C:/Users/Onat/AppData/Local/Android/Sdk
And the error message I got was the same except the JDK (Java Development Kit) version "jdk-12.0.2" . JDK was located in
C:\Program Files\Java\jdk-12.0.2
And Environment Variable in Windows was JAVA_HOME : C:\Program Files\Java\jdk-12.0.2
After 3 hours of research, I found out that Unity does not support JDK 10, as told here. My suggestion is:
Uninstall unwanted JDK if you have one installed already.
Head here
Login to/Open a Oracle account if not already logged in.
Download the older but functional JDK 8 for your computer set-up(32 bit/64 bit, Windows/Linux etc.)
Install the JDK. Remember the installation path.
If you are using Windows, Open Environment Variables and change Java Path via Right click My Computer/This PC>Properties>Advanced System Settings>Environment Variables>New>Variable Name: JAVA_HOME>Variable Value: [YOUR JDK Path, Mine was "C:\Program Files\Java\jdk1.8.0_221"]
In Unity 3D, press Edit > Preferences > External Tools and fill in the JDK path (Mine was "C:\Program Files\Java\jdk1.8.0_221").
Also, in the same pop-up, edit SDK Path. (Get it from Android Studio > SDK Manager > Android SDK > Android SDK Location.)
If needed, restart your computer for changes to take effect.
Just goto your "project folder/gradle/gradle-wrapper.properties" and in distibutionUrl where your gradle version is metioned, check the new updated gradle version from here and change it in "distributionUrl" and done!
I had a similar problem: my default gradle wrapper was version 4.x, while the support for higher versions of Java has been added in Gradle 5.
I've updated my gradlew as described here: https://docs.gradle.org/current/userguide/gradle_wrapper.html#sec:upgrading_wrapper
TLTD:
./gradlew wrapper --gradle-version 5.6.2
I have the similar issue in Windows with redhat java-11 version, edited the gradle-wrapper.properties and updated the distributionUrl as below with gradle-6.5.1-bin.zip
and its working for me.
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
If you've android studio version 4.2.2 its starts as default Java 11.0.8
Check your version Android Studio -> About Android Studio
Change 11.0.8 to JDK 8
1- Install the JDK8
2- Install the Choose Runtime plugin
3- Open action tab: Command + Shift + A ⇧⌘A
4- Choose runtime and select jdk 8 on list
Head over toandroid/gradle/wrapper/gradle-wrapper.properties and update the distributionUrl with the latest gradle version.
Go to https://gradle.org/releases/ to get the latest version, then edit it here.
https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
7.3.3 being the latest version release.
https\://services.gradle.org/distributions/gradle-#latest_gradle-version#-all.zip
Navigate to Project/gradle/wrapper/gradle-wrapper.properties and manually changed the distributionUrl to distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-bin.zip and it worked Hope this helps someone.
I solved this by clicking on File -> Project Structure then changed the JDK Location to Use Embedded JDK (Recommended)
Getting this error when doing a cordova build android --release
I was able to resolve this, after trying so so many different things, by simply doing :
npm install cordova -g # to upgrade to version 10.0.0
cordova platform rm android
cordova platform add android # to upgrade to android version 9.0.0
I ran into a similar issue. I deleted these:
libraries and caches from the .idea folder ( YourApp > .idea > .. ) AND
contents of the build folder.
then rebuild.
* DON'T FORGET TO BACKUP YOUR PROJECT FIRST *
I was facing the same issue in Docker setup, while I was trying to install Gradle-2.4 with JDL 11.0.7. I have to install a later version to fix the issue.
Here is the Working Dockerfile
FROM openjdk:11.0.7-jdk
RUN apt-get update && apt-get install -y unzip
WORKDIR /gradle
RUN curl -L https://services.gradle.org/distributions/gradle-6.5.1-bin.zip -o gradle-6.5.1-bin.zip
RUN unzip gradle-6.5.1-bin.zip
ENV GRADLE_HOME=/gradle/gradle-6.5.1
ENV PATH=$PATH:$GRADLE_HOME/bin
RUN gradle --version
The simplest for a quick and dirty test is to just use an override, for example:
> JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/ ./gradlew build
since the wrapper checks for JAVA_HOME you can just pick any you want on each run.
You might missed to install maven please install the maven then please checked. it will work after ....
As others have mentioned, Java 11 support was added in Gradle 5. The solution is to upgrade your Gradle wrapper:
Go here to figure out the latest version of Gradle: https://gradle.org/releases/
Upgrade the Gradle wrapper
If you have Gradle installed on your machine:
gradle wrapper --gradle-version 7.2
If you don't have Gradle installed:
Modify gradle/wrapper/gradle-wrapper.properties
Update distributionUrl with the latest version of Gradle, e.g.
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
Upgrade the remaining wrapper files (gradle-wrapper.jar, gradlew, gradlew.bat)
./gradlew wrapper --gradle-version 7.2
Since you're upgrading from an old version of Gradle, you'll probably get errors like these:
Could not find method compile() for arguments ...
Could not find method testCompile() for arguments ...
To fix these, edit build.gradle and replace every instance of compile with implementation and replace testCompile with testImplementation.
I ran into the same issue in Ubuntu 18.04.3 LTS. In my case, apt installed gradle version 4.4.1. The already-install java version was 11.0.4
The build message I got was
Could not determine java version from '11.0.4'.
At the time, most of the online docs referenced gradle version 5.6, so I did the following:
sudo add-apt-repository ppa:cwchien/gradle
sudo apt update
sudo apt upgrade gradle
Then I repeated the project initialiation (using gradle init with the defaults). After that, ./gradlew build worked correctly.
I later read a comment regarding a change in format of the output from java --version that caused gradle to break, which was fixed in a later version of gradle.
got to project file..
gradle/wrapper/gradlewrapper.properties
there you can change the value of distributionurl to what ever the lastest version is. (Found on docs.gradle.org)
I am running Gradle on Windows.
In my case, I already had the older Gradle version present in my system and set it into the "Environment Variable".
That is the reason the error occurred.
So I removed the old version, set the new one in "Environment Variable" - path variable and its starts working.
if you're working on a legacy project; Up the gradle version to 6.9 and the Gradle plugin version to 4.2.2. This is the Gradle version to which you can safely turn up without anything breaking.

Categories