尝试使用ionic构建Android模拟器失败,出现“找不到类:javac1.8”的错误。

14

我正在尝试使用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

有没有人知道这个问题可能是什么原因引起的?谢谢。

2个回答

12
主要问题在于 ant < 1.9.0 不支持 Java 8。请参见此处的已接受答案:
javac1.8 class not found 如果更改使用的 ant 版本不方便,则使用 Java 6 或 7 可行。

使用“brew update”命令更新后,再执行“brew install ant”命令以获取最新版本。我混淆了思路,开始执行了错误的“npm install ant”命令。 - Abhinav Gujjar
我遇到了相同的错误,但是我使用的是ant 1.10.1?我的Java版本是jdk1.8.0_112。 - Samir Boulos

5

这对我很有用,设置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>

<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> - Alvaro

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接