从 NDK 代码中读取构建参数 [英] Read build arguments from NDK code
本文介绍了从 NDK 代码中读取构建参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个将我的 api 密钥注入我的应用程序的 NDK 文件,代码可以正常工作:
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 方法中读取该参数
推荐答案
您可以在 cFlags
和 stringify it 在你的 C 代码中:
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屋!
查看全文