2015-10-16 132 views
1

我使用GameHelper類和IabHelper類在我的libgdx遊戲中實現了Google Play商店。排行榜可以工作,但如果我嘗試購買Google Play商店的商品時說:「需要授權,請使用Google帳戶登錄」。在我實施IabHelper之前,我的遊戲向我展示了使用我的帳戶登錄,但現在我什麼都看不到,但沒有登錄我看不到排行榜或? 我希望你能幫助我,爲什麼谷歌Play商店顯示我的錯誤Google Play商店錯誤libgdx遊戲

這裏是androidlauncher代碼:

public class AndroidLauncher extends AndroidApplication implements GameHelper.GameHelperListener, ActionResolver, IabInterface { 

private GameHelper gameHelper; 
IabHelper mHelper; 

@Override 
protected void onCreate (Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 

    if (gameHelper == null) { 
     gameHelper = new GameHelper(this, GameHelper.CLIENT_GAMES); 
     gameHelper.enableDebugLog(true); 
    } 
    gameHelper.setup(this); 

    String base64EncodedPublicKey = "{----}"; //here stand my key 

    mHelper = new IabHelper(this,base64EncodedPublicKey); 

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { 
     public void onIabSetupFinished(IabResult result) { 
      if (!result.isSuccess()) { 
       // Oh noes, there was a problem. 
       Log.d("IAB", "Problem setting up In-app Billing: " + result); 
      } 
      // Hooray, IAB is fully set up! 
      Log.d("IAB", "Billing Success: " + result); 
     } 
    }); 

    AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); 

    config.useAccelerometer = false; 
    config.useCompass = false; 
    config.useWakelock = true; 

    initialize(new mygame(this,this), config); 

} 

@Override 
public void onStart() { 
    super.onStart(); 
    gameHelper.onStart(this); 
} 

@Override 
public void onStop() { 
    super.onStop(); 
    gameHelper.onStop(); 
} 

@Override 
public void onSignInFailed() { 
    // TODO Auto-generated method stub 
    System.out.println("Sign in failed"); 
} 

@Override 
public void onSignInSucceeded() { 
    // TODO Auto-generated method stub 
    System.out.println("Sign in succeeded"); 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{ 
    super.onActivityResult(requestCode, resultCode, data); 
    gameHelper.onActivityResult(requestCode, resultCode, data); 

    if (mHelper != null) { 
     // Pass on the activity result to the helper for handling 
     if (mHelper.handleActivityResult(requestCode, resultCode, data)) { 
      Log.d("IAB", "onActivityResult handled by IABUtil."); 
     } 
    } 
} 

@Override 
public boolean getSignedInGPGS() { 
    return gameHelper.isSignedIn(); 
} 

@Override 
public void loginGPGS() { 
    try { 
     runOnUiThread(new Runnable(){ 
      public void run() { 
       gameHelper.beginUserInitiatedSignIn(); 
      } 
     }); 
    } catch (final Exception ex) { 
    } 
} 

@Override 
public void submitScoreGPGS(int score) { 
    Games.Leaderboards.submitScore(gameHelper.getApiClient(), "----", score); //---- is my leaderboardkey 
} 

@Override 
public void unlockAchievementGPGS(String achievementId) { 
    Games.Achievements.unlock(gameHelper.getApiClient(), achievementId); 
} 

@Override 
public void getLeaderboardGPGS() { 
    if (gameHelper.isSignedIn()) { 
     startActivityForResult(Games.Leaderboards.getLeaderboardIntent(gameHelper.getApiClient(), "----"), 100); //---- is my leaderboardkey 
    } 
    else if (!gameHelper.isConnecting()) { 
     loginGPGS(); 
    } 
} 

@Override 
public void getAchievementsGPGS() { 
    if (gameHelper.isSignedIn()) { 
     startActivityForResult(Games.Achievements.getAchievementsIntent(gameHelper.getApiClient()), 101); 
    } 
    else if (!gameHelper.isConnecting()) { 
     loginGPGS(); 
    } 
} 

@Override 
public void onDestroy() { 
    super.onDestroy(); 
    if (mHelper != null) mHelper.dispose(); 
    mHelper = null; 
} 

@Override 
public void buy_100_random_points() { 
    mHelper.launchPurchaseFlow(this,one_hundret_random_points,RC_Request,mPurchaseFinishedListener,"HANDLE_PAYLOADS"); 
} 

// Callback for when a purchase is finished 
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() { 
    public void onIabPurchaseFinished(IabResult result, Purchase purchase) { 
     if (purchase == null) return; 
     Log.d("IAB", "Purchase finished: " + result + ", purchase: " + purchase); 

     // if we were disposed of in the meantime, quit. 
     if (mHelper == null) return; 

     if (result.isFailure()) { 
      //complain("Error purchasing: " + result); 
      //setWaitScreen(false); 
      return; 
     } 
//   if (!verifyDeveloperPayload(purchase)) { 
//    //complain("Error purchasing. Authenticity verification failed."); 
//    //setWaitScreen(false); 
//    return; 
//   } 

     Log.d("IAB", "Purchase successful."); 

     if (purchase.getSku().equals(one_hundret_random_points)) { 
      // bought the premium upgrade! 
      Log.d("IAB", "Purchase is premium upgrade. Congratulating user."); 

      // Do what you want here maybe call your game to do some update 
      // 
      // Maybe set a flag to indicate that ads shouldn't show anymore 


     } 
    } 
}; 

} 

