Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why NullPointerException happens with usage of standard BillingService?

I use standard BillingService in my application (i.e. copied from the sample application without changes). But sometimes my app crashes with the following data in 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), pid=96, w=1, h=1
04-16 10:05:43.766: DEBUG/SurfaceFlinger(96): Layer::requestBuffer(this=0xb947a8), index=0, pid=96, w=480, h=418 success
04-16 10:05:43.986: DEBUG/dalvikvm(28721): GC_FOR_MALLOC freed 9604 objects / 1369120 bytes in 102ms

Here is the related code:

/**
 * 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);
}

What is wrong here?

What I've noticed - when device sleeps during the night, once I start use it, it crashes within ~5 minutes.

And, here are more details: BillingService started from the Preferences screen of my application. Here the code from the Preferences class:

@Override
protected void onDestroy() {
mBillingService.unbind();
    super.onDestroy();
}

Upd. Probably, I should start this service/unbind in the Main activity?

Here is my 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 <methods>;
}

-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-libraryjars /lib/libGoogleAnalytics.jar
-libraryjars /lib/signpost-commonshttp4-1.2.1.1.jar
-libraryjars /lib/signpost-core-1.2.1.1.jar
-dontwarn org.apache.commons.codec.binary.Base64
like image 509
LA_ Avatar asked Oct 12 '22 06:10

LA_


1 Answers

So you get this NPE after proguard and not beforehand.

You must be obfuscating something that you shouldn't like a class extending Application/Activity/Service

You should not obfuscate these classes:

http://proguard.sourceforge.net/index.html#/manual/examples.html (Goto Example 7)

like image 92
Blundell Avatar answered Oct 27 '22 11:10

Blundell