【问题标题】:Gradle task unable to find local.properties fileGradle 任务找不到 local.properties 文件
【发布时间】:2015-03-29 02:50:14
【问题描述】:

首先,我不得不承认我对android和ndk有相当的经验,但是gradle scripts对我来说是一个新话题。我正在开发一个已经编写好 gradle 脚本的项目(这不是我的工作)并且工作正常。

我的问题是某个特定任务似乎找不到定义在 local.properties 文件中的属性定义的 ndk.dir。

项目结构为(简化):

_ <project_root>
|_ <sub_project folder>
    ...
    |_ main
    |_ build.gradle
    |_ local.properties
|_ ...

local.properties 文件如下所示:

ndk.dir=/home/ubuntu/dev/android-ndk-r9c

任务的问题部分,定义在结构的 build.gradle 文件中,如下:

task buildNDKFlavorGooglePlayStore(type: Exec) {
    if (project.ext.has('ndk.dir') && (project.ext.get('ndk.dir') != null)) {
        ext.ndkBuild = new File((String)project.ext.get('ndk.dir'), 'ndk-build')
        executable ndkBuild
    } else {
        throw new GradleException('Reason: ndk.dir is missing in ' + projectDir + '/local.properties')
    }
(...)
}

同步项目时,由于定义了gradle异常而出现错误。

有人可以帮忙吗?你能告诉我是否可以调试它吗?

提前谢谢你。如有必要,请随时询问额外信息。

【问题讨论】:

  • 你试过gradle.properties而不是local.properties吗?

标签: android groovy gradle android-ndk


【解决方案1】:

这对我有用:

def getNdkDir() {
    if (System.env.ANDROID_NDK_ROOT != null)
        return System.env.ANDROID_NDK_ROOT

    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    def ndkdir = properties.getProperty('ndk.dir', null)
    if (ndkdir == null)
        throw new GradleException("NDK location not found. Define location with ndk.dir in the local.properties file or with an ANDROID_NDK_ROOT environment variable.")

    return ndkdir
}

def getNdkBuildCmd() {
    def ndkbuild = getNdkDir() + "/ndk-build"
    if (Os.isFamily(Os.FAMILY_WINDOWS))
        ndkbuild += ".cmd"

    return ndkbuild
}

查看here了解详情。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-29
    • 1970-01-01
    • 1970-01-01
    • 2017-12-24
    • 2020-01-25
    • 2016-07-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多