本教程幫助我:tutorial link

如果我點擊購買按鈕logcat以紅色顯示我:

10-19 06:33:27.980 2350-2361/? E/Parcel: Class not found when unmarshalling:  com.google.android.finsky.billing.lightpurchase.PurchaseParams 
10-19 06:33:27.980 2350-2361/? E/Parcel: java.lang.ClassNotFoundException: com.google.android.finsky.billing.lightpurchase.PurchaseParams 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at java.lang.Class.classForName(Native Method) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at java.lang.Class.forName(Class.java:204) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at java.lang.Class.forName(Class.java:169) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Parcel.readParcelableCreator(Parcel.java:2091) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Parcel.readParcelable(Parcel.java:2055) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Parcel.readValue(Parcel.java:1971) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Parcel.readMapInternal(Parcel.java:2255) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Bundle.unparcel(Bundle.java:223) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Bundle.getString(Bundle.java:1082) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.content.Intent.getStringExtra(Intent.java:4961) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at com.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:3761) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at com.android.server.am.ActivityStack.startActivityMayWait(ActivityStack.java:4977) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at com.android.server.am.ActivityManagerService.startActivityInPackage(ActivityManagerService.java:3391) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:254) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at com.android.server.am.ActivityManagerService.startActivityIntentSender(ActivityManagerService.java:3283) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:258) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2125) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Binder.execTransact(Binder.java:388) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at dalvik.system.NativeStart.run(Native Method) 
10-19 06:33:27.980 2350-2361/? E/Parcel: Caused by: java.lang.NoClassDefFoundError: com/google/android/finsky/billing/lightpurchase/PurchaseParams 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at java.lang.Class.classForName(Native Method)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at java.lang.Class.forName(Class.java:204)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at java.lang.Class.forName(Class.java:169)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Parcel.readParcelableCreator(Parcel.java:2091)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Parcel.readParcelable(Parcel.java:2055)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Parcel.readValue(Parcel.java:1971)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Parcel.readMapInternal(Parcel.java:2255)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Bundle.unparcel(Bundle.java:223)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Bundle.getString(Bundle.java:1082)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.content.Intent.getStringExtra(Intent.java:4961)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at com.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:3761)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at com.android.server.am.ActivityStack.startActivityMayWait(ActivityStack.java:4977)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at com.android.server.am.ActivityManagerService.startActivityInPackage(ActivityManagerService.java:3391)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:254)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at com.android.server.am.ActivityManagerService.startActivityIntentSender(ActivityManagerService.java:3283)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:258)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2125)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Binder.execTransact(Binder.java:388)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at dalvik.system.NativeStart.run(Native Method)  
10-19 06:33:27.980 2350-2361/? E/Parcel: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.finsky.billing.lightpurchase.PurchaseParams" on path: . 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:64) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 
10-19 06:33:27.980 2350-2361/? E/Parcel:  at java.lang.Class.classForName(Native Method)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at java.lang.Class.forName(Class.java:204)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at java.lang.Class.forName(Class.java:169)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Parcel.readParcelableCreator(Parcel.java:2091)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Parcel.readParcelable(Parcel.java:2055)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Parcel.readValue(Parcel.java:1971)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Parcel.readMapInternal(Parcel.java:2255)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Bundle.unparcel(Bundle.java:223)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Bundle.getString(Bundle.java:1082)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.content.Intent.getStringExtra(Intent.java:4961)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at com.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:3761)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at com.android.server.am.ActivityStack.startActivityMayWait(ActivityStack.java:4977)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at com.android.server.am.ActivityManagerService.startActivityInPackage(ActivityManagerService.java:3391)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:254)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at com.android.server.am.ActivityManagerService.startActivityIntentSender(ActivityManagerService.java:3283)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:258)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2125)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at android.os.Binder.execTransact(Binder.java:388)  
10-19 06:33:27.980 2350-2361/? E/Parcel:  at dalvik.system.NativeStart.run(Native Method)  

