GoogleBaseGameActivty 扩展 BaseGameActivty(AndEngine) 崩溃

GoogleBaseGameActivty extends BaseGameActivty(AndEngine) Crash

一段时间以来,一直在努力处理 andEngine 和 Google 游戏服务集成。所以我想我会在这里碰碰运气。

我已经完成了多个帖子和博客中描述的步骤,如下所示: Issues in integrating Google Play Game Services Leaderboard in AndEngine Game

使用 android 个工作室和 gradle

我添加了 BaseGameUtils(Android Sample),扩展了 AndEngine BaseGameActivity 并重命名为 GoogleBaseGameActivity。然后我在我的 GameActivty(mainActivity)

中用 GoogleBaseGameActivity 替换了 BaseGameActivtiy

游戏在我进行扩展和重命名之前运行。

主要活动:

public class GameActivity extends GoogleBaseGameActivity

BaseGameUtils 中的 BaseGameActivity(Google):

import org.andengine.ui.activity.BaseGameActivity; 

public abstract class GoogleBaseGameActivity extends BaseGameActivity implements GameHelper.GameHelperListener

Logcat:

03-23 10:36:15.006  15860-15860/com.tdt4240.a19.mazegame I/Process﹕ Sending signal. PID: 15860 SIG: 9
03-23 10:51:33.826  17012-17012/com.tdt4240.a19.mazegame W/dalvikvm﹕ No implementation found for native Ldalvik/system/VMRuntime;.pauseGc:(Ljava/lang/String;)I
03-23 10:51:33.826  17012-17012/com.tdt4240.a19.mazegame E/ActivityThread﹕ Pause GC
    java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at android.app.ActivityThread.pauseGC(ActivityThread.java:5410)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2277)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
            at android.app.ActivityThread.access0(ActivityThread.java:169)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5487)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.UnsatisfiedLinkError: Native method not found: dalvik.system.VMRuntime.pauseGc:(Ljava/lang/String;)I
            at dalvik.system.VMRuntime.pauseGc(Native Method)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at android.app.ActivityThread.pauseGC(ActivityThread.java:5410)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2277)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
            at android.app.ActivityThread.access0(ActivityThread.java:169)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5487)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
            at dalvik.system.NativeStart.main(Native Method)
03-23 10:51:33.831  17012-17012/com.tdt4240.a19.mazegame I/PersonaManager﹕ getPersonaService() name persona_policy
03-23 10:51:33.856  17012-17012/com.tdt4240.a19.mazegame D/MultiMazed﹕ onCreateEngineOptions() called
03-23 10:51:33.881  17012-17012/com.tdt4240.a19.mazegame I/PersonaManager﹕ getPersonaService() name persona_policy
03-23 10:51:33.896  17012-17012/com.tdt4240.a19.mazegame W/PopupManager﹕ You have not specified a View to use as content view for popups. Falling back to the Activity content view which may not work properly in future versions of the API. Use setViewForPopups() to set your content view.
03-23 10:51:33.906  17012-17012/com.tdt4240.a19.mazegame I/dalvikvm﹕ Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzg
03-23 10:51:33.906  17012-17012/com.tdt4240.a19.mazegame W/dalvikvm﹕ VFY: unable to resolve virtual method 515: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
03-23 10:51:33.906  17012-17012/com.tdt4240.a19.mazegame D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000b
03-23 10:51:33.971  17012-17012/com.tdt4240.a19.mazegame D/libEGL﹕ loaded /system/lib/egl/libEGL_mali.so
03-23 10:51:33.976  17012-17012/com.tdt4240.a19.mazegame D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_mali.so
03-23 10:51:33.981  17012-17012/com.tdt4240.a19.mazegame D/libEGL﹕ loaded /system/lib/egl/libGLESv2_mali.so
03-23 10:51:33.981  17012-17012/com.tdt4240.a19.mazegame E/﹕ Device driver API match
    Device driver API version: 23
    User space API version: 23
03-23 10:51:33.981  17012-17012/com.tdt4240.a19.mazegame E/﹕ mali: REVISION=Linux-r3p2-01rel3 BUILD_DATE=Mon Feb 10 15:44:10 KST 2014
03-23 10:51:34.036  17012-17012/com.tdt4240.a19.mazegame D/OpenGLRenderer﹕ Enabling debug mode 0
03-23 10:51:34.141  17012-17026/com.tdt4240.a19.mazegame D/MultiMazed﹕ onPopulateScene() called
03-23 10:51:34.141  17012-17026/com.tdt4240.a19.mazegame D/MultiMazed﹕ onCreateScene() called
03-23 10:51:34.141  17012-17026/com.tdt4240.a19.mazegame D/MultiMazed﹕ onCreateResources() called
03-23 10:51:34.336  17012-17012/com.tdt4240.a19.mazegame D/AndroidRuntime﹕ Shutting down VM
03-23 10:51:34.336  17012-17012/com.tdt4240.a19.mazegame W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41d0dc08)
03-23 10:51:34.336  17012-17012/com.tdt4240.a19.mazegame E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.tdt4240.a19.mazegame, PID: 17012
    java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information.
            at com.google.android.gms.common.internal.zzk$zza.zzc(Unknown Source)
            at com.google.android.gms.common.internal.zzk$zza.zzi(Unknown Source)
            at com.google.android.gms.common.internal.zzk$zzc.zzjg(Unknown Source)
            at com.google.android.gms.common.internal.zzk$zzb.handleMessage(Unknown Source)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5487)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
            at dalvik.system.NativeStart.main(Native Method)
03-23 10:51:34.416  17012-17026/com.tdt4240.a19.mazegame D/dalvikvm﹕ GC_EXPLICIT freed 1537K, 32% free 5498K/8056K, paused 3ms+8ms, total 74ms
03-23 10:51:34.481  17012-17026/com.tdt4240.a19.mazegame D/dalvikvm﹕ GC_EXPLICIT freed 40K, 32% free 5494K/8056K, paused 6ms+3ms, total 50ms
03-23 10:56:34.371  17012-17012/com.tdt4240.a19.mazegame I/Process﹕ Sending signal. PID: 17012 SIG: 9

当应用程序 ID 不正确或位置错误时会发生这种情况。对我来说,我必须更改我的清单:

<meta-data android:name="com.google.android.gms.games.APP_ID"
        android:value="000000000000" />
    <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version"/>

string.xml 文件中实际引用它。于是改成这样:

<meta-data android:name="com.google.android.gms.games.APP_ID"
        android:value="@string/app_id" />
    <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version"/>

然后我将我的应用程序 ID 放在字符串 class 中。我不知道为什么会这样,但这就是为我解决的问题。