문제 설명
NDK: 자바 클래스에서 .c 상수를 사용하는 방법 (NDK: How to use .c constants in java class)
.C 파일에서 상수를 정의하고 내 클래스의 .Class 파일에서 해당 상수를 사용하려고 합니다. 어떻게 할 수 있습니까? 저는 NDK에 대해 완전히 새로운 사람입니다. 여기에 상수를 정의했습니다.
const jstring BASE_URL ="http://www.google.com";'
현재 메서드를 호출하여 해당 상수를 사용하고 있습니다.
jstring
Java_com_example_hellojni_HelloJni_variableData(JNIEnv *env) {
return (*env)‑>NewStringUTF(env, BASE_URL);
}
자바 코드에서 직접 사용하는 방법
참조 솔루션
방법 1:
Your method works. I can give you another way from my experience:
Create a custom java object with a String field and a method that returns a String.
Class Container{
private String baseUrl;
public String getBaseUrl(){
return baseUrl;
}
}
Create a Java native method and pass Container as an argument
On the side of C/C++, you can modify Container's fields here are jni funtions' reference that could help you http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html
(by curiousMind、huluyige)