Я пытаюсь создать покерное приложение с JNI в студии android, я хочу сохранить один экземпляр класса c ++ (TexasHoldem) и вызывать только его методы. в texasJNI. java я написал:
public class jniTexasHoldem {
private long texasHoldm;
jniTexasHoldem() {
ConstructNativeTexas();
}
// Used to load the 'native-lib' library on application startup.
static {
System.loadLibrary("native-lib");
}
/**
* A native method that is implemented by the 'native-lib' native library,
* which is packaged with this application.
*/
private native void ConstructNativeTexas();
public native String getCardXML();
public native String stringFromJNI();
}
в mainActivity:
ublic class MainActivity extends AppCompatActivity {
private jniTexasHoldem m_TexasHoldem = new jniTexasHoldem();
...
String cardXml = m_TexasHoldem.getCardXML();
}
и в native-lib:
extern "C"
JNIEXPORT jstring JNICALL
Java_android_myapplication_jniTexasHoldem_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}
extern "C"
JNIEXPORT jlong JNICALL
Java_android_myapplication_jniTexasHoldem_ConstructNativeTexas(JNIEnv *env, jobject thiz) {
TexasHoldm* texasHoldmObj = new TexasHoldm();
return (jlong)texasHoldmObj;
}
extern "C"
JNIEXPORT jstring JNICALL
Java_android_myapplication_jniTexasHoldem_getCardXML(JNIEnv *env, jobject thiz) {
jclass c = env->GetObjectClass(thiz);
// J is the type signature for long:
jfieldID fid_handle = env->GetFieldID(c, "texasHoldm", "J");
TexasHoldm * nativeObject = (TexasHoldm *) env->GetLongField(thiz, fid_handle);
return (env)->NewStringUTF(nativeObject->getCard().c_str());
}
Я ожидаю получить строка {card} .png, которая автоматически генерируется из метода getCard
, но не компилируется из-за undefined reference to 'TexasHoldm::getCard()'
my build.gradle:
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
ndkVersion "21.1.6352462"
и в CmakeList I писал (а):
target_link_libraries( # Specifies the target library.
native-lib
TexasHoldm.h
TexasHoldm.cpp
PokerTable.h
PokerTable.cpp
Player.h
Player.cpp
Hand.h
Hand.cpp
Card.h
Card.cpp
# Links the target library to the log library
# included in the NDK.
${log-lib} )