我的设定为流动:
1.app/build.gradle
defaultConfig {
applicationId "demo.kid.com.testjni"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
ndk {
moduleName "helloNDK"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
2.i添加此" android.useDeprecatedNdk = true"在" gradle.properties"
3. NDK路径也设置正确
4.c ++源代码
JNIEXPORT jstring JNICALL
Java_demo_kid_com_testjni_MainActivity_getStringFromNative
(JNIEnv *env, jobject){
return env->NewStringUTF("Hello World From the JNI!");
}
5. MainActivity使用:
static {
System.loadLibrary("helloNDK");
}
public native String getStringFromNative();
6. eroor信息:
process_begin: CreateProcess(NULL, D:/C/IT/android_studio/some/NDK/android-ndk-r11b-windows-x86/android-ndk-r11b/build//../toolchains/aarch64-linux-android-4.9/prebuilt/windows-x86_64/bin/aarch64-linux-android-gcc -MMD -MP -MF D:\C\IT\android_studio\Model\M_testJNI\TestJNI\app\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/helloNDK/D_\C\IT\android_studio\Model\M_testJNI\TestJNI\app\src\main\jni\helloNDK.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -O2 -g -DNDEBUG -fomit-frame-pointer -fstrict-aliasing -funswitch-loops -finline-limit=300 -ID:\C\IT\android_studio\Model\M_testJNI\TestJNI\app\src\main\jni -ID:\C\IT\android_studio\Model\M_testJNI\TestJNI\app\src\debug\jni -ID:/C/IT/android_studio/Model/M_testJNI/TestJNI/app/build/intermediates/ndk/debug -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security -isystem D:/C/IT/android_studio/some/NDK/android-ndk-r11b-windows-x86/android-ndk-r11b/build//../platforms/android-23/arch-arm64/usr/include -c D:\C\IT\android_studio\Model\M_testJNI\TestJNI\app\src\main\jni\helloNDK.c -o D:\C\IT\android_studio\Model\M_testJNI\TestJNI\app\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/helloNDK/D_\C\IT\android_studio\Model\M_testJNI\TestJNI\app\src\main\jni\helloNDK.o, ...) failed.
make (e=2): 系统找不到指定的文件。
make: *** [D:\C\IT\android_studio\Model\M_testJNI\TestJNI\app\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/helloNDK/D_\C\IT\android_studio\Model\M_testJNI\TestJNI\app\src\main\jni\helloNDK.o] Error 2
Error:Execution failed for task ':app:compileDebugNdk'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'D:\C\IT\android_studio\some\NDK\android-ndk-r11b-windows-x86\android-ndk-r11b\ndk-build.cmd'' finished with non-zero exit value 2