我安装NDK并在“项目结构”中设置NDK路径:
并将以下代码添加到build.gradle:
task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build.cmd",
'-C', file('jni').absolutePath, // Change src/main/jni the relative path to your jni source
'-j', Runtime.runtime.availableProcessors(),
'all',
'NDK_DEBUG=1'
}
task cleanNative(type: Exec, description: 'Clean JNI object files') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build.cmd",
'-C', file('jni').absolutePath, // Change src/main/jni the relative path to your jni source
'clean'
}
clean.dependsOn 'cleanNative'
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn buildNative
}
并将此代码添加到build.gradle中的“defauilConfig”:
ndk {
moduleName "TMessagesProj"
}
当我尝试构建APK时,我收到此错误:
错误:任务执行失败':TMessagesProj:buildNative'。 进程'命令'C:\ Users \ Mehran \ AppData \ Local \ Android \ ndk \ android-ndk-r12 / ndk-build.cmd''以非零退出值2完成
这是消息控制台:
make(e = 2):系统找不到指定的文件。 make:*** [D:/Mehran/AndroidStudioProjects/TelegramTest/TMessagesProj/obj/local/armeabi/objs-debug/tmessages.22 /./ opus / src / opus_encoder.o]错误2 make:离开目录`D:/ Mehran / AndroidStudioProjects / TelegramTest / TMessagesProj / jni'
抱歉我的英语不好。