SonarSystems / Cocos-Helper

Cocos2d-x external framework helper.
MIT License
120 stars 47 forks source link

Game crash when use google play services #47

Open songsinh88 opened 8 years ago

songsinh88 commented 8 years ago

i use cocos2dx v3.10, and Android studio for dev, when i use google playservice (SonarFrameworkSettings.USE_GOOGLE_PLAY_GAME_SERVICES). My game crash when call: if (!SonarCocosHelper::GooglePlayServices::isSignedIn()) { SonarCocosHelper::GooglePlayServices::signIn(); }


Log crash:

02-20 23:38:07.386 12311-12358/com.mystudio.puzzlegame W/GooglePlayServicesUtil: Google Play services out of date. Requires 8487000 but found 7574036 02-20 23:38:07.436 12311-12422/com.mystudio.puzzlegame W/GooglePlayServicesUtil: Google Play services out of date. Requires 8487000 but found 7574036 02-20 23:38:07.576 12311-12356/com.mystudio.puzzlegame D/CocosPlayClient.cpp: isEnabled = 0 02-20 23:38:07.576 12311-12356/com.mystudio.puzzlegame D/CocosPlayClient.cpp: isDemo = 0 02-20 23:38:07.576 12311-12356/com.mystudio.puzzlegame D/CocosPlayClient.cpp: isNotifyFileLoadedEnabled = 0 02-20 23:38:07.656 12311-12311/com.mystudio.puzzlegame D/Cocos2dxActivity: onWindowFocusChanged() hasFocus=true 02-20 23:38:08.447 12311-12356/com.mystudio.puzzlegame D/cocos2d-x debug info: create rendererRecreatedListener for GLProgramState 02-20 23:38:08.447 12311-12356/com.mystudio.puzzlegame V/Cocos2dxActivity: cancelLocalNotification 02-20 23:38:08.467 12311-12356/com.mystudio.puzzlegame V/Cocos2dxActivity: showLocalNotification 02-20 23:38:08.467 12311-12356/com.mystudio.puzzlegame W/dalvikvm: dvmFindClassByName rejecting 'sonar/systems/framework/SonarFrameworkFunctions' 02-20 23:38:08.467 12311-12356/com.mystudio.puzzlegame D/cocos2d-x debug info: create rendererRecreatedListener for GLProgramState 02-20 23:38:08.757 12311-12356/com.mystudio.puzzlegame D/cocos2d-x debug info: create rendererRecreatedListener for GLProgramState 02-20 23:38:08.807 12311-12356/com.mystudio.puzzlegame W/dalvikvm: Invalid indirect reference 0x41c89300 in decodeIndirectRef 02-20 23:38:08.807 12311-12356/com.mystudio.puzzlegame E/dalvikvm: VM aborting 02-20 23:38:09.188 12311-12311/com.mystudio.puzzlegame W/dalvikvm: VFY: unable to resolve virtual method 16398: Landroid/webkit/WebSettings;.setMixedContentMode (I)V 02-20 23:38:09.198 12311-12311/com.mystudio.puzzlegame W/dalvikvm: VFY: unable to resolve virtual method 16409: Landroid/webkit/WebView;.evaluateJavascript (Ljava/lang/String;Landroid/webkit/ValueCallback;)V 02-20 23:38:09.208 12311-12311/com.mystudio.puzzlegame W/dalvikvm: VFY: unable to resolve virtual method 41000: Lcom/google/android/gms/internal/zzjt;.isAttachedToWindow ()Z 02-20 23:38:09.498 12311-12370/com.mystudio.puzzlegame E/SQLiteLog: (1) no such table: CacheGroups 02-20 23:38:09.508 12311-12370/com.mystudio.puzzlegame D/WebKit: ERROR: 02-20 23:38:09.508 12311-12370/com.mystudio.puzzlegame D/WebKit: Application Cache Storage: failed to execute statement "DELETE FROM CacheGroups" error "no such table: CacheGroups" 02-20 23:38:09.508 12311-12370/com.mystudio.puzzlegame D/WebKit: external/webkit/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp(558) : bool WebCore::ApplicationCacheStorage::executeSQLCommand(const WTF::String&) 02-20 23:38:09.508 12311-12370/com.mystudio.puzzlegame E/SQLiteLog: (1) no such table: Caches 02-20 23:38:09.508 12311-12370/com.mystudio.puzzlegame D/WebKit: ERROR: 02-20 23:38:09.508 12311-12370/com.mystudio.puzzlegame D/WebKit: Application Cache Storage: failed to execute statement "DELETE FROM Caches" error "no such table: Caches" 02-20 23:38:09.508 12311-12370/com.mystudio.puzzlegame D/WebKit: external/webkit/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp(558) : bool WebCore::ApplicationCacheStorage::executeSQLCommand(const WTF::String&) 02-20 23:38:09.508 12311-12370/com.mystudio.puzzlegame E/SQLiteLog: (1) no such table: Origins 02-20 23:38:09.508 12311-12370/com.mystudio.puzzlegame D/WebKit: ERROR: 02-20 23:38:09.508 12311-12370/com.mystudio.puzzlegame D/WebKit: Application Cache Storage: failed to execute statement "DELETE FROM Origins" error "no such table: Origins" 02-20 23:38:09.508 12311-12370/com.mystudio.puzzlegame D/WebKit: external/webkit/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp(558) : bool WebCore::ApplicationCacheStorage::executeSQLCommand(const WTF::String&) 02-20 23:38:09.508 12311-12370/com.mystudio.puzzlegame E/SQLiteLog: (1) no such table: DeletedCacheResources 02-20 23:38:09.598 12311-12356/com.mystudio.puzzlegame A/libc: Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 12356 (Thread-8624)

