In my Android App I want to protecte some static strings from being read by decomnpiling the application. I read that a way to do so is to put them into c++ code and load them natively into the Android project.
so I created a c++ file and a CMake script. The c++ file:
#include <jni.h>
#include <string>
extern "C"
JNIEXPORT jstring JNICALL
Java_package_name_NdkUtils_methodForStringToBeProtected(
JNIEnv *env, jobject /* this */) {
std::string result = "secretStaticStringHere";
return env->NewStringUTF(result.c_str());
}
and the CMakeLists.txt:
cmake_minimum_required(VERSION 3.4.1)
add_library(native-lib SHARED src/main/cpp/native-lib.cpp )
find_library( og-lib log )
target_link_libraries( native-lib ${log-lib} )
In Android now I suceeded getting that string within the native call. What I want to get is that the c++ is hidden from the built. I only want to include the so files.
So I went into the genrated apk and I was able to extract the libnative-lib.so file. I integrated the so-files in the aap/src/main/jniLibs folder. But when I remove the c++ sources I cannot access the methodForStringToBeProtected-method anymore. What do I have to do now to call the function only from within the so-file?