1

当我在 2.3.x 设备上运行我的应用程序时,在使用 proguard 缩小我的应用程序后出现此错误

10-17 11:36:10.045: WARN/System.err(17989): Caused by: java.lang.NullPointerException: Can't inject null value into class de.mobile.ui.BaseActivity.drawerLayout when field is not @Nullable
10-17 11:36:10.045: WARN/System.err(17989): at roboguice.inject.ViewListener$ViewMembersInjector.reallyInjectMemberViews(ViewListener.java:179)
10-17 11:36:10.045: WARN/System.err(17989): at roboguice.inject.ViewListener$ViewMembersInjector.reallyInjectMembers(ViewListener.java:138)
10-17 11:36:10.045: WARN/System.err(17989): at roboguice.inject.ViewListener$ViewMembersInjector.injectViews(ViewListener.java:246)
10-17 11:36:10.045: WARN/System.err(17989): at roboguice.inject.ContextScopedRoboInjector.injectViewMembers(ContextScopedRoboInjector.java:258)
10-17 11:36:10.045: WARN/System.err(17989): at de.mobile.ui.BaseActivity.onContentChanged(BaseActivity.java:484)
10-17 11:36:10.045: WARN/System.err(17989): at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:876)
10-17 11:36:10.045: WARN/System.err(17989): at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:267)
10-17 11:36:10.045: WARN/System.err(17989): at de.mobile.ui.webview.WebViewActivity.createUI(WebViewActivity.java:135)
10-17 11:36:10.045: WARN/System.err(17989): at de.mobile.ui.BaseActivity.onCreate(BaseActivity.java:157)
10-17 11:36:10.045: WARN/System.err(17989): at de.mobile.ui.webview.WebViewActivity.onCreate(WebViewActivity.java:76)

这是我的 WebViewActivity 代码

 @Override
    protected void createUI(final Bundle savedInstanceState) {
        LOG.debug("createUI");

        // hack to enable keyboard in webviews which is not usable on Android 2.3.x together with new MenuSlider
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
            final LinearLayout layout = new LinearLayout(this);
            final int CONTENT_VIEW_ID = 10101010; // any id
            layout.setId(CONTENT_VIEW_ID);
            layout.setBackgroundColor(Color.WHITE);

            setContentView(layout,
                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.MATCH_PARENT));

            FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
            fragmentTransaction.add(CONTENT_VIEW_ID, getWebViewFragment());
            fragmentTransaction.commit();

            return;
        }

        setContentView(R.layout.web_activity);

        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.add(R.id.web_layout, getWebViewFragment());
        fragmentTransaction.commit();

    }

在这里我在 BaseActivity 中得到 null

 @Override
    public void onContentChanged() {
        super.onContentChanged();
        RoboGuice.getInjector(this).injectViewMembers(this);
    }

这是我的proguard文件

-target 1.6
-ignorewarnings
-dontoptimize
-dontobfuscate
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose

-renamesourcefileattribute SourceFile

-keepattributes SourceFile,LineNumberTable,*Annotation*

-printmapping map.txt
-printseeds seed.txt
-printusage unused.txt

# The -optimizations option disables some arithmetic simplifications that Dalvik 1.0 and 1.5 can't handle. 
-optimizations !code/simplification/arithmetic 

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

-keep class de.mobile.** 
-keepclassmembers class de.mobile.** { public <init>(...); }
-keepclassmembers class de.mobile.** {
    *** set*(***);
    *** get*();
}
-keep class de.mobile.** {*;}
-keepclassmembers class de.mobile.** {*;}

-keep class de.mobile.test.R*
-keep class de.mobile.**.*Test { public void test* (); }

-keep class de.shop.api.** {*;}
-keepclassmembers class de.shop.api.** {*;}
-keepclassmembers class de.shop.api.client.** { public <init>(...); }

-keep class com.madgag.android.blockingprompt.**

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

-keepclassmembers class * extends android.app.Activity { public void *(android.view.View); }
-keepclassmembers class android.support.v4.app.Fragment { *** getActivity(); public *** onCreate(); public *** onCreateOptionsMenu(...); }

-keep public class * extends junit.framework.TestCase
-keep class junit.framework.**

-keepclassmembers class * { @com.google.inject.Provides *; @android.test.suitebuilder.annotation.* *; void test*(...); }
# There's no way to keep all @Observes methods, so use the On*Event convention to identify event handlers
-keepclassmembers class * { 
    void *(**On*Event); 
}

-keep public class roboguice.** {*;}
-keepclassmembers class roboguice.** {*;}
-keep class com.google.** {*;}
-keep class com.google.inject.Binder
-keep class com.google.inject.Key
-keep class com.google.inject.Provider
-keep class com.google.inject.TypeLiteral

-keepclassmembers class * { @com.google.inject.Inject <init>(...); }
-keepclassmembers class com.google.inject.assistedinject.FactoryProvider2 { *; }
-keepclassmembers class com.google.** {
    private void finalizeReferent();
    protected void finalizeReferent();
    public void finalizeReferent();
    void finalizeReferent();

    private *** startFinalizer(java.lang.Class,java.lang.Object);
    protected *** startFinalizer(java.lang.Class,java.lang.Object);
    public *** startFinalizer(java.lang.Class,java.lang.Object);
    *** startFinalizer(java.lang.Class,java.lang.Object);
}

-keepclassmembers class * extends com.actionbarsherlock.ActionBarSherlock { public <init>(...); }

-keepnames class * implements java.io.Serializable

-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    !static !transient <fields>;
    !private <fields>;
    !private <methods>;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

-keep class org.taptwo.android.widget.**
-keepclassmembers class org.taptwo.android.widget.** { public <init>(...); }
-keepclassmembers class org.taptwo.android.widget.** {
    *** set*(***);
    *** get*();
}

#ACRA specifics
# we need line numbers in our stack traces otherwise they are pretty useless
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

# ACRA needs "annotations" so add this... 
-keepattributes *Annotation*

# keep this class so that logging will show 'ACRA' and not a obfuscated name like 'a'.
# Note: if you are removing log messages elsewhere in this file then this isn't necessary
-keep class org.acra.ACRA {
    *;
}

# keep this around for some enums that ACRA needs
-keep class org.acra.ReportingInteractionMode {
    *;
}
-keepnames class org.acra.ReportField {
    *;
}

# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter
{
    public void addCustomData(java.lang.String,java.lang.String);
    public void putCustomData(java.lang.String,java.lang.String);
    public void removeCustomData(java.lang.String);
}

# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter
{
    public void handleSilentException(java.lang.Throwable);
}

# Trademob Tracking

-keep class com.loopj.** { *; }
-keep class com.trademob.tracking.** { *; }


-assumenosideeffects class android.util.Log {
    public static boolean isLoggable(java.lang.String, int);
    public static int v(...);
    public static int i(...);
    public static int w(...);
    public static int d(...);
    public static int e(...);
}

-assumenosideeffects class * implements org.slf4j.Logger {
    public void trace(...);
    public void debug(...);
    public void info(...);
    public void warn(...);
    public void error(...);
}
4

1 回答 1

-2

升级我的 Proguard 版本有帮助,我想我是因为 proguard 删除了一些注释。

于 2013-10-17T14:34:29.947 回答