我在我的应用程序中使用标准BillingService(即从sample application复制而不做更改).
但有时我的应用程序崩溃与logcat中的以下数据:
04-16 10:05:43.556: INFO/ActivityManager(96): Start proc tv.kinobaza.app for service tv.kinobaza.app/tv.kinobaza.billing.BillingService: pid=28748 uid=10081 gids={3003}
04-16 10:05:43.646: DEBUG/AndroidRuntime(28748): Shutting down VM
04-16 10:05:43.656: WARN/dalvikvm(28748): threadid=1: thread exiting with uncaught exception (group=0x400259f8)
04-16 10:05:43.656: ERROR/AndroidRuntime(28748): FATAL EXCEPTION: main
04-16 10:05:43.656: ERROR/AndroidRuntime(28748): java.lang.RuntimeException: Unable to start service tv.kinobaza.billing.BillingService@4632f578 with null: java.lang.NullPointerException
04-16 10:05:43.656: ERROR/AndroidRuntime(28748): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3282)
04-16 10:05:43.656: ERROR/AndroidRuntime(28748): at android.app.ActivityThread.access$3600(ActivityThread.java:135)
04-16 10:05:43.656: ERROR/AndroidRuntime(28748): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2211)
04-16 10:05:43.656: ERROR/AndroidRuntime(28748): at android.os.Handler.dispatchMessage(Handler.java:99)
04-16 10:05:43.656: ERROR/AndroidRuntime(28748): at android.os.Looper.loop(Looper.java:144)
04-16 10:05:43.656: ERROR/AndroidRuntime(28748): at android.app.ActivityThread.main(ActivityThread.java:4937)
04-16 10:05:43.656: ERROR/AndroidRuntime(28748): at java.lang.reflect.Method.invokeNative(Native Method)
04-16 10:05:43.656: ERROR/AndroidRuntime(28748): at java.lang.reflect.Method.invoke(Method.java:521)
04-16 10:05:43.656: ERROR/AndroidRuntime(28748): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-16 10:05:43.656: ERROR/AndroidRuntime(28748): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-16 10:05:43.656: ERROR/AndroidRuntime(28748): at dalvik.system.NativeStart.main(Native Method)
04-16 10:05:43.656: ERROR/AndroidRuntime(28748): Caused by: java.lang.NullPointerException
04-16 10:05:43.656: ERROR/AndroidRuntime(28748): at tv.kinobaza.billing.BillingService.onStart(Unknown Source)
04-16 10:05:43.656: ERROR/AndroidRuntime(28748): at android.app.Service.onStartCommand(Service.java:420)
04-16 10:05:43.656: ERROR/AndroidRuntime(28748): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3267)
04-16 10:05:43.656: ERROR/AndroidRuntime(28748): ... 10 more
04-16 10:05:43.736: DEBUG/SurfaceFlinger(96): Layer::setBuffers(this=0xb947a8),pid=96,w=1,h=1
04-16 10:05:43.736: DEBUG/SurfaceFlinger(96): Layer::setBuffers(this=0xb947a8),h=1
04-16 10:05:43.766: DEBUG/SurfaceFlinger(96): Layer::requestBuffer(this=0xb947a8),index=0,w=480,h=418 success
04-16 10:05:43.986: DEBUG/dalvikvm(28721): GC_FOR_MALLOC freed 9604 objects / 1369120 bytes in 102ms
这是相关的代码:
/**
* We don't support binding to this service,only starting the service.
*/
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onStart(Intent intent,int startId) {
handleCommand(intent,startId);
}
这有什么不对?
我注意到了 – 当设备在夜间睡觉时,一旦我开始使用它,它会在约5分钟内崩溃.
并且,以下是更多详细信息:BillingService从我的应用程序的“首选项”屏幕开始.这里是Preferences类的代码:
@Override
protected void onDestroy() {
mBillingService.unbind();
super.onDestroy();
}
UPD.也许,我应该在Main活动中启动此服务/解除绑定?
这是我的proguard.cfg:
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keep class com.android.vending.billing.**
-keepclasseswithmembernames class * {
native
最佳答案
所以你在proguard之后得到这个NPE而不是事先.
你必须混淆一些你不应该喜欢扩展应用程序/活动/服务的类
你不应该混淆这些类:
http://proguard.sourceforge.net/index.html#/manual/examples.html(转到例7)