Pls help me fix that.

OscarLeif commented 8 years ago

if you don't use those methods everything works fine ?

OscarLeif commented 8 years ago

make sure you add the java files of play services if you don't put them in the right folder it will crash. Did you watch the tutorial of setting up google play services ?

uxdxdev commented 8 years ago

Im having the same issue with v3.9 using api 21. I have followed your tutorial for setting it up, got twitter going fine, thanks for that :), but google play services just crashes the app once its installed on the device. I am building the debug version using cocos run -p android using eclipse.

OscarLeif commented 8 years ago

@damorton Right now in order to use Google play services you need to compile cocos2d-x android project with Android version 21+ I the helper with google play services with no problems. Tell more details

uxdxdev commented 8 years ago

Ok details are:

Project builds OK but when using cocos run -p android the game crashes after being installed on the device.

If I set USE_GOOGLE_PLAY_GAME_SERVICES=true the game will crash on install. Setting this to false will run the game fine but without gps obviously.

uxdxdev commented 8 years ago

log file from LogCat

03-17 01:19:05.094: D/AndroidRuntime(25424): Shutting down VM
03-17 01:19:05.104: E/AndroidRuntime(25424): FATAL EXCEPTION: main
03-17 01:19:05.104: E/AndroidRuntime(25424): Process: ie.blogspot.damorton, PID: 25424
03-17 01:19:05.104: E/AndroidRuntime(25424): java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/util/ArrayMap;
03-17 01:19:05.104: E/AndroidRuntime(25424):    at com.google.android.gms.common.api.GoogleApiClient$Builder.<init>(Unknown Source)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at com.google.android.gms.common.api.GoogleApiClient$Builder.<init>(Unknown Source)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at sonar.systems.frameworks.GooglePlayServices.GooglePlayServicesGameHelper.createApiClientBuilder(GooglePlayServicesGameHelper.java:290)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at sonar.systems.frameworks.GooglePlayServices.GooglePlayServicesGameHelper.setup(GooglePlayServicesGameHelper.java:335)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at sonar.systems.frameworks.GooglePlayServices.GooglePlayServices.onCreate(GooglePlayServices.java:109)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at sonar.systems.framework.SonarFrameworkFunctions.onCreate(SonarFrameworkFunctions.java:1145)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at sonar.systems.framework.SonarFrameworkActivity.onCreate(SonarFrameworkActivity.java:29)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at android.app.Activity.performCreate(Activity.java:6289)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2655)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at android.app.ActivityThread.access$900(ActivityThread.java:177)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at android.os.Handler.dispatchMessage(Handler.java:102)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at android.os.Looper.loop(Looper.java:145)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at android.app.ActivityThread.main(ActivityThread.java:5951)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at java.lang.reflect.Method.invoke(Native Method)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at java.lang.reflect.Method.invoke(Method.java:372)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
03-17 01:19:05.104: E/AndroidRuntime(25424): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.util.ArrayMap" on path: DexPathList[[zip file "/data/app/ie.blogspot.damorton-1/base.apk"],nativeLibraryDirectories=[/data/app/ie.blogspot.damorton-1/lib/arm, /vendor/lib, /system/lib]]
03-17 01:19:05.104: E/AndroidRuntime(25424):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
03-17 01:19:05.104: E/AndroidRuntime(25424):    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
03-17 01:19:05.104: E/AndroidRuntime(25424):    ... 20 more
03-17 01:19:05.104: E/AndroidRuntime(25424):    Suppressed: java.lang.ClassNotFoundException: android.support.v4.util.ArrayMap
03-17 01:19:05.104: E/AndroidRuntime(25424):        at java.lang.Class.classForName(Native Method)
03-17 01:19:05.104: E/AndroidRuntime(25424):        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
03-17 01:19:05.104: E/AndroidRuntime(25424):        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
03-17 01:19:05.104: E/AndroidRuntime(25424):        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
03-17 01:19:05.104: E/AndroidRuntime(25424):        ... 21 more
03-17 01:19:05.104: E/AndroidRuntime(25424):    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
uxdxdev commented 8 years ago

