我在我的libgdx游戏中使用GameHelper类和IabHelper类实现Google Play商店。排行榜有效,但如果我尝试购买商品,Google Play商店会说:“需要授权,请使用Google帐户登录”。在我实施IabHelper之前,我的游戏向我展示了使用我的帐户登录,但现在我什么都没看到,但是没有登录我看不到排行榜或者? 我希望你能帮助我,为什么Google Play商店会向我显示错误
这是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)
答案 0 :(得分:2)
我会告诉你一些指示。这些你必须按照信中的说明,好吗?
您使用Google帐户登录开发者控制台,好吗?然后,转到手机中的设置>帐户并删除此帐户,如果您没有更多的Google帐户,则必须创建另一个用于测试inapp结算的Google帐户,然后将其添加到设置&gt ;帐户。请注意,重复一下,在手机中无法成为开发者控制台的Google帐户。使用另一个进行测试,您可以在完成工作后添加该帐户。
能够测试实际购买,不收费。您必须在开发者控制台中添加帐户测试gmail: (设置>帐户详细信息)
当您点击在应用内购买时,您必须添加信用卡,但请确保您可以看到下面的句子不收费:
上传已签名的apk(非调试版)非常重要,如果您不知道如何操作,请告诉我,我可以帮助您。
取消安装在手机中的当前apk,转到商店并通过商店下载测试版,是的,您可以通过此下载测试版,只需复制链接(https://play.google.com/store/apps/details?id=com.yourpackage.change.this),并确认测试版。要在Beta(或alpha)版本页面中添加测试电子邮件帐户,您需要使用测试Google帐户查看和下载测试版。 在你的" APK"这里的开发者控制台中的菜单,因为你可以添加测试电子邮件来查看商店中的apk(在商店中,只能看到apk,这里列出的人没有其他人):
在此处列出每个点后,如果您有任何问题请告诉我。 我希望这对你有用。
答案 1 :(得分:0)
你能在logcat中看到像“设置应用程序内结算问题:”的消息吗? 你的logcat会出现什么样的错误?你能发帖吗?
请记住购买您必须符合以下条件的物品:
完成这两个步骤后,显示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;
}