`
tudusi
  • 浏览: 1056875 次
文章分类
社区版块
存档分类
最新评论

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

 
阅读更多

今天做应用内支付功能,发现官方给的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 Playpublisher account.
    2. On the upper left part of the page, under your name, clickEdit Profile.
    3. On the Edit Profile page, scroll down to theLicensing & In-app Billingpanel.
    4. Copy your public key.
    5. Opensrc/com/example/dungeons/Security.javain 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 iscom.example.dungeons. Google Play does not let you upload applications with package names that containcom.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, seeBuilding and Running.


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics