更新时间:2023-10-15 22:54:40
注意:如果您已经创建了项目,然后又通过SDK Tools安装了Android NDK,CMake和LLDB,则您的项目可能无法构建,即您将获得一个进行项目时出错.
Note: If you already created project and after that you are installing Android NDK, CMake and LLDB through SDK Tools then your project might not build i.e you will get an error while Make Project.
请遵循以下步骤:
在应用级别的 build.gradle
文件中.
在您的 apply插件之前添加以下行:...
import org.apache.tools.ant.taskdefs.condition.Os
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkDir = properties.getProperty('ndk.dir')
添加 android
-> defaultConfig
externalNativeBuild {cmake {cppFlags"-frtti -fexceptions"}}
externalNativeBuild{ cmake{ cppFlags "-frtti -fexceptions" } }
在 buildTypes {}
标记
externalNativeBuild {cmake {路径"CMakeLists.txt"}}任务ndkBuild(type:Exec){如果(Os.isFamily(Os.FAMILY_WINDOWS)){命令行ndkDir +'/ndk-build.cmd','-C',file('src/main').absolutePath} 别的 {命令行ndkDir +'/ndk-build','-C',file('src/main').absolutePath}}
externalNativeBuild { cmake { path "CMakeLists.txt" } } task ndkBuild(type: Exec) { if (Os.isFamily(Os.FAMILY_WINDOWS)) { commandLine ndkDir + '/ndk-build.cmd', '-C', file('src/main').absolutePath } else { commandLine ndkDir + '/ndk-build', '-C', file('src/main').absolutePath } }
tasks.withType(JavaCompile){compileTask-> compileTask.dependsOn ndkBuild}
tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn ndkBuild }
希望它对您有帮助.!!
Hope it helps you. !!