首先,我必须承认我对 android 和 ndk 有相当的经验,但是 gradle scripts 对我来说是一个新话题。我正在开发一个已经编写了 gradle 脚本的项目(这不是我的部分)并且工作正常。
我的问题是一个特定的任务似乎没有找到属性定义的 ndk.dir,它是在 local.properties 文件中定义的。
项目结构是(简化):
_ <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异常而出现错误。
有人可以帮忙吗?你能告诉我是否可以调试它吗?
提前致谢。如有必要,请随时询问额外信息。
最佳答案
这对我有用:
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了解详情。
关于android - Gradle 任务找不到 local.properties 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28222158/