Skip to content

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

Open
@txcxjp

Description

@txcxjp

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 ([email protected])
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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions