NullPointerException异常使用ProGuard [英] NullPointerException with proguard

查看:427
本文介绍了NullPointerException异常使用ProGuard的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Proguard的与我的应用程序,我得到 NullPointerException异常发送到我的开发者控制台随机用户。当我做一回扫,这似乎是一个问题, AD浏览报我使用。在令人困惑的事情是,错误是发生在我的服务其中,很明显,不使用的广告。不知道是否 Proguard的正在做的事情为code或内容。这是去混淆的堆栈跟踪:

 显示java.lang.NullPointerException
在com.google.ads.internal.AdWebView $ 1.A(来源不明)
在com.app.base.MainService.onHandleIntent(来源不明)
在android.app.IntentService $ ServiceHandler.handleMessage(IntentService.java:59)
在android.os.Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loop(Looper.java:130)
在android.os.HandlerThread.run(HandlerThread.java:60)
 

MainService 是我的服务,然后显示,从我可以告诉,一个 NullPointerException异常 com.google.ads.internal.AdView

最近我意识到我没有叫破坏()在我的AD浏览报,所以我说这对活动正在使用它:

  @覆盖
 公共无效的onDestroy()
 {
    如果(AD浏览报!= NULL)
      adView.destroy();

    super.onDestroy();
  }
 

不知道这会导致问题。

这是我的 proguard.cfg 文件:

  -optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dont preverify
-verbose
-optimizations!code /简/算术,!现场/ * ,!类/合并/ *

-libraryjars C:\工作区\ JAR文件\ GoogleAdMobAdsSdk-6.0.0.jar
-libraryjars C:\工作区\ JAR文件\ Android的支持,v4.jar

-repackageclasses''
-allowaccessmodification
-optimizations!code /简/算术
-keepattributes *注释*

-dontwarn ** CompatHoneycomb
-dontwarn ** CompatHoneycombMR2
-dontwarn ** CompatCreatorHoneycombMR2

-keep公共类*扩展android.app.Activity
-keep公共类*扩展android.app.Application
-keep公共类*扩展android.app.Service
-keep公共类*扩展android.content.BroadcastReceiver
-keep公共类*扩展android.content.ContentProvider
-keep公共类*扩展android.app.Fragment

-keep类android.support.v4.app ** {*。 }
-keep接口android.support.v4.app ** {*。 }
-keep类com.actionbarsherlock ** {*。 }
-keep接口com.actionbarsherlock ** {*。 }
-keep类com.app.base.KeywordsFragment
-keep类com.app.base.ListingFragment

-keep公共类*扩展android.view.View {
    公共和LT; INIT>(android.content.Context);
    公共和LT; INIT>(android.content.Context,android.util.AttributeSet);
    公共和LT; INIT>(android.content.Context,android.util.AttributeSet,INT);
    公共无效套*(......);
}

#这将避免从XML布局中引用被删除了所有的onClick监听器
-keepclassmembers类*扩展android.app.Activity {
       公共无效*(android.view.View);
}

-keepclasseswithmembers类* {
    公共和LT; INIT>(android.content.Context,android.util.AttributeSet);
}

-keepclasseswithmembers类* {
    公共和LT; INIT>(android.content.Context,android.util.AttributeSet,INT);
}

-keepclassmembers类*实现android.os.Parcelable {
    静态android.os.Parcelable $造物主创造者;
}

-keepclassmembers类** R $ * {
    公共静态<领域取代;
}

-dontwarn android.support。**
 

更新:

在看着Proguard的手册,我发现这是在故障排除部分:

MissingResourceException异常或NullPointerException异常     您处理code可能无法找到一些资源文件。 ProGuard的简单复制的资源从输入罐子到输出罐子文件结束了。

想知道如果我需要使用 keepdirectories

更新2:

我想知道如果加入这将解决我的问题。因为我无法重现该错误我自己,我不能对此进行测试,但。它只是发生随机用户:

  -keep类com.google.ads **。{*;}
 

更新3:

追溯其他错误,我得到了开发者控制台后,他们似乎都与com.google.ads,例如:

 显示java.lang.NullPointerException
 在com.google.ads.InterstitialAd.a(来源不明)
 

解决方案

我想用下面应该工作:

  -keepattributes *注释*
-keep公共类com.google.ads。**
 

注释块可能会在那里了。我认为这个问题是,SDK有它自己的ProGuard的,并且依赖于它的公共类不能由开发商proguarded。

I'm using Proguard with my apps and I'm getting NullPointerExceptions sent to my Developer Console for random users. When I do a ReTrace, it seems to be an issue with the AdView I'm using. The confusing thing is, the error is happening in my Service which, obviously, doesn't use ads. Not sure if Proguard is doing something to the code or what. This is the de-obfuscated stack trace:

java.lang.NullPointerException
at com.google.ads.internal.AdWebView$1.a(Unknown Source)
at com.app.base.MainService.onHandleIntent(Unknown Source)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.os.HandlerThread.run(HandlerThread.java:60)

MainService is my service, which is then showing, from what I can tell, a NullPointerException related to com.google.ads.internal.AdView.

I recently realized I wasn't calling destroy() on my AdView, so I added this to the Activities that are using it:

 @Override
 public void onDestroy() 
 {
    if (adView != null)
      adView.destroy();

    super.onDestroy();
  }

Not sure if that would cause the issue.

This is my proguard.cfg file:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-libraryjars C:\Workspace\JARs\GoogleAdMobAdsSdk-6.0.0.jar
-libraryjars C:\Workspace\JARs\android-support-v4.jar

-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*

-dontwarn **CompatHoneycomb
-dontwarn **CompatHoneycombMR2
-dontwarn **CompatCreatorHoneycombMR2

-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.Fragment

-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-keep class com.app.base.KeywordsFragment
-keep class com.app.base.ListingFragment

-keep public class * extends android.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}

# This will avoid all the onClick listeners referenced from XML Layouts from being removed
-keepclassmembers class * extends android.app.Activity { 
       public void *(android.view.View); 
}

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

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

-keepclassmembers class * implements android.os.Parcelable {
    static android.os.Parcelable$Creator CREATOR;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

-dontwarn android.support.**

UPDATE:

After looking at the Proguard manual, I found this is in the troubleshooting section:

"MissingResourceException or NullPointerException Your processed code may be unable to find some resource files. ProGuard simply copies resource files over from the input jars to the output jars."

Wonder if I need to use keepdirectories

UPDATE 2:

I'm wondering if adding this will fix my issue. I can't test this though because I am unable to recreate the error myself. It is only happening for random users:

 -keep class com.google.ads.** {*;}

UPDATE 3:

After retracing other errors I'm getting in the Developer Console, they all seem to be related to com.google.ads, eg:

 java.lang.NullPointerException
 at com.google.ads.InterstitialAd.a(Unknown Source)

解决方案

I think using the following should work:

-keepattributes *Annotation*
-keep public class com.google.ads.**

The annotation piece may be in there already. I think the issue is that the SDK has it's own proguard, and relies on it's public classes to not be proguarded by the developer.

这篇关于NullPointerException异常使用ProGuard的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