What does "Failed to find static method id..." mean?

cocos2d-x version: 3.3 (C++)
build platform: Ubuntu Linux 14.04
build target: Android (API level 15) (NDK r10d)

I created a new game wth cocos new and then built an APK with cocos run. It mostly works but a few features fail.
When I looked at the logcat output I saw some lines like this:

E/JniHelper(98038010): Failed to find static method id of getCocos2dxWritablePath
E/JniHelper(98038010): Failed to find static method id of setAnimationInterval
E/JniHelper(98038010): Failed to find static method id of preloadEffect
E/JniHelper(98038010): Failed to find static method id of getCocos2dxPackageName
E/JniHelper(98038010): Failed to find static method id of getBoolForKey
E/JniHelper(98038010): Failed to find static method id of playEffect
E/JniHelper(98038010): Failed to find static method id of pauseAllEffects

(Some occur multiple times.) If these functions are failing then that would explain why some features such as sound are not working in my game but how did this happen. Some grepping shows that these messages are coming from JNIHelper but the only file I changed in the proj.android/jni directory was Android.mk which now looks like this.

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

$(call import-add-path,$(LOCAL_PATH)/../../cocos2d)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/external)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos)

LOCAL_MODULE := cocos2dcpp_shared

LOCAL_MODULE_FILENAME := libcocos2dcpp

LOCAL_SRC_FILES := hellocpp/main.cpp \
                   ../../Classes/AppDelegate.cpp \
                   ../../Classes/GameScreen.cpp \
                   ../../Classes/HelpScreen.cpp \
                   ../../Classes/SplashScreen.cpp \
                   ../../Classes/Util.cpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes

LOCAL_STATIC_LIBRARIES := cocos2dx_static
LOCAL_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_STATIC_LIBRARIES += cocos_extension_static

include $(BUILD_SHARED_LIBRARY)

$(call import-module,.)
$(call import-module,audio/android)
$(call import-module,extensions)

Is something wrong there? Any help in solving this would be gratefully appreciated.

I’m using same configuration except API level 19 and every thing running smooth.

In the end the problem was proguard. After I added

-keep public class org.cocos2dx.lib.* {
    *;
}

-keep public class org.cocos2dx.cpp.AppActivity {
    *;
}

…to proj.android/proguard-project.txt the problem went away.

4 Likes

Had the same problem. Jaldhar, thanks for solution!

Just a quick note: I had proguard disabled so I haven’t got this issue… until now, because in the latest android studio update it seems like it enables proguard when bulding release apk, so my app was just crashing when running from apk, but working fine while running in debug mode from Android Studio. Adding these lines fixed the issue, thanks.