2017-08-21 81 views
0

的Android 2.3.3工作室(最新)声纳科科斯助手 - 设置谷歌Play游戏服务在Android工作室

的Cocos2D-X 3.15.1(最新)

我测试了调试。

这是我用的Cocos2D-X游戏引擎第一次的经验,我公司开发使用的Cocos2D-X的Android的游戏,它的所有罚款,但是当我试图表明的成绩就说明我的错误这样的:

java.lang.NullPointerException 
          at sonar.systems.framework.SonarFrameworkFunctions.showAchievements(SonarFrameworkFunctions.java:432) 
          at org.cocos2dx.lib.Cocos2dxRenderer.nativeTouchesEnd(Native Method) 
          at org.cocos2dx.lib.Cocos2dxRenderer.handleActionUp(Cocos2dxRenderer.java:129) 
          at org.cocos2dx.lib.Cocos2dxGLSurfaceView$10.run(Cocos2dxGLSurfaceView.java:311) 
          at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1486) 
          at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1263) 

当我点击,显示成就我的代码:

SonarCocosHelper::GooglePlayServices::showAchievements(); 

,当我想登陆:

java.lang.NullPointerException 
      at sonar.systems.framework.SonarFrameworkFunctions.isSignedIn(SonarFrameworkFunctions.java:277) 
      at org.cocos2dx.lib.Cocos2dxRenderer.nativeRender(Native Method) 
      at org.cocos2dx.lib.Cocos2dxRenderer.onDrawFrame(Cocos2dxRenderer.java:105) 
      at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1557) 
      at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1263) 

我对代码签名在:

if(!SonarCocosHelper::GooglePlayServices::isSignedIn()) 
    SonarCocosHelper::GooglePlayServices::signIn(); 

我的清单文件:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.ilyo.test" 
    android:installLocation="auto"> 

    <supports-screens android:anyDensity="true" 
     android:smallScreens="true" 
     android:normalScreens="true" 
     android:largeScreens="true" 
     android:xlargeScreens="true"/> 

    <uses-feature android:glEsVersion="0x00020000" /> 

    <!-- Basic permission for Internet and don't allow turn of the screen --> 
    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.WAKE_LOCK" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

    <application 
     android:label="@string/app_name" 
     android:allowBackup="true" 
     android:hardwareAccelerated="true" 
     android:icon="@mipmap/ic_launcher"> 

     <!-- Tell Cocos2dxActivity the name of our .so --> 
     <meta-data android:name="android.app.lib_name" 
        android:value="MyGame" /> 

     <!-- Required for Google Play Services --> 
<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"/> 


<activity 
    android:name="org.cocos2dx.cpp.AppActivity" 
    android:screenOrientation="portrait" 
    android:configChanges="orientation|keyboardHidden|screenSize" 
    android:label="@string/app_name" 
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > 

    <intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 

     <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
</activity> 

</application> 
</manifest> 

建设摇篮文件:

enter image description here

科科斯助手框架中使用:

enter image description here

我的谷歌游戏成就(我删除从这张照片的ID):

enter image description here

我搜索已经为使用Android Studio中关系的解决方案,但结果是非常罕见的,我不不知道什么是解决方案,这是什么原因造成这个错误。

谢谢

回答

0

我创立了一个解决方案,但现在我想这只是一个肮脏的修复,第一问题是在GooglePlayServices.java,准确地在在onStart方法:空指针异常,因为mHelper为空。

@Override 
    public void onStart() 
    { 
     mHelper.onStart((Activity) ctx); 
    } 

让我们远一点,为什么它会产生空,所以:

1 SonarFrameworkFunctions.java

,当我们想从SonarFrameworkFunctions调用GooglePlayServices构造。的java

//GOOGLE PLAY SERVICES 
    if (SonarFrameworkSettings.USE_GOOGLE_PLAY_GAME_SERVICES) 
    { 
     String packageName = "sonar.systems.frameworks.GooglePlayServices.GooglePlayServices"; 
     googlePlayServices = (InstantiateFramework(packageName) != null) ? InstantiateFramework(packageName) : new Framework(); 
    } 

2.方法:在InstantiateFramework SonarFrameworkFunctions.java

public static Framework InstantiateFramework(String packageName) 
{ 
    Framework tmp = null; 
    try 
    { 
     tmp = (Framework) Class.forName(packageName).getConstructor().newInstance(); 
     tmp.SetActivity(((SonarFrameworkActivity) app)); 
    } catch (InstantiationException e) 
    { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (IllegalAccessException e) 
    { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (IllegalArgumentException e) 
    { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (InvocationTargetException e) 
    { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (NoSuchMethodException e) 
    { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (ClassNotFoundException e) 
    { 
     e.printStackTrace(); 
     Log.e("Class not found", "class doesn't exist or bad package name " + packageName); 
    } 
    return tmp; 
} 

构造是空的,所以仅存在称为的onCreate的方法,其实例和制备mHelper访问适用于Google Play服务的所有功能。

溶液(脏修复):

GooglePlayServices.java

public GooglePlayServices() 
    { 
     mHelper=getGameHelper(); 
    mHelper.setup(this); 
    }