我安装了 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
}
并将此代码添加到“ defauilConfig
”中build.gradle
:
ndk {
moduleName "TMessagesProj"
}
当我尝试构建 APK 时,出现此错误:
错误:任务“:TMessagesProj:buildNative”执行失败。Process 'command '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'
对不起,我的英语不好。