【问题标题】:bash script not reading local.propertiesbash 脚本未读取 local.properties
【发布时间】:2015-02-19 18:54:17
【问题描述】:

我创建了一个基于官方 Cocos2dx 示例的项目。在脚本中,它尝试使用以下内容读取本地属性:

_LOCALPROPERTIES_FILE=$(dirname "$0")"/local.properties"
if [ -f "$_LOCALPROPERTIES_FILE" ]
then
    [ -r "$_LOCALPROPERTIES_FILE" ] || die "Fatal Error: $_LOCALPROPERTIES_FILE exists but is unreadable"

    # strip out entries with a "." because Bash cannot process variables with a "."
    _PROPERTIES=`sed '/\./d' "$_LOCALPROPERTIES_FILE"`
    for line in "$_PROPERTIES"; do
        declare "$line";
        echo "$line";
    done
fi

然后它会尝试获取 NDK_ROOT:

if [ -z "${NDK_ROOT+aaa}" ];then
echo "NDK_ROOT not defined. Please define NDK_ROOT in your environment or in local.properties"
exit 1
fi

如果我在 local.properties 中定义 NDK 根,如下所示:

NDK_ROOT=/Users/myuser/Documents/android-ndk-r9d

它无法识别该属性,尽管我确实在控制台中看到了这一行。为什么这个脚本无法将 local.properties 读入变量?这是脚本中的错误还是我如何定义我的属性?我怀疑脚本不正确。我知道我可以定义环境变量,但我真的很想将这些变量保存在我的 local.properties 中,而不是弄乱人们的 bash 配置文件。

【问题讨论】:

    标签: java android bash cocos2d-x


    【解决方案1】:

    local.properties 旨在由构建系统(ant 或其他)读取以传递构建的键值对 (http://ant.apache.org/manual/properties.html)不是外壳环境。此外,local.properties 不应该被修改,因为它是由 Android 构建系统生成的。

    您可能想要定义一个 custom_rules.xml 文件来实现您想做的事情。这个线程Android custom build using Ant 可能会有所帮助。

    【讨论】:

    • shell 环境可能是构建系统的一部分,Cocos2dx 构建就是这种情况。
    • 您是用 ant、eclipse、gradle 还是其他方式构建的?
    猜你喜欢
    • 1970-01-01
    • 2014-10-26
    • 2012-11-18
    • 2012-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-05-30
    • 2014-10-28
    相关资源
    最近更新 更多