NDK: 자바 클래스에서 .c 상수를 사용하는 방법 (NDK: How to use .c constants in java class)


문제 설명

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 curiousMindhuluyige)

참조 문서

  1. NDK: How to use .c constants in java class (CC BY‑SA 2.5/3.0/4.0)

#class-constants #android-ndk #java






관련 질문

NDK: 자바 클래스에서 .c 상수를 사용하는 방법 (NDK: How to use .c constants in java class)

상수 클래스 멤버, 할당 연산자 및 QList (Constant class members, assignment operator and QList)

kotlin 클래스의 상수 풀에 있는 미친 UTF-8 항목 (Crazy UTF-8 entry in a kotlin class' constant pool)

PHP 5.3 ~ PHP7 - 정의되지 않은 클래스 상수 'self::MYCONST' (PHP 5.3 to PHP7 - Undefined class constant 'self::MYCONST')

PHP의 특정 클래스에 정의된 '클래스 상수'와 함께 defined() 메서드를 사용하는 방법은 무엇입니까? (How to use defined() method with 'Class Constants' that are defined into a specific class in PHP?)

클래스 상수를 사용한 PHP 객체 액세스 (PHP Object access with class constant)

Java에서 상수 클래스를 어떻게 정의합니까? (How do you define a class of constants in Java?)







코멘트