从Eclipse到Android Studio:为什么在不构建Release时使用proguard.cfg?

时间:2015-04-21 01:46:28

标签: android-studio android-gradle proguard

所以,我一直在尝试将多项目(eclipse项目)应用程序的开发迁移到Android Studio(v1.1)。

通过文件导入>导入项目非常简单,没有发生任何事故。

然而,当我尝试Make / Rebuild项目时,我遇到了许多惊喜。第一个与Proguard无关,与源文件编码有关(最初在Windows-1252中),但我很快找到了使用此Windows-1252 > Reload > UTF-8 > Convert答案的解决方案。

然后,"错误:找不到符号类"对于我的com.comp.mod.X类。然后我通过转到包含该类的模块(Android Studio模块,以前是Eclipse项目)并将其添加到 proguard.cfg 中来解决它:

-keep public class com.comp.mod.X

这给我留下了一个"错误:无法找到符号变量"对于在上述类中定义的const BB。我通过添加以下 proguard.cfg 来解决这个问题:

-keepclassmembers class com.comp.mod.X {
    public static final boolean BB;
}

这让我只有一个"错误:找不到符号方法getPreferenceX()"。我通过添加相同的 -keepclassmembers 那个方法来解决这个问题,所以上面现在看起来:

-keepclassmembers class com.comp.mod.X {
    public static final boolean BB;
    public static java.lang.String getPreferenceX();
}

我以为我已经完成了,但令我沮丧的是,当我尝试重建项目时,我从项目中的其他模块收到了许多其他错误,所有类型都为"错误:找不到符号类/变量/方法"并与某些 proguard.cfg 相关。

我可以继续屠杀每个模块的proguard.cfg文件但是在这一点上我开始怀疑我做了一些根本错误的事情,因为那些proguard.cfg文件在Eclipse下完美运行。所以,

  1. 为什么突然间这些对Android Studio不再有用?
  2. 如果ProGuard runs only when you build your application in release mode,为什么基于Android Studio的构建抱怨"找不到符号"由于Proguard的混淆?
  3. 我错过了什么?

    注意:尝试"生成签名APK"。我所做的只是"重建项目"。

1 个答案:

答案 0 :(得分:2)

