Reputation: 81
I'm new to Android studio and android NDK. I'm trying to compile a simple hello.c program with android NDK for a class assignment. I've followed the following project instructions but get an error:
Create a c program
create Android.mk with following contents:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello.out
LOCAL_SRC_FILES :=hello.c
include $(BUILD_EXECUTABLE)
Create Application.mk with following content:
APP_ABI := armeabi
APP_PLATFORM := android-10
APP_STL := stlport_static
APP_BUILD_SCRITP := Android.mk
Put hello.c, Android.mk, Application.mk into same folder x.
go to folder x
run command:
export NDK_PROJECT_PATH=.
Run command
[NDK_dir]/ndk-build NDK_APPLICATION_MK=./Application.mk
the executable will be generated at ./libs/armeabi/hello.out
But I get this error when following those instructions:
/home/justin/Desktop/android-ndk-r16/build/core/add-application.mk:49: Application.mk: No such file or directory
Android NDK: APP_PLATFORM not set. Defaulting to minimum supported version android-14.
Android NDK: There is no Android.mk under ./jni
Android NDK: If this is intentional please define APP_BUILD_SCRIPT to point
Android NDK: to a valid NDK build script.
/home/justin/Desktop/android-ndk-r16/build/core/add-application.mk:116: *** Android NDK: Aborting... . Stop.
I installed android NDK components through Andoird studio SDK and my [NDK_DiR] is /home/justin/Android/Sdk/ndk-bundle
Upvotes: 3
Views: 2455
Reputation: 57173
The easy fix is to move all three files to a subdirectory called jni
. You don't need to export NDK_PROJECT_PATH, and your command will look like
<path-to/>ndk-build -C <path-to/>x/jni
If you need to avoid jni
directory at any price, try
<path-to/>ndk-build NDK_PROJECT_PATH=<path-to/>x NDK_APPLICATION_MK=<path-to/>x/Application.mk APP_BUILD_SCRIPT=<path-to/>x/Android.mk
which is almost equivalent to
<path-to/>ndk-build -C <path-to/>x NDK_PROJECT_PATH=. NDK_APPLICATION_MK=Application.mk APP_BUILD_SCRIPT=Android.mk
Upvotes: 1