I installed NDK and set the NDK path in "Project Structure" :
And then I added below codes to 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
}
And add this code to "defauilConfig
" in build.gradle
:
ndk {
moduleName "TMessagesProj"
}
When I try to build an APK , I get this error :
Error:Execution failed for task ':TMessagesProj:buildNative'. Process 'command 'C:\Users\Mehran\AppData\Local\Android\ndk\android-ndk-r12/ndk-build.cmd'' finished with non-zero exit value 2
This is the Messages Console :
make (e=2): The system cannot find the file specified. make: *** [D:/Mehran/AndroidStudioProjects/TelegramTest/TMessagesProj/obj/local/armeabi/objs-debug/tmessages.22/./opus/src/opus_encoder.o] Error 2 make: Leaving directory `D:/Mehran/AndroidStudioProjects/TelegramTest/TMessagesProj/jni'
Sorry for my bad English.