-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update check_reqs.js - allow JDK > 1.8 #928
Conversation
Checking JDK should not fail when there is another version installed like 11.0.6 for example. Redme file declare clearly > Requires > Java JDK 1.8 or greater
Indentation fix
fix trailing spaces
Is actually wrong. Android requires 1.8, not anything lower, not anything greater. So if the readme states this, it probably should be changed. But I would favour the README change in a separate PR. |
As Norman said, Android requires Java 8, so the docs should be changed, not the code. |
I am not native speaker so you may not understood me what I mean with this PR. With my code you can use any java version. Who has today lower than 1.8? Next LTS version is 11. So my code works well with both But you can do what ever you want. Have a nice day. |
I'm reopening so can be tested, but supposedly Android only works with Java 8. |
I'm pretty sure this is the case. The android documentation says that the target compile needs to be set to jdk 8, which is what we define in gradle. https://developer.android.com/studio/write/java8-support So we cannot use features that only appear in later versions. I still think it's safer to stick with java8, but perhaps the checks can be less restrictive, which I believe is what this PR tries to do. I would like to see some tests added to ensure the checks returns appropriately when it finds older versions of java and when it finds newer versions of java. And if we go that route, then I guess this will make #929 obsolete. |
I just tested openJDK 11 on ubuntu and the tests was passed.. so I think was indeed wrong about the android sdk strictly requiring java 8. If we are going to open up that requirements check though, I think we should have a suite of tests for both java8 and java11 in the github actions. |
Hi ! Actually, I patch this file manually to Or ... can we set a ['CORDOVA_JAVA'] env variable so everyone can use last update of java, and a specific version for cordova ? |
Sorry, I just saw that the NPM package |
Nope, i dont think you're suggestion is out dated. I'm not sure which route we should take, but there are two different routes imo:
|
IMO, option 2 is safer and doesn't introdruce new bugs if it works great with JDK8. |
On this note, I did add java 11 to the test CI on my fork, and it all appears to pass: https://github.com/breautek/cordova-android/runs/676508506?check_suite_focus=true |
is there any quick fix to this? I have multiple JREs/JDKs and even if my JAVA_HOME points to jdk1.8,
|
Improvements were made with how java is detected, so this may be fixed in |
I can't build with nightly. See below...
|
Hey, sorry, I started editing my original post but it seems I forgot to actually post it (or didnt work) I got it to work. there was still a ref to javac 11 in the path before 1.8 (but not for java), so when I rearranged some more path vars it worked. |
@@ -393,11 +393,13 @@ module.exports.run = function () { | |||
console.log('ANDROID_SDK_ROOT=' + process.env['ANDROID_SDK_ROOT'] + ' (recommended setting)'); | |||
console.log('ANDROID_HOME=' + process.env['ANDROID_HOME'] + ' (DEPRECATED)'); | |||
|
|||
if (!String(values[0]).startsWith('1.8.')) { | |||
if (values[0] === undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this, theoretically, allow JDK <8, too? They would, e.g., start with 1.6 for a JDK6. We should maybe use something like this in order to check for >= 52
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, we should still throw an error for JDK < 8. We might be able to use semver. We already depend on it IIRC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that in Java <=1.8 it’s labeled as 1.x
while Java 9 and newer dropped the 1.
. This complicates the check a little bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, using semver it would still only entail checking that we satisfy >=1.8
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, 14 > 1.8, so this could work/be a sufficient check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With semver
the following should work:
if (values[0] === undefined) { | |
if (!semver.satisfies(semver.coerce(values[0]), '>= 1.8')) { |
I would like to get this fixed, would definitely agree with @timbru31 to check for JDK < 8. |
); | ||
} else { | ||
console.log('Detected JDK version: ' + values[0] + '\n'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we want to add this output. If so, it needs to use events
like everything else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer this text to be verbose
output, personally.
It would be great if we could finally allow builds using the latest SDKs! I remember that I thought this was possible quite some time ago. But when I did some tests in preparation of a PR it appeared as if the newer SDKs did break the build after all. Maybe I just messed up something else instead. I really hope so. |
As I said in this thread on the mailing list([1]), I was able to use OpenJDK 13 to build and install a couple of non-Cordova Android apps from the command line, including a React Native project. (OpenJDK 13 also worked for me with building and installing https://github.com/sqlcipher/sqlcipher-android-tests from the command line.) A side point is that we are using Gradle a little differently than most other Android projects, as discussed in the same thread ([1]). So yes, I think we should update to allow JDK > 1.8, properly, with proper review and testing. I took the liberty to update the title again to better reflect the actual change proposed here. |
Here's the problem I encountered and still do when using Java > 8:
An explanation of the Exception can be found at stackoverflow. Unfortunately there seems to be no workaround for Java 11. It might work with later Android SDK tools. But I don't know what we support exactly. This issue does not have to block this PR, since users should be able to use latest JDK if it works for them and the SDKs they are using. But we should maybe have an idea of what will and what will not work together, so we can estimate the impact of allowing newer JDK versions and maybe warn users or catch errors appropriately. |
Strange. Is it possible you're still using the old command line tools? Android now offers command line tools as a separate package that you need to install. Perhaps this is updated for java 11+ support. |
@breautek Yeah, it's been some time since I did Android development, so I still have the tools that come with the SDK (or you install via the sdkmanager?). I did not know there were new tools. If this is an unsupported or deprecated setup we don't have to worry. Hopefully we call the right tools from |
I haven't been doing a whole lot of mobile development stuff at my workplace lately, but I'll install JDK 11 and see what kind of issues I run into with. My SDK environment is relatively up to date with everything as well. Edit: Actually I'm seeing similar issues running JDK 11 as well, even Android Studio GUI doesn't work properly for me when I have Not sure why my fork had all the tests passing, perhaps most of these android studio calls are mocked...? https://github.com/breautek/cordova-android/runs/676508506?check_suite_focus=true Edit 2: Yah, quick glance at the unit tests, it looks like most android sdk calls are mocked. So it looks like my original interpretation of Android SDK strictly supports java 8 is correct I think... |
Thank you for your PR, but I'm certain that Android SDK tools doesn't play nicely with any java version above 8. You can get Java11 working with the android tools, but it requires some hackery. Depending on this is not an acceptable solution, it should work out of the box. So unfortunately, I don't see supporting java11 in the foreseeable future. This is something we can return to once Android Studio/Android SDK Tools supports java11, or greater. |
Just some more details from my side: Even the latest (6609375) Android Command Line Tools did not work properly for me using Java 11. While
|
I wanted to switch from an old docker image to
So I wanted to know if maybe @aahlenst (who wrote this article) has a trick up his sleeve and can show us what could be done to make it work. |
To make things work:
Install instructions:
Then, use sdkmanager to install all required dependencies. PATH configuration:
|
Thanks for the fast answer! |
I use a faster way, just sed the Fix JAVA_HOME not detected: #928
I run this command from my VueJS project folder. You should probably fix the path. |
Checking JDK should not fail when there is another version installed like 11.0.6 for example.
Redme file declares clearly
Motivation and Context
I have another verison installed. It fails but shouldn't.