diff --git a/native/cocos/network/CCDownloader-android.cpp b/native/cocos/network/CCDownloader-android.cpp index f4db4ba032..09be4eb42f 100644 --- a/native/cocos/network/CCDownloader-android.cpp +++ b/native/cocos/network/CCDownloader-android.cpp @@ -34,6 +34,11 @@ #define JARG_STR "Ljava/lang/String;" #define JARG_DOWNLOADER "L" JCLS_DOWNLOADER ";" +#ifndef ORG_DOWNLOADER_CLASS_NAME +#define ORG_DOWNLOADER_CLASS_NAME org_cocos2dx_lib_Cocos2dxDownloader +#endif +#define JNI_DOWNLOADER(FUNC) JNI_METHOD1(ORG_DOWNLOADER_CLASS_NAME,FUNC) + std::unordered_map sDownloaderMap; std::mutex sDownloaderMutex; @@ -254,7 +259,7 @@ namespace cocos2d { namespace network { extern "C" { -JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxDownloader_nativeOnProgress(JNIEnv *env, jclass clazz, jint id, jint taskId, jlong dl, jlong dlnow, jlong dltotal) +JNIEXPORT void JNICALL JNI_DOWNLOADER(nativeOnProgress)(JNIEnv *env, jclass clazz, jint id, jint taskId, jlong dl, jlong dlnow, jlong dltotal) { DLLOG("_nativeOnProgress(id: %d, taskId: %d, dl: %lld, dlnow: %lld, dltotal: %lld)", id, taskId, dl, dlnow, dltotal); //It's not thread-safe here, use thread-safe method instead @@ -267,7 +272,7 @@ JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxDownloader_nativeOnProgress downloader->_onProcess((int)taskId, (int64_t)dl, (int64_t)dlnow, (int64_t)dltotal); } -JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxDownloader_nativeOnFinish(JNIEnv *env, jclass clazz, jint id, jint taskId, jint errCode, jstring errStr, jbyteArray data) +JNIEXPORT void JNICALL JNI_DOWNLOADER(nativeOnFinish)(JNIEnv *env, jclass clazz, jint id, jint taskId, jint errCode, jstring errStr, jbyteArray data) { DLLOG("_nativeOnFinish(id: %d, taskId: %d)", id, taskId); //It's not thread-safe here, use thread-safe method instead diff --git a/native/cocos/platform/android/jni/JniHelper.h b/native/cocos/platform/android/jni/JniHelper.h index 1f0e12aaa7..af6d95a08c 100644 --- a/native/cocos/platform/android/jni/JniHelper.h +++ b/native/cocos/platform/android/jni/JniHelper.h @@ -34,6 +34,10 @@ THE SOFTWARE. #include "base/ccMacros.h" #include "math/Vec3.h" +//The macro must be used this way to find the native method. The principle is not well understood. +#define JNI_METHOD2(CLASS2,FUNC2) Java_##CLASS2##_##FUNC2 +#define JNI_METHOD1(CLASS1,FUNC1) JNI_METHOD2(CLASS1,FUNC1) + NS_CC_BEGIN typedef struct JniMethodInfo_ diff --git a/native/cocos/platform/android/jni/JniImp.cpp b/native/cocos/platform/android/jni/JniImp.cpp index 178753bd40..ebae6c0220 100644 --- a/native/cocos/platform/android/jni/JniImp.cpp +++ b/native/cocos/platform/android/jni/JniImp.cpp @@ -40,6 +40,26 @@ #define JNI_IMP_LOG_TAG "JniImp" #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,JNI_IMP_LOG_TAG,__VA_ARGS__) +#ifndef ORG_RENDER_CLASS_NAME +#define ORG_RENDER_CLASS_NAME org_cocos2dx_lib_Cocos2dxRenderer +#endif +#define JNI_RENDER(FUNC) JNI_METHOD1(ORG_RENDER_CLASS_NAME,FUNC) + +#ifndef ORG_ACCELEROMETER_CLASS_NAME +#define ORG_ACCELEROMETER_CLASS_NAME org_cocos2dx_lib_Cocos2dxAccelerometer +#endif +#define JNI_ACCELEROMETER(FUNC) JNI_METHOD1(ORG_ACCELEROMETER_CLASS_NAME,FUNC) + +#ifndef ORG_HELPER_CLASS_NAME +#define ORG_HELPER_CLASS_NAME org_cocos2dx_lib_Cocos2dxHelper +#endif +#define JNI_HELPER(FUNC) JNI_METHOD1(ORG_HELPER_CLASS_NAME,FUNC) + +#ifndef ORG_AUDIOFOCUS_CLASS_NAME +#define ORG_AUDIOFOCUS_CLASS_NAME org_cocos2dx_lib_Cocos2dxAudioFocusManager +#endif +#define JNI_AUDIO(FUNC) JNI_METHOD1(ORG_AUDIOFOCUS_CLASS_NAME,FUNC) + #define KEYCODE_BACK 0x04 #define KEYCODE_MENU 0x52 #define KEYCODE_DPAD_UP 0x13 @@ -106,7 +126,7 @@ extern "C" * Cocos2dxActivity native functions implementation. *****************************************************/ - JNIEXPORT jintArray JNICALL Java_org_cocos2dx_lib_Cocos2dxActivity_getGLContextAttrs(JNIEnv* env, jobject thiz) + JNIEXPORT jintArray JNICALL JNI_RENDER(getGLContextAttrs)(JNIEnv* env, jobject thiz) { //REFINE int tmp[7] = {8, 8, 8, @@ -121,7 +141,7 @@ extern "C" * Cocos2dxRenderer native functions implementation. *****************************************************/ - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h, jstring jDefaultResourcePath) + JNIEXPORT void JNICALL JNI_RENDER(nativeInit)(JNIEnv* env, jobject thiz, jint w, jint h, jstring jDefaultResourcePath) { g_width = w; g_height = h; @@ -146,7 +166,7 @@ extern "C" g_isStarted = true; } - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeRender(JNIEnv* env) + JNIEXPORT void JNICALL JNI_RENDER(nativeRender)(JNIEnv* env) { if (g_isGameFinished) { @@ -227,7 +247,7 @@ extern "C" __jsbInvocationCount = 0; } - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnPause() + JNIEXPORT void JNICALL JNI_RENDER(nativeOnPause)() { if (g_isGameFinished) { return; @@ -236,7 +256,7 @@ extern "C" g_app->applicationDidEnterBackground(); } - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnResume() + JNIEXPORT void JNICALL JNI_RENDER(nativeOnResume)() { if (g_isGameFinished) { return; @@ -245,22 +265,22 @@ extern "C" g_app->applicationWillEnterForeground(); } - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInsertText(JNIEnv* env, jobject thiz, jstring text) + JNIEXPORT void JNICALL JNI_RENDER(nativeInsertText)(JNIEnv* env, jobject thiz, jstring text) { //REFINE } - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeDeleteBackward(JNIEnv* env, jobject thiz) + JNIEXPORT void JNICALL JNI_RENDER(nativeDeleteBackward)(JNIEnv* env, jobject thiz) { //REFINE } - JNIEXPORT jstring JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeGetContentText() + JNIEXPORT jstring JNICALL JNI_RENDER(nativeGetContentText)() { //REFINE } - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnSurfaceChanged(JNIEnv* env, jobject thiz, jint w, jint h) + JNIEXPORT void JNICALL JNI_RENDER(nativeOnSurfaceChanged)(JNIEnv* env, jobject thiz, jint w, jint h) { //REFINE } @@ -269,7 +289,7 @@ extern "C" * Cocos2dxAccelerometer native functions implementation. ***********************************************************/ - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxAccelerometer_onSensorChanged(JNIEnv* env, jobject thiz, jfloat x, jfloat y, jfloat z, jlong timeStamp) + JNIEXPORT void JNICALL JNI_ACCELEROMETER(onSensorChanged)(JNIEnv* env, jobject thiz, jfloat x, jfloat y, jfloat z, jlong timeStamp) { //REFINE } @@ -326,7 +346,7 @@ extern "C" cocos2d::EventDispatcher::dispatchTouchEvent(touchEvent); } - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesBegin(JNIEnv * env, jobject thiz, jint id, jfloat x, jfloat y) + JNIEXPORT void JNICALL JNI_RENDER(nativeTouchesBegin)(JNIEnv * env, jobject thiz, jint id, jfloat x, jfloat y) { if (g_isGameFinished) { return; @@ -334,7 +354,7 @@ extern "C" dispatchTouchEventWithOnePoint(env, cocos2d::TouchEvent::Type::BEGAN, id, x, y); } - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesEnd(JNIEnv * env, jobject thiz, jint id, jfloat x, jfloat y) + JNIEXPORT void JNICALL JNI_RENDER(nativeTouchesEnd)(JNIEnv * env, jobject thiz, jint id, jfloat x, jfloat y) { if (g_isGameFinished) { return; @@ -342,7 +362,7 @@ extern "C" dispatchTouchEventWithOnePoint(env, cocos2d::TouchEvent::Type::ENDED, id, x, y); } - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesMove(JNIEnv * env, jobject thiz, jintArray ids, jfloatArray xs, jfloatArray ys) + JNIEXPORT void JNICALL JNI_RENDER(nativeTouchesMove)(JNIEnv * env, jobject thiz, jintArray ids, jfloatArray xs, jfloatArray ys) { if (g_isGameFinished) { return; @@ -350,7 +370,7 @@ extern "C" dispatchTouchEventWithPoints(env, cocos2d::TouchEvent::Type::MOVED, ids, xs, ys); } - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesCancel(JNIEnv * env, jobject thiz, jintArray ids, jfloatArray xs, jfloatArray ys) + JNIEXPORT void JNICALL JNI_RENDER(nativeTouchesCancel)(JNIEnv * env, jobject thiz, jintArray ids, jfloatArray xs, jfloatArray ys) { if (g_isGameFinished) { return; @@ -358,7 +378,7 @@ extern "C" dispatchTouchEventWithPoints(env, cocos2d::TouchEvent::Type::CANCELLED, ids, xs, ys); } - JNIEXPORT jboolean JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeKeyEvent(JNIEnv * env, jobject thiz, jint keyCode, jboolean isPressed) + JNIEXPORT jboolean JNICALL JNI_RENDER(nativeKeyEvent)(JNIEnv * env, jobject thiz, jint keyCode, jboolean isPressed) { if (g_isGameFinished) { return JNI_TRUE; @@ -407,25 +427,25 @@ extern "C" * Cocos2dxHelper native functions implementation. ***********************************************************/ - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxHelper_nativeSetApkPath(JNIEnv* env, jobject thiz, jstring apkPath) + JNIEXPORT void JNICALL JNI_HELPER(nativeSetApkPath)(JNIEnv* env, jobject thiz, jstring apkPath) { g_apkPath = JniHelper::jstring2string(apkPath); } - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxHelper_nativeSetContext(JNIEnv* env, jobject thiz, jobject context, jobject assetManager) + JNIEXPORT void JNICALL JNI_HELPER(nativeSetContext)(JNIEnv* env, jobject thiz, jobject context, jobject assetManager) { JniHelper::setClassLoaderFrom(context); FileUtilsAndroid::setassetmanager(AAssetManager_fromJava(env, assetManager)); } - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxHelper_nativeSetAudioDeviceInfo(JNIEnv* env, jobject thiz, jboolean isSupportLowLatency, jint deviceSampleRate, jint deviceAudioBufferSizeInFrames) + JNIEXPORT void JNICALL JNI_HELPER(nativeSetAudioDeviceInfo)(JNIEnv* env, jobject thiz, jboolean isSupportLowLatency, jint deviceSampleRate, jint deviceAudioBufferSizeInFrames) { g_deviceSampleRate = deviceSampleRate; g_deviceAudioBufferSizeInFrames = deviceAudioBufferSizeInFrames; LOGD("nativeSetAudioDeviceInfo: sampleRate: %d, bufferSizeInFrames: %d", g_deviceSampleRate, g_deviceAudioBufferSizeInFrames); } - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxHelper_nativeSetEditTextDialogResult(JNIEnv* env, jobject obj, jbyteArray text) + JNIEXPORT void JNICALL JNI_HELPER(nativeSetEditTextDialogResult)(JNIEnv* env, jobject obj, jbyteArray text) { jsize size = env->GetArrayLength(text); @@ -455,7 +475,7 @@ extern "C" * Cocos2dxAudioFocusManager native functions implementation. ***********************************************************/ - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxAudioFocusManager_nativeOnAudioFocusChange(JNIEnv* env, jobject thiz, jint focusChange) + JNIEXPORT void JNICALL JNI_AUDIO(nativeOnAudioFocusChange)(JNIEnv* env, jobject thiz, jint focusChange) { // cocos_audioengine_focus_change(focusChange); } diff --git a/native/cocos/scripting/js-bindings/manual/JavaScriptJavaBridge.cpp b/native/cocos/scripting/js-bindings/manual/JavaScriptJavaBridge.cpp index 2cae43e31d..e98647e649 100644 --- a/native/cocos/scripting/js-bindings/manual/JavaScriptJavaBridge.cpp +++ b/native/cocos/scripting/js-bindings/manual/JavaScriptJavaBridge.cpp @@ -37,9 +37,14 @@ #define LOG_TAG "JavaScriptJavaBridge" +#ifndef ORG_JAVABRIDGE_CLASS_NAME +#define ORG_JAVABRIDGE_CLASS_NAME org_cocos2dx_lib_Cocos2dxJavascriptJavaBridge +#endif +#define JNI_JSJAVABRIDGE(FUNC) JNI_METHOD1(ORG_JAVABRIDGE_CLASS_NAME,FUNC) + extern "C" { -JNIEXPORT jint JNICALL Java_org_cocos2dx_lib_Cocos2dxJavascriptJavaBridge_evalString +JNIEXPORT jint JNICALL JNI_JSJAVABRIDGE(evalString) (JNIEnv *env, jclass cls, jstring value) { se::AutoHandleScope hs; diff --git a/native/cocos/ui/edit-box/EditBox-android.cpp b/native/cocos/ui/edit-box/EditBox-android.cpp index a8abfce705..6a0f0cc235 100644 --- a/native/cocos/ui/edit-box/EditBox-android.cpp +++ b/native/cocos/ui/edit-box/EditBox-android.cpp @@ -29,6 +29,12 @@ #define CLASS_PATH "org/cocos2dx/lib/Cocos2dxEditBox" +#ifndef ORG_EDITBOX_CLASS_NAME +#define ORG_EDITBOX_CLASS_NAME org_cocos2dx_lib_Cocos2dxEditBox +#endif +#define JNI_EDITBOX(FUNC) JNI_METHOD1(ORG_EDITBOX_CLASS_NAME,FUNC) + + NS_CC_BEGIN void EditBox::show(const cocos2d::EditBox::ShowInfo& showInfo) @@ -81,17 +87,17 @@ namespace extern "C" { - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxEditBox_onKeyboardInputNative(JNIEnv* env, jclass, jstring text) + JNIEXPORT void JNICALL JNI_EDITBOX(onKeyboardInputNative)(JNIEnv* env, jclass, jstring text) { callJSFunc("input", text); } - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxEditBox_onKeyboardCompleteNative(JNIEnv* env, jclass, jstring text) + JNIEXPORT void JNICALL JNI_EDITBOX(onKeyboardCompleteNative)(JNIEnv* env, jclass, jstring text) { callJSFunc("complete", text); } - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxEditBox_onKeyboardConfirmNative(JNIEnv* env, jclass, jstring text) + JNIEXPORT void JNICALL JNI_EDITBOX(onKeyboardConfirmNative)(JNIEnv* env, jclass, jstring text) { callJSFunc("confirm", text); }