从NDK代码读取构建参数 [英] Read build arguments from NDK code
本文介绍了从NDK代码读取构建参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个NDK文件,可将我的api密钥注入我的应用程序,代码可以正常工作:
I have an NDK file that inject my api key into my app, the code works correctly:
#include <jni.h>
JNIEXPORT jstring JNICALL
Java_yt_javi_nftweets_ui_main_MainActivity_getTwitterKey(JNIEnv *env, jobject instance) {
return (*env)-> NewStringUTF(env, "my_twitter_key");
}
我想通过自定义构建参数更改 my_twitter_key
I would like to change my_twitter_key by an custom build argument
externalNativeBuild {
ndkBuild {
arguments "-DTWITTER_API_KEY=my_twitter_key"
}
}
并在方法 Java_yt_javi_nftweets_ui_main_MainActivity_getTwitterKey
推荐答案
You could add a define to your cFlags
and stringify it in your C code:
android {
defaultConfig {
externalNativeBuild {
ndkBuild {
cFlags "-DTWITTER_API_KEY=my_twitter_key"
}
}
}
}
#define xstr(s) str(s)
#define str(s) #s
...
return (*env)->NewStringUTF(env, xstr(TWITTER_API_KEY));
这篇关于从NDK代码读取构建参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文