目前(截至2015-04-24),所有版本类型的 04-26 18:09:01.944: D/ServiceManager(22760): The name of the service is display 04-26 18:09:01.946: D/ServiceManager(22760): The name of the service is dropbox 04-26 18:09:01.949: D/jdwp(22760): sendBufferedRequest : len=0x57 04-26 18:09:01.952: W/asset(22760): AssetManager-->addDefaultAssets CIP path not exsit! 04-26 18:09:01.954: D/ServiceManager(22760): The name of the service is package 04-26 18:09:01.962: D/ServiceManager(22760): The name of the service is connectivity 04-26 18:09:02.031: D/ServiceManager(22760): The name of the service is window 04-26 18:09:02.033: D/ServiceManager(22760): The name of the service is accessibility 04-26 18:09:02.063: D/ServiceManager(22760): The name of the service is theme 04-26 18:09:02.067: W/asset(22760): AssetManager-->addDefaultAssets CIP path not exsit! 04-26 18:09:02.068: D/ThemeManager(22760): contextandroid.app.ContextImpl@41296280 04-26 18:09:02.069: D/ThemeManager(22760): create ThemeManager object 04-26 18:09:02.070: D/ThemeManager(22760): Res_clear() 04-26 18:09:02.107: W/asset(22760): AssetManager-->addDefaultAssets CIP path not exsit! 04-26 18:09:02.138: I/dalvikvm(22760): Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted 04-26 18:09:02.138: W/dalvikvm(22760): VFY: unable to resolve virtual method 11343: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V 04-26 18:09:02.138: D/dalvikvm(22760): VFY: replacing opcode 0x6f at 0x0000 04-26 18:09:02.139: I/dalvikvm(22760): Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll 04-26 18:09:02.139: W/dalvikvm(22760): VFY: unable to resolve virtual method 11349: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V 04-26 18:09:02.140: D/dalvikvm(22760): VFY: replacing opcode 0x6f at 0x0000 04-26 18:09:02.142: I/dalvikvm(22760): Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled 04-26 18:09:02.143: W/dalvikvm(22760): VFY: unable to resolve virtual method 9037: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V 04-26 18:09:02.143: D/dalvikvm(22760): VFY: replacing opcode 0x6e at 0x000e 04-26 18:09:02.154: I/dalvikvm(22760): Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations 04-26 18:09:02.154: W/dalvikvm(22760): VFY: unable to resolve virtual method 365: Landroid/content/res/TypedArray;.getChangingConfigurations ()I 04-26 18:09:02.155: D/dalvikvm(22760): VFY: replacing opcode 0x6e at 0x0002 04-26 18:09:02.157: I/dalvikvm(22760): Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType 04-26 18:09:02.157: W/dalvikvm(22760): VFY: unable to resolve virtual method 387: Landroid/content/res/TypedArray;.getType (I)I 04-26 18:09:02.157: D/dalvikvm(22760): VFY: replacing opcode 0x6e at 0x0002 04-26 18:09:02.194: D/ThemeManager(22760): Res_clear() 04-26 18:09:02.206: W/asset(22760): AssetManager-->addDefaultAssets CIP path not exsit! 04-26 18:09:02.231: D/AbsListView(22760): checkAbsListViewlLogProperty get invalid command 04-26 18:09:02.245: V/PhoneWindow(22760): DecorView setVisiblity: visibility = 4 04-26 18:09:02.245: D/ServiceManager(22760): The name of the service is input_method 04-26 18:09:02.251: D/ServiceManager(22760): The name of the service is power 04-26 18:09:02.257: V/PhoneWindow(22760): DecorView setVisiblity: visibility = 0 04-26 18:09:02.276: D/GN_FW_TextView(22760): onMeasure,mLayout=android.text.BoringLayout@41312d60 04-26 18:09:02.278: D/AndroidRuntime(22760): Shutting down VM 04-26 18:09:02.279: W/dalvikvm(22760): threadid=1: thread exiting with uncaught exception (group=0x40d249a8) 04-26 18:09:02.295: E/AndroidRuntime(22760): FATAL EXCEPTION: main 04-26 18:09:02.295: E/AndroidRuntime(22760): java.lang.NullPointerException 04-26 18:09:02.295: E/AndroidRuntime(22760): at com.example.gridviewmapexample.NikAdapter.getView(MainActivity.java:98) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.widget.AbsListView.obtainView(AbsListView.java:2207) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.widget.GridView.onMeasure(GridView.java:1040) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.View.measure(View.java:15635) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:681) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.View.measure(View.java:15635) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4919) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.View.measure(View.java:15635) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4919) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.support.v7.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:453) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.View.measure(View.java:15635) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4919) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.View.measure(View.java:15635) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4919) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1411) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.widget.LinearLayout.measureVertical(LinearLayout.java:698) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.View.measure(View.java:15635) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4919) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 04-26 18:09:02.295: E/AndroidRuntime(22760): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2200) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.View.measure(View.java:15635) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2165) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1249) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1443) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1139) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4872) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.Choreographer.doCallbacks(Choreographer.java:579) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.Choreographer.doFrame(Choreographer.java:548) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.os.Handler.handleCallback(Handler.java:800) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.os.Handler.dispatchMessage(Handler.java:100) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.os.Looper.loop(Looper.java:194) 04-26 18:09:02.295: E/AndroidRuntime(22760): at android.app.ActivityThread.main(ActivityThread.java:5410) 04-26 18:09:02.295: E/AndroidRuntime(22760): at java.lang.reflect.Method.invokeNative(Native Method) 04-26 18:09:02.295: E/AndroidRuntime(22760): at java.lang.reflect.Method.invoke(Method.java:525) 04-26 18:09:02.295: E/AndroidRuntime(22760): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 04-26 18:09:02.295: E/AndroidRuntime(22760): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 04-26 18:09:02.295: E/AndroidRuntime(22760): at dalvik.system.NativeStart.main(Native Method) 04-26 18:09:02.332: I/Process(22760): Sending signal. PID: 22760 SIG: 9 默认值minifyEnabled对于多模块项目不正确,其中一些模块(包括应用程序)依赖在其他模块上。这是由于bug #52962导致构建类型传播到库 - 它们始终构建为RELEASE。

欢迎解决此错误或其修复通知的建议。