ons.util.Base64DecoderException: single trailing character at offset 19

本文记录了在实现应用内支付功能过程中遇到的一个崩溃问题及其解决方案。问题出现在交易完成后的验证阶段,原因是Base64解码失败导致的异常。通过检查代码并确保正确配置了Google Play公共密钥解决了该问题。

今天做应用内支付功能,发现官方给的Sample 运行后出现一个问题,在交易完成后,程序 crash,异常信息如下:


04-05 11:02:58.862: I/ActivityManager(144): Start proc com.example.dungeons for service com.example.dungeons/.BillingService: pid=1804 uid=10060 gids={}

04-05 11:02:58.922: E/Security(1804): Base64 decoding failed.
04-05 11:02:58.922: D/AndroidRuntime(1804): Shutting down VM
04-05 11:02:58.922: W/dalvikvm(1804): threadid=1: thread exiting with uncaught exception (group=0x401e4568)
04-05 11:02:58.932: E/AndroidRuntime(1804): FATAL EXCEPTION: main
04-05 11:02:58.932: E/AndroidRuntime(1804): java.lang.RuntimeException: Unable to start service com.example.dungeons.BillingService@406e76c8 with Intent { act=com.android.vending.billing.PURCHASE_STATE_CHANGED cmp=com.example.dungeons/.BillingService (has extras) }: java.lang.IllegalArgumentException: com.example.dungeons.util.Base64DecoderException: single trailing character at offset 19
04-05 11:02:58.932: E/AndroidRuntime(1804): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2060)
04-05 11:02:58.932: E/AndroidRuntime(1804): at android.app.ActivityThread.access$2800(ActivityThread.java:117)
04-05 11:02:58.932: E/AndroidRuntime(1804): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:994)
04-05 11:02:58.932: E/AndroidRuntime(1804): at android.os.Handler.dispatchMessage(Handler.java:99)
04-05 11:02:58.932: E/AndroidRuntime(1804): at android.os.Looper.loop(Looper.java:130)
04-05 11:02:58.932: E/AndroidRuntime(1804): at android.app.ActivityThread.main(ActivityThread.java:3694)
04-05 11:02:58.932: E/AndroidRuntime(1804): at java.lang.reflect.Method.invokeNative(Native Method)
04-05 11:02:58.932: E/AndroidRuntime(1804): at java.lang.reflect.Method.invoke(Method.java:507)
04-05 11:02:58.932: E/AndroidRuntime(1804): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
04-05 11:02:58.932: E/AndroidRuntime(1804): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
04-05 11:02:58.932: E/AndroidRuntime(1804): at dalvik.system.NativeStart.main(Native Method)
04-05 11:02:58.932: E/AndroidRuntime(1804): Caused by: java.lang.IllegalArgumentException: com.example.dungeons.util.Base64DecoderException: single trailing character at offset 19
04-05 11:02:58.932: E/AndroidRuntime(1804): at com.example.dungeons.Security.generatePublicKey(Security.java:209)
04-05 11:02:58.932: E/AndroidRuntime(1804): at com.example.dungeons.Security.verifyPurchase(Security.java:128)
04-05 11:02:58.932: E/AndroidRuntime(1804): at com.example.dungeons.BillingService.purchaseStateChanged(BillingService.java:493)
04-05 11:02:58.932: E/AndroidRuntime(1804): at com.example.dungeons.BillingService.handleCommand(BillingService.java:383)
04-05 11:02:58.932: E/AndroidRuntime(1804): at com.example.dungeons.BillingService.onStart(BillingService.java:360)
04-05 11:02:58.932: E/AndroidRuntime(1804): at android.app.Service.onStartCommand(Service.java:428)
04-05 11:02:58.932: E/AndroidRuntime(1804): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2047)
04-05 11:02:58.932: E/AndroidRuntime(1804): ... 10 more
04-05 11:02:58.932: E/AndroidRuntime(1804): Caused by: com.example.dungeons.util.Base64DecoderException: single trailing character at offset 19
04-05 11:02:58.932: E/AndroidRuntime(1804): at com.example.dungeons.util.Base64.decode(Base64.java:559)
04-05 11:02:58.932: E/AndroidRuntime(1804): at com.example.dungeons.util.Base64.decode(Base64.java:474)
04-05 11:02:58.932: E/AndroidRuntime(1804): at com.example.dungeons.util.Base64.decode(Base64.java:420)
04-05 11:02:58.932: E/AndroidRuntime(1804): at com.example.dungeons.Security.generatePublicKey(Security.java:199)

04-05 11:02:58.932: E/AndroidRuntime(1804): ... 16 more


solution:

是我自己的代码问题,我忘记了:第六条



Configuring and building the sample application

Before you can run the sample application, you need to configure it and build it by doing the following:

  1. Add your Google Play public key to the sample application code.

    This enables the application to verify the signature of the transaction information that is returned from Google Play. To add your public key to the sample application code, do the following:

    1. Log in to your Google Play publisher account.
    2. On the upper left part of the page, under your name, click Edit Profile.
    3. On the Edit Profile page, scroll down to the Licensing & In-app Billing panel.
    4. Copy your public key.
    5. Open src/com/example/dungeons/Security.java in the editor of your choice.

      You can find this file in the sample application's project folder.

    6. Add your public key to the following line of code:

      String base64EncodedPublicKey = "your public key here";

    7. Save the file.
  2. Change the package name of the sample application.

    The current package name is com.example.dungeons. Google Play does not let you upload applications with package names that contain com.example, so you must change the package name to something else.

  3. Build the sample application in release mode and sign it.

    To learn how to build and sign applications, see Building and Running.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值