Ndk-Bridge is desgined for simplifying ndk to java calls.
you can easily to call java methods in your native apps like game-engine;
#include <jni.h>
#include <string>
#include "NativeContext.h"
#include "java/security/MessageDigest.h"
auto getSignature(JNIEnv *env, jobject8 /* this */thiz) -> std::string {
NativeContext context(thiz,env);
const char hexcode[] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };
std::string package = context.getPackageName();
auto & pm = context.getPackageManager();
auto & info = pm->getPackageInfo(package);
auto & sign = info->signatures[0];
std::vector<int8_t> array = sign.toByteArray();
std::vector<int8_t> publicKey = MessageDigest::getInstance(env,"SHA1").digest(array);
std::string sha;
for(auto a : publicKey){
sha.append(1,hexcode[((unsigned char)a) / 16]);
sha.append(1, hexcode[((unsigned char)a) % 16]);
sha.append(":");
}
return sha;
}
auto getImei(JNIEnv *env, jobject /* this */thiz) -> std::string
{
NativeContext context(thiz, env);
return context.getTelephonyManager()->getDeviceId();
}
- add include file in your code
#include <NativeBridge.h>
- add LOCAL_STATIC_LIBRARIES in you app Android.mk
LOCAL_STATIC_LIBRARIES := .... ndk_bridge
- add import module at last ine in you app Android.mk
$(call import-module,ndk_bridge)
- build it
call ndk-build
it will be supported in the next version