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

Posted 苏小七

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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‘) {

   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‘
   }

}
 

以上是关于android开发里跳过的坑-AS导入NDK工程提示错误 No such property: sdkHandler for class: com.android.build.gradle.Librar的主要内容,如果未能解决你的问题,请参考以下文章

android开发里跳过的坑——button不响应点击事件

android开发里跳过的坑——图片文件上传失败

android开发里跳过的坑——GridView使用Glide加载图片不显示

Android NDK系列-AS使用javah生成so文件

Android NDK系列- AS导入so三方库,使用C/C+方法

Android NDK系列- AS导入so三方库,使用C/C+方法