2017-08-21 56 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); 
    }