回答

2

我會告訴你一些指導。這些你必須遵守這封信的指示,好嗎?

  • 您使用Google帳戶登錄開發者控制檯,好嗎?然後,轉到手機中的設置>帳戶並刪除此帳戶,如果您沒有更多的Google帳戶,那麼您必須創建另一個Google帳戶來測試inapp帳單,然後將其添加到手機的設置>帳戶中。請記住,重複一遍,在您的手機中不能是開發者控制檯的Google帳戶。使用另一個進行測試,您可以在完成工作後稍後添加帳戶。

  • 爲了能夠測試實際購買,並且不收取費用。你必須添加帳戶測試的Gmail在這裏開發者控制檯: (設置>帳戶信息)

enter image description here

你將不得不在瞬間增加信用卡當你點擊購買裏面你應用程序,但讓你確信你可以看到下面的句子不收:

enter image description here

  • 上傳已簽名的apk文件非常重要(不是調試版),如果您不知道如何操作,請告訴我,我可以幫助您。

  • 取消您的手機中安裝的當前apk安裝程序,進入商店並通過商店下載測試版,是的,您可以通過此下載測試版,只需複製鏈接(https://play.google.com/store/apps/details?id=com.yourpackage.change.this),然後確認測試版。爲了能夠查看並下載測試版本的測試Google帳戶,您需要在測試版(或Alpha版)頁面中添加測試電子郵件帳戶。 在您的開發者控制檯的「APK」菜單中,您可以在這裏添加測試電子郵件,以查看商店中的apk(在商店中,只能看到apk,此處沒有其他人可以看到的人):

enter image description here

當你做了每個點列表在這裏,如果你有任何問題,讓我知道。 我希望這對你有用。

+0

謝謝,但你看到我騎購買問題已經完成?我希望。購買系統現在不是我的問題,問題是現在的谷歌如果我在Android工作室開始我的遊戲,但是如果我上傳apk上的谷歌播放,我下載它,我成爲一個錯誤 – wiifree

+0

好吧,我不明白它,現在它的工作,播放服務和購買服務。我不明白谷歌。非常感謝你的幫助 – wiifree

+0

@wiifree好的,這聽起來不錯。如果你不介意,請爲我的答案投票,以獲得更多的聲譽,只是一點點的獎勵,以保持積極主動,並繼續幫助別人。再見。 – josemwarrior

0

你能否在logcat中看到類似「問題設置應用內結算:」??的消息? 你的logcat顯示什麼樣的錯誤?你可以發佈嗎?

記得買您擁有的項目,以滿足幾個條件:

  • 您的APK必須上傳到您的谷歌Play開發者控制檯,它沒有必要,你公開發表您的APK,您可以選擇「測試版「,只有你可以下載。 (https://play.google.com/apps/publish/)確保您使用您的最終(非調試)證書和私鑰簽署您的應用程序。
  • 如果您的應用有權購買(<使用權限android:name =「com.android.vending.BILLING」/>),則在Android-manifiest.xml中,您的apk面板中的子菜單將被解鎖在Google Play開發者控制檯中,您必須定義要購買的商品。 http://developer.android.com/training/in-app-billing/list-iab-products.html#DefineProducts

當你完成這兩個步驟,並顯示你的痕跡的logcat中,如:

Log.d ("IAB", "Problem setting up In-app Billing:" + result); 

然後我會繼續幫助你。

並請更改此:

if (result.isFailure()) { 
     //complain("Error purchasing: " + result); 
     //setWaitScreen(false); 
     return; 
    } 

此:

if (result.isFailure()) { 
     Log.d ("IAB", "Problem with the purchase:" + result); 
     return; 
    } 
+0

我測試了一些。如果我刪除base64EncodedPublicKey這個字符串base64EncodedPublicKey =「」;它向我展示了同樣的錯誤。就好像我的遊戲不會連接到我的帳戶以獲取應用內商品 – wiifree

+0

,但logcat對此問題沒有顯示任何設置應用內結算的信息。它不顯示在日誌中。它顯示此D/IAB:帳單成功:IabResult:安裝成功。 (響應:0:好) – wiifree

+0

在開始但後來IAB什麼也沒有顯示 – wiifree