I want to make an Android application that uses NDK with C ++
I made a new Android solution in Xamarin Studio called ndkTest. I added the jni folder and these files are added there:
- Android.mk
- Application.mk
- my.h
- test.cpp
Here are the contents of each of them:
Android.mk :
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ndkTest
LOCAL_SRC_FILES := test.cpp
LOCAL_STATIC_LIBRARIES := my
include $(BUILD_SHARED_LIBRARY)
Application.mk :
APP_ABI := armeabi-v7a
APP_STL := stlport_static
my.h :
#ifndef __MY_H__
#define __MY_H__
#define MY_CONST 1
#ifdef __cplusplus
extern "C"
#endif
short
my_func( short my_param );
#endif
test.cpp
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <iostream>
#include <fstream>
#include <vector>
#include "my.h"
#define SOME_CONST 2*MY_CONST
short some_short;
#ifdef __cplusplus
extern "C"
{
#endif
static void static_func_0()
{
some_short = 0;
}
static void static_func_1()
{
some_short = 1;
}
#ifdef __cplusplus
}
#endif
static void static_print()
{
printf("static_print\n");
printf("some_short = %d\n", some_short);
}
extern "C" short getSomeShort()
{
printf("myExtern\n");
return some_short;
}
Here, where it gets interesting: I have ndk installed and configured correctly. At the command prompt, I connected to the project directory and ran
ndk-build
And I get this error:
make.exe: *** No rule to make target [path to ndk]/sources/cxx-stl/stlport/test.cpp', needed byobj/local/armeabi/objs/ndkTest/test.o'. Stop.
This is strange, but I can specify the full path to test.cpp in Android.mk, and it creates:
[armeabi] Compile++ thumb: ndkTest <= test.cpp
[armeabi] SharedLibrary : libndkTest.so
[armeabi] Install : libndkTest.so => libs/armeabi/libndkTest.so
So now I have a .so file. After adding this to the beginning of MainActivity.cs: using System.Runtime.InteropServices;I added the following:
[DllImport("libndkTest", EntryPoint="getSomeShort")]
static extern short getSomeShort();
OnCreate. DllNotFoundException.
?