最后我解决了。这是我的cpp文件代码
Java_com_de_demo_ndk2_MainActivity_stringFromJNI( JNIEnv *env, jobject jobject1, jstring jstring1) { std::string hello; const char *nativeString1 = env->GetStringUTFChars( jstring1, 0); if (strcmp(nativeString1, "demo") == 0) { hello = "Hello from demo C++"; } else if (strcmp(nativeString1, "live") == 0) { hello = "Hello from live C++"; } return env->NewStringUTF(hello.c_str());}我从Java代码传递风味值,这是我的Java文件代码。
public class MainActivity extends AppCompatActivity { // Used to load the 'native-lib' library on application startup. static { System.loadLibrary("native-lib"); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Example of a call to a native method TextView tv = (TextView) findViewById(R.id.sample_text); String value = BuildConfig.FLAVOR; String ndkValue = stringFromJNI(value); tv.setText(ndkValue); } public native String stringFromJNI(String value);}现在,我可以根据选定的口味获取想要的任何文本。



