ant debug, and sdk.dir

9

我有一个生成Android APK文件的问题。

当我运行ant debug时,编译工作正常,但当我运行ant debug时,出现以下错误:

错误提示:

iMac:proj.android smartmind$ ant debug
Buildfile: /Users/smartmind/Works/Smallthing/cocos2d-x/samples/HelloCpp/proj.android/build.xml

BUILD FAILED
/Users/smartmind/Works/Smallthing/cocos2d-x/samples/HelloCpp/proj.android/build.xml:46: sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var

Total time: 0 seconds

我不知道问题出在哪里。

2个回答

17

你的项目应该有一个local.properties文件,其中包含一行sdk.dir,该行指向安装Android SDK的位置:

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.

# location of the SDK. This is only used by Ant
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=/opt/android-sdk-linux_x86

如需创建该文件,若不存在,请运行android update project -p ...,其中...代表您项目所在的路径。

是的,我有这个文件,是用“android update project -t android-16 -p .”创建的。#此文件由Android工具自动生成。 #不要修改此文件--您的更改将被擦除! # #此文件应检入版本控制系统, #因为它包含特定于您的本地配置的信息。#SDK的位置。这仅由Ant使用 #有关使用版本控制系统进行自定义,请阅读 #标题注释。 sdk.dir=/Users/smartmind/Works/SDK/Android/sdk - lordubik
构建失败 /Users/smartmind/Works/SDK/Android/sdk/tools/ant/build.xml:569: 在执行此行时发生以下错误: /Users/smartmind/Works/Smallthing/cocos2d-x/cocos2dx/platform/android/java/build.xml:46: 缺少sdk.dir。请确保使用'android update project'生成local.properties或通过环境变量注入它。 - lordubik
@lordubik:除了确保您使用的是最新版本的Android工具,并确保sdk.dir的值确实正确之外,我没有其他建议。 - CommonsWare
Android工具已经通过AVD Manager更新,sdk.dir已设置为Android SDK根目录。(/Works/Android/sdk) - lordubik
5
好的,使用这个语法解决了问题:ant -Dsdk.dir=$ANDROID_HOME -Dtarget=android-16 debug。无论如何,感谢您的帮助! - lordubik

14

我曾遇到同样的问题,我使用-Dvar或VM参数解决了这个问题。

ant debug -Dsdk.dir=$SDK_ROOT

$SDK_ROOT是Android SDK路径。


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