android开发里跳过的坑-AS导入NDK工程提示错误 No such property: sdkHandler for class: com.android.build.gradle.Librar

冲天香阵透长安,满城尽带黄金甲。这篇文章主要讲述android开发里跳过的坑-AS导入NDK工程提示错误 No such property: sdkHandler for class: com.android.build.gradle.Librar相关的知识,希望能为你提供帮助。
接到一个NDK工程需要调试,导入后发现总是提示错误
Error:(37, 1) A problem occurred evaluating project ‘:libuvccamera‘.
> No such property: sdkHandler for class: com.android.build.gradle.LibraryPlugin
百度上各种说法,有说要降低gadle版本,有说要在环境变量里配置ANDROID_NDK的路径,试验了都不行,最后参考别人NDK gradle文件修改如下:
未修改之前:
task ndkBuild(type: Exec, description: ‘Compile JNI source via NDK‘) {
【android开发里跳过的坑-AS导入NDK工程提示错误 No such property: sdkHandler for class: com.android.build.gradle.Librar】    println(‘executing ndkBuild‘)
    def ndkBuildingDir = project.plugins.findPlugin(‘com.android.library‘).sdkHandler.getNdkFolder().absolutePath
    def ndkBuildPath = ndkBuildingDir
  if (Os.isFamily(Os.FAMILY_WINDOWS)){
    ndkBuildPath = ndkBuildingDir + ‘/ndk-build.cmd‘

} else {
ndkBuildPath = ndkBuildingDir + ‘/ndk-build‘
}
commandLine ndkBuildPath, ‘-j8‘, ‘-C‘, file(‘src/main‘).absolutePath
}

可修改为

task ndkBuild(type: Exec, description: ‘Compile JNI source via NDK‘) {
println(‘executing ndkBuild‘)
def ndkBuildingDir = android.ndkDirectory
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
ndkBuildingDir = "$ndkBuildingDir/ndk-build.cmd"
} else {
ndkBuildingDir = "$ndkBuildingDir/ndk-build"
}
commandLine ndkBuildingDir, ‘-j8‘, ‘-C‘, file(‘src/main‘).absolutePath
}

或者修改为
task ndkBuild(type: Exec, description: ‘Compile JNI source via NDK‘) {

println(‘executing ndkBuild‘)

//def ndkBuildingDir = project.plugins.findPlugin(‘com.android.library‘).sdkHandler.getNdkFolder().absolutePath
//def ndkBuildPath = ndkBuildingDir
def ndkBuildPath = android.ndkDirectory
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine "$ndkBuildPath/ndk-build.cmd",
‘-C‘, file(‘src/main‘).absolutePath, // Change src/main/jni the relative path to your jni source
‘-j‘, Runtime.runtime.availableProcessors(),
‘all‘,
‘NDK_DEBUG=1‘
} else {
commandLine "$ndkBuildPath/ndk-build",

‘-C‘, file(‘src/main‘).absolutePath, // Change src/main/jni the relative path to your jni source
‘-j‘, Runtime.runtime.availableProcessors(),
‘all‘,
‘NDK_DEBUG=1‘

}

}

 


    推荐阅读