Jestem nowy na Androida. Mam podstawowe hello-world natywną funkcję kodu:Używanie plików .so w Androidzie Studio
#include <string.h>
#include <jni.h>
#include <cassert>
#include <string>
#include <iostream>
#include <fromhere.h>
using namespace std;
/* This is a trivial JNI example.
* The string returned can be used by java code*/
extern "C"{
JNIEXPORT jstring JNICALL
Java_com_example_hellojni_HelloJni_stringFromJNI(JNIEnv* env, jobject thiz)
{
#if defined(__arm__)
#if defined(__ARM_ARCH_7A__)
#if defined(__ARM_NEON__)
#if defined(__ARM_PCS_VFP)
#define ABI "armeabi-v7a/NEON (hard-float)"
#else
#define ABI "armeabi-v7a/NEON"
#endif
#else
#if defined(__ARM_PCS_VFP)
#define ABI "armeabi-v7a (hard-float)"
#else
#define ABI "armeabi-v7a"
#endif
#endif
#else
#define ABI "armeabi"
#endif
#elif defined(__i386__)
#define ABI "x86"
#elif defined(__x86_64__)
#define ABI "x86_64"
#elif defined(__mips64) /* mips64el-* toolchain defines __mips__ too */
#define ABI "mips64"
#elif defined(__mips__)
#define ABI "mips"
#elif defined(__aarch64__)
#define ABI "arm64-v8a"
#else
#define ABI "unknown"
#endif
string s = returnit();
jstring retval = env->NewStringUTF(s.c_str());
return retval;
}
}
Teraz, gdy piszę fromhere.cpp następująco:
#include <string>
using namespace std;
string returnit()
{
string s="Hello World";
return s;
}
mogę zawierać fromhere.h pisząc fromhere.h plik i zadeklarowanie returnit w tym i włączenie nazwy powyższego pliku w LOCAL_SRC_FILES Android.mk i "Hello World" pojawia się w widoku tekstowym zrobionym z klasy java.
Ale chcę skompilować te pliki fromhere.cpp i fromhere.h jako wstępnie skompilowany .so plik ny ndk i użyj funkcji returnit() z niego. Czy ktoś może mi wyjaśnić krok po kroku, jak to zrobić w Androidzie Studio, aby być konkretnym?
Proszę, popraw mnie, jeśli wypowiedziałem jakieś bzdury.