Android Roboguice proguard 警告
Posted
技术标签:
【中文标题】Android Roboguice proguard 警告【英文标题】:Android Roboguice proguard warning 【发布时间】:2015-06-02 14:54:44 【问题描述】:我似乎无法在没有警告的情况下进行编译。这是警告:
Warning:roboguice.activity.RoboMapActivity: can't find superclass or interface com.google.android.maps.MapActivity
Warning:roboguice.activity.RoboSherlockActivity: can't find superclass or interface com.actionbarsherlock.app.SherlockActivity
Warning:roboguice.activity.RoboSherlockFragmentActivity: can't find superclass or interface com.actionbarsherlock.app.SherlockFragmentActivity
Warning:roboguice.activity.RoboSherlockListActivity: can't find superclass or interface com.actionbarsherlock.app.SherlockListActivity
Warning:roboguice.activity.RoboSherlockPreferenceActivity: can't find superclass or interface com.actionbarsherlock.app.SherlockPreferenceActivity
Warning:roboguice.activity.SherlockAccountAuthenticatorActivity: can't find superclass or interface com.actionbarsherlock.app.SherlockActivity
Warning:roboguice.fragment.RoboSherlockDialogFragment: can't find superclass or interface com.actionbarsherlock.app.SherlockDialogFragment
Warning:roboguice.fragment.RoboSherlockFragment: can't find superclass or interface com.actionbarsherlock.app.SherlockFragment
Warning:roboguice.fragment.RoboSherlockListFragment: can't find superclass or interface com.actionbarsherlock.app.SherlockListFragment
Warning:org.roboguice.shaded.goole.common.cache.Striped64: can't find referenced class sun.misc.Unsafe
Warning:org.roboguice.shaded.goole.common.cache.Striped64$1: can't find referenced class sun.misc.Unsafe
Warning:org.roboguice.shaded.goole.common.cache.Striped64$Cell: can't find referenced class sun.misc.Unsafe
Warning:roboguice.activity.RoboMapActivity: can't find referenced class com.google.android.maps.MapActivity
Warning:roboguice.activity.RoboMapActivity: can't find referenced method 'android.content.res.Resources getResources()' in program class roboguice.activity.RoboMapActivity
Warning:roboguice.activity.RoboMapActivity: can't find referenced class com.google.android.maps.MapActivity
Warning:roboguice.activity.RoboSherlockAccountAuthenticatorActivity: can't find referenced method 'void onRestart()' in program class roboguice.activity.SherlockAccountAuthenticatorActivity
Warning:roboguice.activity.RoboSherlockAccountAuthenticatorActivity: can't find referenced method 'void onStart()' in program class roboguice.activity.SherlockAccountAuthenticatorActivity
Warning:roboguice.activity.RoboSherlockAccountAuthenticatorActivity: can't find referenced method 'void onResume()' in program class roboguice.activity.SherlockAccountAuthenticatorActivity
Warning:roboguice.activity.RoboSherlockAccountAuthenticatorActivity: can't find referenced method 'void onPause()' in program class roboguice.activity.SherlockAccountAuthenticatorActivity
Warning:roboguice.activity.RoboSherlockAccountAuthenticatorActivity: can't find referenced method 'void onNewIntent(android.content.Intent)' in program class roboguice.activity.SherlockAccountAuthenticatorActivity
Warning:roboguice.activity.RoboSherlockAccountAuthenticatorActivity: can't find referenced method 'void onStop()' in program class roboguice.activity.SherlockAccountAuthenticatorActivity
Warning:roboguice.activity.RoboSherlockAccountAuthenticatorActivity: can't find referenced method 'void onDestroy()' in program class roboguice.activity.SherlockAccountAuthenticatorActivity
Warning:roboguice.activity.RoboSherlockAccountAuthenticatorActivity: can't find referenced method 'android.content.res.Resources getResources()' in program class roboguice.activity.RoboSherlockAccountAuthenticatorActivity
Warning:roboguice.activity.RoboSherlockAccountAuthenticatorActivity: can't find referenced method 'void onConfigurationChanged(android.content.res.Configuration)' in program class roboguice.activity.SherlockAccountAuthenticatorActivity
Warning:roboguice.activity.RoboSherlockAccountAuthenticatorActivity: can't find referenced method 'void onContentChanged()' in program class roboguice.activity.SherlockAccountAuthenticatorActivity
Warning:roboguice.activity.RoboSherlockAccountAuthenticatorActivity: can't find referenced method 'void onActivityResult(int,int,android.content.Intent)' in program class roboguice.activity.SherlockAccountAuthenticatorActivity
Warning:roboguice.activity.RoboSherlockAccountAuthenticatorActivity: can't find referenced method 'android.view.View onCreateView(java.lang.String,android.content.Context,android.util.AttributeSet)' in program class roboguice.activity.SherlockAccountAuthenticatorActivity
Warning:roboguice.activity.RoboSherlockAccountAuthenticatorActivity: can't find referenced method 'android.view.View onCreateView(android.view.View,java.lang.String,android.content.Context,android.util.AttributeSet)' in program class roboguice.activity.SherlockAccountAuthenticatorActivity
Warning:roboguice.activity.RoboSherlockActivity: can't find referenced class com.actionbarsherlock.app.SherlockActivity
Warning:roboguice.activity.RoboSherlockActivity: can't find referenced method 'android.content.res.Resources getResources()' in program class roboguice.activity.RoboSherlockActivity
Warning:roboguice.activity.RoboSherlockActivity: can't find referenced class com.actionbarsherlock.app.SherlockActivity
Warning:roboguice.activity.RoboSherlockFragmentActivity: can't find referenced class com.actionbarsherlock.app.SherlockFragmentActivity
Warning:roboguice.activity.RoboSherlockFragmentActivity: can't find referenced method 'android.content.res.Resources getResources()' in program class roboguice.activity.RoboSherlockFragmentActivity
Warning:roboguice.activity.RoboSherlockFragmentActivity: can't find referenced class com.actionbarsherlock.app.SherlockFragmentActivity
Warning:roboguice.activity.RoboSherlockListActivity: can't find referenced class com.actionbarsherlock.app.SherlockListActivity
Warning:roboguice.activity.RoboSherlockListActivity: can't find referenced method 'android.content.res.Resources getResources()' in program class roboguice.activity.RoboSherlockListActivity
Warning:roboguice.activity.RoboSherlockListActivity: can't find referenced class com.actionbarsherlock.app.SherlockListActivity
Warning:roboguice.activity.RoboSherlockPreferenceActivity: can't find referenced class com.actionbarsherlock.app.SherlockPreferenceActivity
Warning:roboguice.activity.RoboSherlockPreferenceActivity: can't find referenced method 'android.content.res.Resources getResources()' in program class roboguice.activity.RoboSherlockPreferenceActivity
Warning:roboguice.activity.RoboSherlockPreferenceActivity: can't find referenced class com.actionbarsherlock.app.SherlockPreferenceActivity
Warning:roboguice.activity.SherlockAccountAuthenticatorActivity: can't find referenced class com.actionbarsherlock.app.SherlockActivity
Warning:roboguice.activity.SherlockAccountAuthenticatorActivity: can't find referenced method 'android.content.Intent getIntent()' in program class roboguice.activity.SherlockAccountAuthenticatorActivity
Warning:roboguice.activity.SherlockAccountAuthenticatorActivity: can't find referenced class com.actionbarsherlock.app.SherlockActivity
Warning:roboguice.fragment.RoboSherlockDialogFragment: can't find referenced class com.actionbarsherlock.app.SherlockDialogFragment
Warning:roboguice.fragment.RoboSherlockDialogFragment: can't find referenced method 'android.support.v4.app.FragmentActivity getActivity()' in program class roboguice.fragment.RoboSherlockDialogFragment
Warning:roboguice.fragment.RoboSherlockDialogFragment: can't find referenced class com.actionbarsherlock.app.SherlockDialogFragment
Warning:roboguice.fragment.RoboSherlockFragment: can't find referenced class com.actionbarsherlock.app.SherlockFragment
Warning:roboguice.fragment.RoboSherlockFragment: can't find referenced method 'android.support.v4.app.FragmentActivity getActivity()' in program class roboguice.fragment.RoboSherlockFragment
Warning:roboguice.fragment.RoboSherlockFragment: can't find referenced class com.actionbarsherlock.app.SherlockFragment
Warning:roboguice.fragment.RoboSherlockListFragment: can't find referenced class com.actionbarsherlock.app.SherlockListFragment
Warning:roboguice.fragment.RoboSherlockListFragment: can't find referenced method 'android.support.v4.app.FragmentActivity getActivity()' in program class roboguice.fragment.RoboSherlockListFragment
Warning:roboguice.fragment.RoboSherlockListFragment: can't find referenced class com.actionbarsherlock.app.SherlockListFragment
Warning:there were 118 unresolved references to classes or interfaces.
You may need to add missing library jars or update their versions.
If your code works fine without the missing classes, you can suppress
the warnings with '-dontwarn' options.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning:there were 22 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile the code.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
:app:proguardAgmobileRelease FAILED
我尝试添加 actionarSherlock 所需的 Proguard,但没有帮助。如果项目在调试模式下运行良好,使用 --dontwarn 是否安全?
这是我的 Proguard 文件:
-target 1.6
-dontobfuscate
-dontoptimize
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-dump ../bin/class_files.txt
-printseeds ../bin/seeds.txt
-printusage ../bin/unused.txt
-printmapping ../bin/mapping.txt
# The -optimizations option disables some arithmetic simplifications that Dalvik 1.0 and 1.5 can't handle.
-optimizations !code/simplification/arithmetic
-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 class com.google.inject.Binder
-keepclassmembers class *
@com.google.inject.Inject <init>(...);
# 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 * 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*(...);
-keep class roboguice.**
-keep class org.roboguice.**
-keep public class AnnotationDatabaseImpl
【问题讨论】:
解决这个问题有运气吗? 【参考方案1】:仅使用我的 Proguard 文件中的这些行,我可以隐藏警告并编译我的应用程序。
也许这些行可以帮助其他人:
-dontwarn roboguice.**
-dontwarn org.roboguice.**
-keep class roboguice.** *;
-keep class org.roboguice.** *;
-keepattributes *Annotation*,Signature
-keep class com.google.inject.Binder
-keep public class com.google.inject.Inject
# keeps all fields and Constructors with @Inject
-keepclassmembers,allowobfuscation class *
@com.google.inject.Inject <fields>;
@com.google.inject.Inject <init>(...);
来源:
How to make Proguard ignore external libraries?
Injection with google guice does not work anymore after obfuscation with proguard
【讨论】:
【参考方案2】:尝试将此添加到您的 proguard 文件中。
-dontwarn roboguice.**
【讨论】:
那(加上-dontwarn org.roboguice.**
)将让它编译,但不能运行(在运行时仍然会崩溃)。以上是关于Android Roboguice proguard 警告的主要内容,如果未能解决你的问题,请参考以下文章
在android中使用带有片段的roboguice的任何简单示例?
注入框架RoboGuice使用:(A brief example of what RoboGuice does)