Cocos2d-x 项目仅在 android 14 (SDK 34) 上崩溃

问题描述 投票:0回答:1

我正在做一个用Cocos2d-x开发的项目。使用org.cocos2dx.lib,我已经在Android Studio中成功将其移植到Android。但是,我遇到了仅在 Android 14 (SDK 34) 上发生的崩溃问题。在 Android 14 上启动后立即崩溃。该应用程序在其他版本的 Android 上运行良好。 该应用程序在 Android 13 上运行没有问题,但在 Android 14 (SDK 34) 上遇到崩溃。 logcat中的错误信息是:

JNI 在应用程序中检测到错误:obj==null 调用 CallObjectMethodV 来自 void org.cocos2dx.lib.Cocos2dxRenderer.nativeInit(int, int)

此错误消息仅在 Android 14 中显示。

是否存在已知问题或需要进行特定更改才能与 Android 14 兼容? 我可以采取哪些步骤来调试或解决此 JNI 错误?

android java-native-interface cocos2d-x android-14
1个回答
0
投票

cocos2d-x 的最后一个版本是 5 年前的版本。我有大约 40 个使用 cocos2d-x 的应用程序,并且旧版本 4.0 与新的 Android 版本和 iOS 版本结合使用时遇到了几个问题。

我现在使用 Axmol 引擎(cocos2d-x 4.0 的分支)Axmol.org,几乎不需要任何更改(cocos:: 到 ax::)(CCLOG 到 AXLOG)工作完美,错误很快得到修复。 这个项目中的JNI可以帮助你。

但是如果你还想使用cocos2d-x:

    JNIEXPORT void JNICALL Java_org_axmol_lib_AxmolRenderer_nativeRender(JNIEnv*, jclass)
{
    ax::Director::getInstance()->mainLoop();
}

JNIEXPORT void JNICALL Java_org_axmol_lib_AxmolRenderer_nativeOnPause(JNIEnv*, jclass)
{
    if (Director::getInstance()->getGLView())
    {
        Application::getInstance()->applicationDidEnterBackground();
        ax::EventCustom backgroundEvent(EVENT_COME_TO_BACKGROUND);
        ax::Director::getInstance()->getEventDispatcher()->dispatchEvent(&backgroundEvent);
    }
}

JNIEXPORT void JNICALL Java_org_axmol_lib_AxmolRenderer_nativeOnResume(JNIEnv*, jclass)
{
    static bool firstTime = true;
    if (Director::getInstance()->getGLView())
    {
        // don't invoke at first to keep the same logic as iOS
        // can refer to https://github.com/cocos2d/cocos2d-x/issues/14206
        if (!firstTime)
            Application::getInstance()->applicationWillEnterForeground();

        ax::EventCustom foregroundEvent(EVENT_COME_TO_FOREGROUND);
        ax::Director::getInstance()->getEventDispatcher()->dispatchEvent(&foregroundEvent);

        firstTime = false;
    }
}

JNIEXPORT void JNICALL Java_org_axmol_lib_AxmolRenderer_nativeInsertText(JNIEnv* env, jclass, jstring text)
{
    std::string strValue = ax::StringUtils::getStringUTFCharsJNI(env, text);
    const char* pszText  = strValue.c_str();
    ax::IMEDispatcher::sharedDispatcher()->dispatchInsertText(pszText, strlen(pszText));
}

JNIEXPORT void JNICALL Java_org_axmol_lib_AxmolRenderer_nativeDeleteBackward(JNIEnv*, jclass)
{
    ax::IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward();
}

JNIEXPORT jstring JNICALL Java_org_axmol_lib_AxmolRenderer_nativeGetContentText(JNIEnv* env, jclass)
{
    auto pszText = ax::IMEDispatcher::sharedDispatcher()->getContentText();
    return ax::StringUtils::newStringUTFJNI(env, pszText);
}
© www.soinside.com 2019 - 2024. All rights reserved.