Skip to content
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

Docs: cordova run --emulator not working with Android SDK Command-line Tool 11.0 #1346

Open
3 tasks done
txcxjp opened this issue Nov 24, 2023 · 4 comments
Open
3 tasks done

Comments

@txcxjp
Copy link

txcxjp commented Nov 24, 2023

Bug Report

Problem

cordova run --emulator command fails and the emulator don't be launched.

What is expected to happen?

The emulator starts and launch the sample application.

What does actually happen?

The application was built successfully but the emulator don't be launched.
Below is the log the command outputted.

PS C:\dev\MyProject> cordova run --emulator
Checking Java JDK and Android SDK versions
ANDROID_HOME=C:\Users\skyis\AppData\Local\Android\Sdk (recommended setting)
ANDROID_SDK_ROOT=C:\Users\skyis\AppData\Local\Android\Sdk (DEPRECATED)
Using Android SDK: C:\Users\skyis\AppData\Local\Android\Sdk
Subproject Path: CordovaLib
Subproject Path: app

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.6/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 3s
50 actionable tasks: 50 up-to-date
Built the following apk(s):
        C:\dev\MyProject\platforms\android\app\build\outputs\apk\debug\app-debug.apk
Checking Java JDK and Android SDK versions
ANDROID_HOME=C:\Users\skyis\AppData\Local\Android\Sdk (recommended setting)
ANDROID_SDK_ROOT=C:\Users\skyis\AppData\Local\Android\Sdk (DEPRECATED)
Using Android SDK: C:\Users\skyis\AppData\Local\Android\Sdk
Command failed with exit code 1: avdmanager list avd
�G���[: ���C���E�N���Xcom.android.sdklib.tool.AvdManagerCli�̃��[�h����LinkageError���������܂���
        java.lang.UnsupportedClassVersionError: com/android/sdklib/tool/AvdManagerCli has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0

Information

The error message says that the command avdmanager list avd cannot execute because Java version is too old.
avdmanager command is part of Command-line tools and actually it doesn't work with Java11 which specified by Cordova.

Reading emulator.js, it indeed calls avdmanager command.

According to the document, using Environment Variable CORDOCA_JAVA_HOME, we can use multiple Java versions differently for Cordova and other programs.
I thought that I can solve this problem by setting CORDOCA_JAVA_HOME as JDK11 and JAVA_HOME as JDK21 because Command-line tools is not part of Cordova and it should be execute with the Java specified with JAVA_HOME, but it didn't work.

Reading java.js, if the environment variable CORDOVA_JAVA_HOME is specified, it set JAVA_HOME as CORDOVA_JAVA_HOME's value and the original value of JAVA_HOME is discarded.
That may be why avdmanager is executed with old java version.

Command or Code

cordova create MyProject
cd MyProject
cordova platform add android
cordova run --emulator

Environment, Platform, Device

Windows10 (Japanese language)
Powershell 5.1.19041.3693

Environment Variables

  • PATH
    • C:\Users\myname\AppData\Local\Android\Sdk\emulator
    • C:\Users\myname\AppData\Local\Android\Sdk\cmdline-tools\latest\bin
    • C:\Users\myname\AppData\Local\Android\Sdk\platform-tools
    • C:\Users\myname\AppData\Local\Android\Sdk\build-tools
  • ANDROID_HOME
    • C:\Users\myname\AppData\Local\Android\Sdk
  • ANDROID_SDK_ROOT
    • C:\Users\myname\AppData\Local\Android\Sdk
  • GRADLE_HOME
    • C:\ProgramData\chocolatey\lib\gradle\tools\gradle-8.4
  • JAVA_HOME
    • C:\Program Files\OpenJDK\jdk-21.0.1
  • CORDOVA_JAVA_HOME
    • C:\Program Files\OpenJDK\jdk-11

Version information

Windows10 22H2
Android SDK Build-tools 33.02
Android SDK Command-line Tools(latest)  11.0
Android Emulator    32.1.15
Android SDK Platform-Tools  34.0.5
Android Studio  Giraffe 2022.3.1 Patch 4
Cordova 12.0.0 (cordova-lib@12.0.1)
cordova-android 12.0.1
Gradle  8.4

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@breautek
Copy link
Contributor

Next major for API 34 support will bump the JDK requirement to 17.

Despite the docs stating it requires JDK 11, JDK 17 should work on cordova-android@12. So you should be able to set CORDOVA_JAVA_HOME to a JDK 17 environment, while keeping your JDK 21 environment. Note that JDK 21 won't work because cordova-android@12 is using gradle 7.6.

Alternatively downgrading command line tools package to version 10.0 will probably also work.

It's good to know that the command line tools actually has a dependency on the java runtime, so this definitely should be reflected in the docs, rather than suggesting to install the latest version.

@txcxjp
Copy link
Author

txcxjp commented Dec 3, 2023

Thank you for your reply.

The problem was solved by using JDK17 you suggested.
As I don't know the criteria that this ticket can be closed, I'll keep this open. I think someone can close this if no problem remained for this project.

I agree with improbe the document by writing about JDK version or command-line tools version to prevent new entrants from stumbling if it is premise that command-line tools uses the same JDK version to cordova uses.

Thank you anyway.

@breautek breautek transferred this issue from apache/cordova-android Feb 15, 2024
@breautek breautek changed the title cordova run --emulator not working with Android SDK Command-line Tool 11.0 Docs: cordova run --emulator not working with Android SDK Command-line Tool 11.0 Feb 15, 2024
@breautek
Copy link
Contributor

I moved this to the docs repo. I think we should just document using a specific version of command line tools instead of latest.

@kevinYCKim33
Copy link

Downgrading command line tools package from latest to version 10.0 worked for me.

Here is my .zshrc file at the moment:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools/
# changed below from /latest/bin
export PATH=$PATH:$ANDROID_HOME/cmdline-tools/10.0/bin/
export PATH=$PATH:$ANDROID_HOME/build-tools
export PATH=$PATH:$ANDROID_HOME/emulator/

Also deleted my node_modules, platforms, plugins and ran npm i, cordova platform add android I'm able to run cordova run --emulator

As @breautek stated, if we could update Installing SDK Command-line Tools (latest)
to say to download 10.0 instead of latest it would really help out people setting up Cordova.

Huge thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants