首页 > 代码库 > Android Studio编译开源项目(含NDK开发)常见报错

Android Studio编译开源项目(含NDK开发)常见报错

1.未设置NDK的路径

Error:Execution failed for task ‘:library:ndkBuild‘. > A problem occurred starting process ‘command ‘null/ndk-build‘‘
配置NDK的的安装路径即可。
1)设置环境变量:新增ANDROID_NDK_HOME键值为Android NDK安装目录,在PATH末尾增加;%ANDROID_NDK_HOME%

或者2)在AS的project structure设置,如下图:

技术分享

 

2. 调用的ndk-build命令不对

Error:Execution failed for task ‘:library:ndkBuild‘.> A problem occurred starting process ‘command ‘D:\androidDev\android-ndk-r10e/ndk-build‘‘

在stackoverflow上找到原因,build.gradle文件中

taskndkBuild(type: Exec,description:‘Compile JNI source via NDK‘) {
    defndkDir =project.plugins.findPlugin(‘com.android.library‘).sdkHandler.ndkFolder
    workingDir"$projectDir/src/main/jni"
    commandLine"$ndkDir/ndk-build"
}

  

commandLine"$ndkDir/ndk-build"这一行windows下应该用ndk-build.cmd(项目中有遇到)

3. 找不到boost库文件

项目Readme中有说明

Manual Build
Make sure$ANDROID_NDK_HOMEis correctly set to the root directory of your NDK installation. Also, if Boost lives in a non-standard directory (or you‘re on Windows) you‘ll need to set$BYPASS_INCLUDE_PATH to its parent directory.

  

设置环境变量:新增BYPASS_INCLUDE_PATH键值为boost的安装目录,在PATH末尾增加;%BYPASS_INCLUDE_PATH%

Android Studio编译开源项目(含NDK开发)常见报错