最近在使用NDK编译JNA接口时报错:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
> Task :app:ndkBuild FAILED
D:/MyDevEnv/Android-SDK/ndk/21.4.7075529/build//../build/core/add-application.mk:88: *** Android NDK: Aborting... . Stop.
make: Entering directory 'D:/MyWork/jasmine-android/app/src/main'
Android NDK: APP_PLATFORM not set. Defaulting to minimum supported version android-16.
Android NDK: WARNING: APP_PLATFORM android-16 is higher than android:minSdkVersion 1 in ./AndroidManifest.xml. NDK binaries will *not* be compatible with devices older than android-16. See https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md for more information.
Android NDK: Your APP_BUILD_SCRIPT points to an unknown file: ./jni/Android.mk
make: Leaving directory 'D:/MyWork/jasmine-android/app/src/main'

Execution failed for task ':app:ndkBuild'.
> Process 'command 'D:\MyDevEnv\Android-SDK\ndk\21.4.7075529/ndk-build.cmd'' finished with non-zero exit value 2

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

分析一下输出结果,除了对未指定编译平台的警告,重要的原因是APP_BUILD_SCRIPT指向了一个未知的Android.mk文件。

首先检查了一下gradle文件,发现原来是配置的问题,从Android.mk迁移至CMakeLists.txt时有一些跟MakeFile有关的配置没有完全删除掉,修改配置后问题得到解决。