我在我的应用程序中使用RoboGuice 3,并且在调试模式下minifiedEnabled设置为false时,一切正常。但是,如果我将minifiedEnabled设置为true,则注入的视图似乎为null:
NullPointerException: Attempt to invoke virtual method 'void android.support.v4.view.ViewPager.setAdapter(android.support.v4.view.PagerAdapter)' on a null object reference
我的ProGuard配置如下:
-dontobfuscate
-dontoptimize
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-dump class_files.txt
-printseeds seeds.txt
-printusage unused.txt
-printmapping mapping.txt
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-allowaccessmodification
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-repackageclasses ''
-dontwarn rx.internal.**
-dontwarn retrofit.appengine.UrlFetchClient
-dontwarn roboguice.**
-dontwarn org.roboguice.**
-dontwarn com.squareup.okhttp.**
-dontwarn okio.**
-dontwarn org.joda.convert.**
-keepattributes *Annotation*
-keepattributes Signature
-keepattributes Exceptions
-keepattributes InnerClasses
-keep class roboguice.**
-keep class com.google.inject.** { *; }
-keep class javax.inject.** { *; }
-keep class javax.annotation.** { *; }
-keep class retrofit.** { *; }
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
-keep class android.support.v4.** { *; }
-keep interface android.support.v4.** { *; }
-keep class com.squareup.okhttp.** { *; }
-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.google.inject.Binder
-keep class com.afollestad.materialdialogs.GravityEnum
-keep class org.rtschat.views.tab.SlidingTabLayout$TabColorizer
-dontnote com.android.vending.licensing.ILicensingService
-keepclassmembers class ** {
public void onEvent*(**);
}
-keepclassmembers class * {
@com.google.inject.Inject <init>(...);
}
-keepclassmembers class * {
void *(**On*Event);
}
-keepclasseswithmembers class * {
@retrofit.http.* <methods>;
}
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
-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 class **.R$* {
public static <fields>;
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep public class * {
public protected *;
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.examples.android.model.** { *; }
答案 0 :(得分:0)
我可以通过将其添加到我的proguard conf中来解决它:
-keepclassmembers class * {
...
@com.google.inject.InjectResource <init>(...);
@com.google.inject.Inject <fields>;
@com.google.inject.InjectView <fields>;
}
答案 1 :(得分:0)
我通过将其添加到我的proguard.txt来修复它,希望可以帮到你
-keepclassmembers class * {
@roboguice.inject.InjectView <fields>;
}