Switched to using Android Studio, getting errors with appcompat-v7 with libcocos2dx.

OscarLeif commented 8 years ago

@damorton Sorry I no have a lot of free time, in the last log that you have you will need the android-support-v4.jar file, 4 line talks about that. I'm not sure why some people have to use that library. If I can reproduce the problem I will write about that. Cocos helper was made for eclipse I'm not sure how to use it in Android Studio but it looks like you need android-support-v7.jar file. Better use the lasted Android NDK

uxdxdev commented 8 years ago

No worries thanks for the help. Im going to go back to using Eclipse ADT and see I can get it working from there.

uxdxdev commented 8 years ago

Ok so I tried it again. Setup is:

Built google-play-services_lib with target api 21 because with api 19 the appcompat-v7 error is happening. Build successful.

Built project to api 21. Build successful.

Export apk from Eclipse, added keystore key, activated Googe Play Services from developer console. Installed to device. OK

Run app on device. Crashes.

If I set USE_GOOGLE_PLAY_GAME_SERVICES = false; and rebuild, the app runs fine but I dont have gps as before. Im trying an older revision of the google play services_lib now. Rev 22

uxdxdev commented 8 years ago

Ok so I got it working. googe-play-services_lib needs to be rev22. Link to download the library is here http://venomvendor.blogspot.ie/2012/03/android-sdk-extras-by-google-inc.html

Final setup:

Build google-play-services_lib for api 19 Build libcocos2dx for api 19 Build project for api 21

Notes: gps sign in needs to happen in the init() of the scene. I had originally set it to called on a button press but it didnt work so, make sure its called when the app starts.

uxdxdev commented 8 years ago

It could be something to do with the deprecated use of the clearDefaultAccount line 579 GooglePlayServicesGameHelper.java. on newer revisions of the gps_lib

OscarLeif commented 8 years ago

@damorton Google updates the libraries so we have also to update them, I remember when in a release of a new Google play services our code stop working, because some methods were delete by them So it need some updates, I will check that. About the android extras libraries they're in the android SDK folder (a lot of people don't know this) Example of path D:\SDK_Android\sdk\extras\android\support Check inside and you find folder v4,v7 inside those folder are the support libraries.