gpt4 book ai didi

android - 无法编译Android测试应用

转载 作者:行者123 更新时间:2023-11-29 02:04:27 25 4
gpt4 key购买 nike

我决定尝试为 Android 编程。我开始了他们的教程,但无法运行第一个项目自动创建的应用程序。我怀疑我的电脑设置有误,但不知道在哪里搜索错误。

教程说到新建项目的目录运行ant debug。这会为我抛出一个错误:java.lang.NoClassDefFoundError: com.android.sdklib.internal.build.DebugKeyProvider。我怀疑 SDK 安装不正确,但不知道出了什么问题或如何修复它。

我的电脑运行 openSUSE 12.1 64 位。我安装了 Oracte JDK 版本 1.7.0_04,以及包括工具和平台 Android 4.0 和 4.0.3 的 Android SDK。安装后,我将android tools文件夹添加到我的路径环境中,并为我的手机添加了一个udev规则,但没有做进一步的定制。亚行看到我的手机,我可以用 ddms 截屏。我不使用 Eclipse。

我是否遗漏了设置的某些部分?我该如何解决这个问题?

更新 我找到一个mailing list discussion关于有同样问题的人。他通过在/usr/bin 中更新一个名为“keytool”的符号链接(symbolic link)来指向正确的文件来解决这个问题。我没有这样的链接,所以我创建了它。问题仍然存在。回答该主题的人建议 SDK 中可能缺少一个名为“jarutil.jar”的文件。我的 SDK 中没有这样的文件,即使从头开始重新安装也是如此。由于讨论已经超过一年,我什至不知道这样的文件是否应该出现在当前版本中。

这是 ant debug 命令的完整输出:

rumtscho@bradbury:~/dev/learn-android/MyFirstApp> ant debug Buildfile: /home/rumtscho/dev/learn-android/MyFirstApp/build.xml

-set-mode-check:

-set-debug-files:

-set-debug-mode:

-debug-obfuscation-check:

-setup: [echo] Creating output directories if needed... [echo] Gathering info for MyFirstApp... [setup] Android SDK Tools Revision 19 [setup] Project Target: Android 4.0.3 [setup] API level: 15 [setup] [setup] ------------------ [setup] Resolving library dependencies: [setup] No library dependencies. [setup] [setup] ------------------ [setup] API<=15: Adding annotations.jar to the classpath. [setup] [setup] ------------------ [setup] WARNING: No minSdkVersion value set. Application will install on all Android versions.

-build-setup:

-pre-build:

-code-gen: [echo] ---------- [echo] Handling aidl files... [aidl] No AIDL files to compile. [echo] ---------- [echo] Handling RenderScript files... [renderscript] No RenderScript files to compile. [echo] ---------- [echo] Handling Resources... [aapt] No changed resources. R.java and Manifest.java untouched. [echo] ---------- [echo] Handling BuildConfig class... [buildconfig] Generating BuildConfig class.

-pre-compile:

-compile: [javac] Compiling 1 source file to /home/rumtscho/dev/learn-android/MyFirstApp/bin/classes

-post-compile:

-obfuscate:

-dex: [dex] Found modified input file [dex] Converting compiled files and external libraries into /home/rumtscho/dev/learn-android/MyFirstApp/bin/classes.dex...

-crunch: [crunch] Crunching PNG Files in source dir: /home/rumtscho/dev/learn-android/MyFirstApp/res [crunch] To destination dir: /home/rumtscho/dev/learn-android/MyFirstApp/bin/res
[crunch] Crunched 0 PNG files to update cache

-package-resources: [aapt] Creating full resource package...

-package: [apkbuilder] Current build type is different than previous build: forced apkbuilder run. [apkbuilder] Creating MyFirstApp-debug-unaligned.apk and signing it with a debug key...

BUILD FAILED /home/rumtscho/android-sdk-linux/tools/ant/build.xml:886: The following error occurred while executing this line: /home/rumtscho/android-sdk-linux/tools/ant/build.xml:897: The following error occurred while executing this line: /home/rumtscho/android-sdk-linux/tools/ant/build.xml:307: java.lang.NoClassDefFoundError: com.android.sdklib.internal.build.DebugKeyProvider at java.lang.Class.initializeClass(libgcj.so.12) at com.android.sdklib.build.ApkBuilder.getDebugKeystore(ApkBuilder.java:919) at com.android.ant.ApkBuilderTask.execute(ApkBuilderTask.java:334)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at java.lang.reflect.Method.invoke(libgcj.so.12) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at java.lang.reflect.Method.invoke(libgcj.so.12) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:398) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at java.lang.reflect.Method.invoke(libgcj.so.12) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
at com.android.ant.IfElseTask.execute(IfElseTask.java:124) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at java.lang.reflect.Method.invoke(libgcj.so.12) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
at com.android.ant.IfElseTask.execute(IfElseTask.java:124) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at java.lang.reflect.Method.invoke(libgcj.so.12) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at java.lang.reflect.Method.invoke(libgcj.so.12) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:398) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at java.lang.reflect.Method.invoke(libgcj.so.12) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.Target.execute(Target.java:390) at org.apache.tools.ant.Target.performTasks(Target.java:411) at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368) at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:809) at org.apache.tools.ant.Main.startAnt(Main.java:217) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109) Caused by: java.lang.ClassNotFoundException: java.security.KeyStore$ProtectionParameter at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1361) at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1311) at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1064) at java.lang.ClassLoader.loadClass(libgcj.so.12) at java.lang.Class.initializeClass(libgcj.so.12) ...48 more

Total time: 3 seconds

最佳答案

Oracle JDK rpm 不以 SuSE 的方式配置 Java。特别是,您的 JAVA_HOME 可能设置不正确。

试试 JAVA_HOME=/usr/java/default ant debug

还要确保 readlink -f `which java` 指向您的 Oracle JDK

看来您可以在 /etc/java/java.conf 中永久设置 JAVA_HOME

Apache Ant 手册建议使用以下方式设置 ant 需要的环境变量:

export ANT_HOME=/usr/local/ant
export JAVA_HOME=/usr/local/jdk-1.5.0.05
export PATH=${PATH}:${ANT_HOME}/bin

其中jdk号应该指向电脑上安装的JDK号。这也永久设置变量。

关于android - 无法编译Android测试应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10842501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com