【问题标题】:Android In App Billing crashes only in Samsung tab 10.1Android In App Billing 仅在三星标签 10.1 中崩溃
【发布时间】:2014-08-13 06:54:34
【问题描述】:

我在测试 In App Billing 时遇到了一个非常奇怪的问题。该应用程序仅在三星标签 10.1 中崩溃,并显示以下错误消息,我完全不知道它有什么问题:

java.lang.IllegalArgumentException: com.d.b.a.b: Bad Base64 input character at 0: 5(decimal)

   at com.test.iab.util.Security.verifyPurchase()
   at com.test.iab.util.Security.verifyPurchase()
   at com.test.iab.util.IabHelper.enableDebugLogging()
   at com.test.iab.util.IabHelper.enableDebugLogging()
   at com.test.iab.util.IabHelper.enableDebugLogging()
   at com.test.iab.util.IabHelper$2.run()
   at java.lang.Thread.run(Thread.java:856) Caused by: com.d.b.a.b: Bad Base64 input character at 0: 5(decimal)
   at com.test.iab.util.Base64.decode4to3()
   at com.test.iab.util.Base64.decode4to3()
   at com.test.iab.util.Base64.decode4to3()
   at com.test.iab.util.Security.verifyPurchase()
   at com.test.iab.util.Security.verifyPurchase()
   at com.test.iab.util.IabHelper.enableDebugLogging()
   at com.test.iab.util.IabHelper.enableDebugLogging()
   at com.test.iab.util.IabHelper.enableDebugLogging()
   at com.test.iab.util.IabHelper$2.run()
   at java.lang.Thread.run(Thread.java:856)

该应用程序在 Samsung S4、HTC one 和其他一些设备上运行良好,但仅在 Samsung tab 10.1 中崩溃。有没有人遇到过同样的问题?之所以在这里问,是因为我没有三星平板调试。

编辑:

我没有发布源代码的原因是因为源代码来自谷歌,我不知道究竟是哪个代码导致了问题。无论如何这里是可能与问题相关的代码:

public static boolean verifyPurchase(String base64PublicKey, String signedData, String signature) {
        if (TextUtils.isEmpty(signedData) || TextUtils.isEmpty(base64PublicKey) ||
                TextUtils.isEmpty(signature)) {
            Log.e(TAG, "Purchase verification failed: missing data.");
            return false;
        }

        PublicKey key = Security.generatePublicKey(base64PublicKey);
        return Security.verify(key, signedData, signature);
    }

【问题讨论】:

  • 你确定是设备而不是安卓版本(KitKat)?
  • 你能添加崩溃代码的sn-ps吗?指向代码行?
  • 没有人遇到过这种问题?

标签: android in-app-billing


【解决方案1】:

您的问题与您的公钥(您从 Google Play 复制)的解码有关。

我建议修改一下谷歌的代码,即函数:

public static byte[] decode(String s) throws Base64DecoderException {
    byte[] bytes = s.getBytes();
    return decode(bytes, 0, bytes.length);
}

这里的弱点是getBytes(),它应该将您的 Base64 编码字符串转换为字节数组。 getBytes() 使用默认系统字符集,适用于所有 Android 设备是 UTF-8。

Probably there's a bug in Galaxy Tab 10.1 related to default charset。请尝试使用显式字符集 UTF-8,例如:

byte[] bytes = s.getBytes("UTF-8");

【讨论】:

  • 感谢您的回复。我试试看。
  • 我太忙了,无法测试您的代码。但是我认为您的回答是合理的,尽管可以毫无问题地使用另一个开源代码。所以我会给你50分。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-18
  • 1970-01-01
  • 2018-03-16
  • 2011-08-25
  • 1970-01-01
相关资源
最近更新 更多