尝试用离子构建Android模拟器失败了。“未找到类:javac1.8”

2022-09-04 02:39:46

我正在尝试使用ionic框架的“ionic emulate android”命令来模拟Android。

但它会引发异常。

 [aapt] Generating resource IDs...
 [echo] ----------
 [echo] Handling BuildConfig class...
 [buildconfig] Generating BuildConfig class.

 -pre-compile:

 -compile:

 BUILD FAILED
 C:\adt-bundle-windows-x86-20131030\sdk\tools\ant\build.xml:601: The following er
 ror occurred while executing this line:
 C:\adt-bundle-windows-x86-20131030\sdk\tools\ant\build.xml:720: The following er
 ror occurred while executing this line:
 C:\adt-bundle-windows-x86-20131030\sdk\tools\ant\build.xml:734: Class not found:
  javac1.8

 Total time: 1 second

 C:\PhoneApps2\myApp2\platforms\android\cordova\node_modules\q\q.js:126
                throw e;
                      ^
 Error code 1 for command: cmd with args: /s,/c,ant,debug,-f,C:\PhoneApps2\myApp2
 \platforms\android\build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
 Error: cmd: Command failed with exit code 8
     at ChildProcess.whenDone (C:\Users\Colin\AppData\Roaming\npm\node_modules\co
 rdova\src\superspawn.js:112:23)
     at ChildProcess.EventEmitter.emit (events.js:98:17)
     at maybeClose (child_process.js:730:16)
     at Process.ChildProcess._handle.onexit (child_process.js:797:5)
 Unable to emulate app on platform android. Please see console for more info.

我安装了最新版本的 JRE 和 JDK。在我的系统变量中;

JRE_HOME:  C:\Program Files (x86)\Java\jre8
JAVA_HOME: C:\Program Files (x86)\Java\jdk1.8.0
ANT_HOME: C:\Users\Colin\AppData\Roaming\npm\node_modules\ant\ant
PATH: ...;%ANT_HOME%\bin;%PATH%\tools;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%JAVA_HOME%\bin;%JRE_HOME%\bin

有没有人知道是什么可能导致这个问题?谢谢


答案 1

主要问题是蚂蚁<1.9.0不支持Java 8。在这里看到接受的答案:
找不到javac1.8类

如果不方便更改使用的 ant 版本,则使用 Java 6 或 7 将起作用。


答案 2

这对我有用,设置或.compiler="javac1.6"compiler="javac.17"

当然,您必须安装java1.6 / 1.7。

<target name="compile">
    <javac srcdir="src" destdir="build/classes" source="1.6" target="1.6" compiler="javac1.6">
        <classpath>
            <fileset dir="lib">
                <include name="*.jar" />
            </fileset>
        </classpath>
    </javac>

推荐