android - 使用ant构建android项目时如何解决 'sdk.dir is missing'错误

标签 android ubuntu ant sdk build.xml

当我在窗口的命令行中创建 build.xml 时,(android update project -p . -n myapp ),然后“init”、“clean”和“build”目标名称基本上是在 build.xml 中创建的.

但是在ubuntu中创建build.xml时,

在build.xml代码之后,缺少sdk.dir。

<!-- The local.properties file is created and updated by the 'android' tool.
     It contains the path to the SDK. It should *NOT* be checked into
     Version Control Systems. -->
<property file="local.properties" />

<!-- The ant.properties file can be created by you. It is only edited by the
     'android' tool to add properties to it.
     This is the place to change some Ant specific build properties.
     Here are some properties you may want to change/update:

     source.dir
         The name of the source directory. Default is 'src'.
     out.dir
         The name of the output directory. Default is 'bin'.

     For other overridable properties, look at the beginning of the rules
     files in the SDK, at tools/ant/build.xml

     Properties related to the SDK location or the project target should
     be updated using the 'android' tool with the 'update' action.

     This file is an integral part of the build system for your
     application and should be checked into Version Control Systems.

     -->
<property file="ant.properties" />

<!-- if sdk.dir was not set from one of the property file, then
     get it from the ANDROID_HOME env var.
     This must be done before we load project.properties since
     the proguard config can use sdk.dir -->
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
    <isset property="env.ANDROID_HOME" />
</condition>

<!-- The project.properties file is created and updated by the 'android'
     tool, as well as ADT.

     This contains project specific properties such as project target, and library
     dependencies. Lower level build properties are stored in ant.properties
     (or in .classpath for Eclipse projects).

     This file is an integral part of the build system for your
     application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />

<!-- quick check on sdk.dir -->
<fail
        message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
        unless="sdk.dir"
/>

<!--
    Import per project custom build rules if present at the root of the project.
    This is the place to put custom intermediary targets such as:
        -pre-build
        -pre-compile
        -post-compile (This is typically used for code obfuscation.
                       Compiled code location: ${out.classes.absolute.dir}
                       If this is not done in place, override ${out.dex.input.absolute.dir})
        -post-package
        -post-build
        -pre-clean
-->
<import file="custom_rules.xml" optional="true" />

<!-- Import the actual build file.

     To customize existing targets, there are two options:
     - Customize only one target:
         - copy/paste the target into this file, *before* the
           <import> task.
         - customize it to your needs.
     - Customize the whole content of build.xml
         - copy/paste the content of the rules files (minus the top node)
           into this file, replacing the <import> task.
         - customize to your needs.

     ***********************
     ****** IMPORTANT ******
     ***********************
     In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
     in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />

虽然 'command': 'ant clean' 和 'ant release' 效果很好,

我还想自动创建基本的 build.xml,包括“init”、“clean”和“build”目标名称。

此外,ANDROID_HOME 和 PATH 已经设置好了。

js@js-W65-67SH:~$ echo $ANDROID_HOME
/opt/android-sdk-linux
js@js-W65-67SH:~$ 
js@js-W65-67SH:~$ echo $PATH
/home/js/.nvm/versions/node/v0.12.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/android-sdk-linux/tools:/opt/android-sdk-linux/platform_tools

本地.properties

# 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

我不知道如何解决这个问题。

请帮我解决这个问题。

最佳答案

请仔细检查您的构建箱中是否下载了 Android SDK。在你的例子中,看起来它在/opt/android-sdk-linux 中寻找 SDK。因此,请确保它在那里可用。

转到 Jenkins > 管理 Jenkins > 配置系统 检查“环境变量” 添加名称:ANDROID_HOME,值 -> 你的 Android SDK 在 jenkins build box 上的位置

点击保存。

再次构建作业。将生成一个 local.properties 文件,其中填充了 sdk.dir 字段。

关于android - 使用ant构建android项目时如何解决 'sdk.dir is missing'错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28557766/

相关文章:

java - 在 Android 上创建自己的键盘

Android 计费测试 - 如何与测试用户进行测试?

python-3.x - 在浏览器中打开 Visual Studio Code

linux - Linux 上已安装程序的文件位置有什么意义?

android - 谷歌地图 API 代码不工作。请帮我

android - 在Ionic 1中构建android时无法合并Dex

MySQl 5.7 在 Ubuntu 16.04 上安装失败

调用 JDeveloper 以创建具有指定部署文件的 EAR 文件的 ANT 作业

java - ant 到 maven 迁移 maven - jar 构建

javascript - 如何从 ant build.xml 中调用 jasmine-node