Proguard似乎删除了路径中包含的整个包 [英] Proguard seeming to remove an entire packages that are included in the path

查看:231
本文介绍了Proguard似乎删除了路径中包含的整个包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Proguard来模糊我的代码,并使其更小。我建立使用Eclipse,并有一段时间。我最近有一个在调试版本中工作的构建,我正在尝试发布。我一直在努力在最后一天的大部分时间内完成这项工作,当我尝试使用发布的版本运行我的代码时,我会收到以下错误(如果有帮助,我可以产生更多的)。


02-25 16:39:58.844:E / AndroidRuntime(27593):导致:
java.lang.ClassNotFoundException:没有找到类
com.kd7uiy.hamfinder.MainActivity路径:DexPathList [[zip file
/data/app/com.kd7uiy.hamfinder-2.apk\"],nativeLibraryDirectories=[/data/app -lib / com.kd7uiy.hamfinder-2,
/ vendor / lib,/ system / lib]]


真奇怪的是,我没有改变我的proguard文件,至少不是我第一次这样做。我一直在玩它,看看是否可以得到任何东西让它上班,但似乎没有什么办法。自从构建之后,我已经添加了一个新的库到我的代码库,,即:


  1. -Xmx256m 增加到 -Xmx2048m 在eclipse.ini文件中。

  2. 将-XX:MaxPermSize = 256m添加到eclipse.ini文件。

  3. -Xms256M -Xmx512M 添加到JVM中,在Window-> Preferences - > Java - > Installed JREs - >点击JRE - > Edit

  4. 删除 -ignorewarnings 。这只是掩盖了这个问题,如果我没有这样做,我会早点弄清楚发生了什么事情。 -dontwarn 为已知问题(一个lib我可以选择使用 java.awt ,但不是我使用的东西...

  5. 尝试多次以使构建工作,如果没有控制台错误,您会知道它有效。

  6. 使用Ant / Gradle make

这些步骤有所帮助,但最后我能够修复它,尽管我做了几件事情一次,任何一个都可以解决问题,我做了以下事情:


  1. 正确设置依赖关系的顺序,以便第一个库包含的是首先编译的,依此类推,我有几个依赖图书馆的图书馆,所以...

  2. 我的一个项目的代码是/ java而不是/ src可能会导致一些混乱,我不确定。

  3. 确保所有图书馆都针对最新的Android版本。

我的project.properties现在看起来像这样:

  proguard.config = $ {sdk.dir} /工具/ progu ard / proguard-android.txt:proguard-project.txt 

#项目目标。
target = android-19
android.library.reference.1 = .. / .. / .. / workspace / android-support-v7-appcompat
android.library.reference.2 = .. \\..\\\\\workspace\\google- play-services_lib
android.library.reference.3 = .. \\..\\ \\\..\\Documents\\GitHub\\android-styleed-dialogs\\library\\src\\main
android.library.reference.4 = .. \\..\\..\\Documents\\GitHub\\drag-sort-listview\\library
android.library.reference.5 = .. \\..\\..\\Documents\\GitHub\\\\\\\\\\


I use Proguard to obfuscate my code, and make it smaller. I build using Eclipse, and have for some time. I've recently had a build that works great in the debug version, which I'm trying to release. I've been trying to get this done for most of the last day, and I keep getting the following error when I try to run my code using the released build (I can produce more if it helps).

02-25 16:39:58.844: E/AndroidRuntime(27593): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.kd7uiy.hamfinder.MainActivity" on path: DexPathList[[zip file "/data/app/com.kd7uiy.hamfinder-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.kd7uiy.hamfinder-2, /vendor/lib, /system/lib]]

The really strange thing is, I didn't change my proguard file, at least not the first time I did this. I've since been playing with it, to see if I can get anything to get it to work, but nothing seems to do the trick. Since this build, I have added a new library to my code base, the Google Maps utility library. My last build was only a few days ago.

Trying to troubleshoot this issue, I've found that there is an entire folder that doesn't appear on the path list. I see this folder in the compiled binary classes, but they don't survive the process. If I stop using Proguard, the release version works as intended.

My code relies on 6 packages that are in my /src directory. I did not significantly alter this structure for this release, although I probably added a file or two to various folders, and might have moved a folder or two. The 6 packages are:

com.kd7uiy.hamfinder
com.kd7uiy.hamfinder.dialogs
com.kd7uiy.hamfinder.ObserverOutPairs
com.kd7uiy.hamfinder.Subjects
com.kd7uiy.library
com.robobunny

Of these, I can find no direct evidence of the following packages in my proguard mapping file, at least for this particular trial

com.kd7uiy.hamfinder
com.kd7uiy.hamfinder.ObserverOutPairs
com.kd7uiy.hamfinder.Subjects

Some have a few variable names referenced, but not evidence of the entire package being included. I've checked the .dex file, which does not contain the missing packages either. I should add, sometimes seemingly randomly some of the other packages will appear, but never the com.kd7uiy.hamfinder, where my MainActivity resides. Sometimes none of them appear.

Here's my project.properties file:

# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-19
android.library.reference.1=..\\..\\..\\Documents\\GitHub\\android-maps-utils\\library
android.library.reference.2=..\\..\\..\\..\\..\\Program Files (x86)\\Android\\android-sdk\\extras\\android\\support\\v7\\appcompat
android.library.reference.3=..\\..\\..\\..\\..\\Program Files (x86)\\Android\\android-sdk\\extras\\google\\google_play_services\\libproject\\google-play-services_lib
android.library.reference.4=..\\..\\..\\Documents\\GitHub\\android-styled-dialogs\\library\\src\\main
android.library.reference.5=..\\..\\..\\Documents\\GitHub\\drag-sort-listview\\library

And my original proguard-project.txt file, which has been shown not to work.

-keep class com.kd7uiy.hamfinder.MainSettingsActivity$GeneralPreferenceFragment
-keep class com.kd7uiy.hamfinder.MainSettingsActivity$LocationPreferenceFragment
-keep class com.android.vending.billing.**
-keep class jsqlite.** { *;}
-ignorewarnings

I did change it to add the appropriate Google Maps required changes for Proguard as well. Neither worked.

-keep class com.kd7uiy.hamfinder.MainSettingsActivity$GeneralPreferenceFragment
-keep class com.kd7uiy.hamfinder.MainSettingsActivity$LocationPreferenceFragment
-keep class com.android.vending.billing.**
-keep class jsqlite.** { *;}
-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

#-keep class com.kd7uiy.hamfinder.AbstractReverseGeoCoder
-keep class com.kd7uiy.hamfinder.AbstractWebReverseGeoCoder

-dontwarn java.awt.**

-ignorewarnings

For reference here's my proguard-android.txt file, found in the correct location.

# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose

# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize
-dontpreverify
# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.

-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}

# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
   void set*(***);
   *** get*();
}

# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

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

# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**

Here's a snapshot of my files

And here's my build path

Looking at some other files, I have seen evidence of the files in the /bin/proguard.txt file, but they just seem to disappear after that. The compiled size isn't noticeably smaller either, but that could be because I have far more non-code stuff than code, it'd be hard to detect a difference of a few java files. Here's the entire /bin/proguard.txt file.

# view res/layout/activity_main.xml #generated:14
-keep class android.support.v4.view.ViewPager { <init>(...); }

# view large-land\res/layout-large-land/activity_main.xml #generated:2
# view large-port\res/layout-large-port/activity_main.xml #generated:2
# view res/layout/activity_main.xml #generated:1
# view xlarge-land\res/layout-xlarge-land/activity_main.xml #generated:2
# view xlarge-port\res/layout-xlarge-port/activity_main.xml #generated:2
-keep class android.support.v4.widget.DrawerLayout { <init>(...); }

# view res/layout/abc_action_menu_item_layout.xml #generated:17
-keep class android.support.v7.internal.view.menu.ActionMenuItemView { <init>(...); }

# view res/layout/abc_action_menu_layout.xml #generated:17
-keep class android.support.v7.internal.view.menu.ActionMenuView { <init>(...); }

# view res/layout/abc_expanded_menu_layout.xml #generated:17
-keep class android.support.v7.internal.view.menu.ExpandedMenuView { <init>(...); }

# view res/layout/abc_list_menu_item_layout.xml #generated:17
# view res/layout/abc_popup_menu_item_layout.xml #generated:17
-keep class android.support.v7.internal.view.menu.ListMenuItemView { <init>(...); }

# view res/layout/abc_action_bar_decor_include.xml #generated:19
# view res/layout/abc_action_bar_decor_include.xml #generated:47
# view res/layout/abc_action_bar_decor_overlay.xml #generated:30
# view res/layout/abc_action_bar_decor_overlay.xml #generated:53
-keep class android.support.v7.internal.widget.ActionBarContainer { <init>(...); }

# view res/layout/abc_action_bar_decor_include.xml #generated:31
# view res/layout/abc_action_bar_decor_overlay.xml #generated:41
# view res/layout/abc_action_mode_bar.xml #generated:19
-keep class android.support.v7.internal.widget.ActionBarContextView { <init>(...); }

# view res/layout/abc_action_bar_decor_overlay.xml #generated:17
-keep class android.support.v7.internal.widget.ActionBarOverlayLayout { <init>(...); }

# view res/layout/abc_action_bar_decor_include.xml #generated:25
# view res/layout/abc_action_bar_decor_overlay.xml #generated:36
-keep class android.support.v7.internal.widget.ActionBarView { <init>(...); }

# view res/layout/abc_action_bar_home.xml #generated:17
-keep class android.support.v7.internal.widget.ActionBarView$HomeView { <init>(...); }

# view res/layout/abc_action_bar_tabbar.xml #generated:17
# view res/layout/abc_activity_chooser_view.xml #generated:19
-keep class android.support.v7.internal.widget.LinearLayoutICS { <init>(...); }

# view v11\res/layout-v11/abc_action_bar_decor.xml #generated:17
-keep class android.support.v7.internal.widget.NativeActionModeAwareLayout { <init>(...); }

# view res/layout/abc_action_bar_tab.xml #generated:17
-keep class android.support.v7.internal.widget.ScrollingTabContainerView$TabView { <init>(...); }

# view res/layout/abc_search_view.xml #generated:85
-keep class android.support.v7.widget.SearchView$SearchAutoComplete { <init>(...); }

# view AndroidManifest.xml #generated:72
-keep class com.google.analytics.tracking.android.CampaignTrackingReceiver { <init>(...); }

# view AndroidManifest.xml #generated:70
-keep class com.google.analytics.tracking.android.CampaignTrackingService { <init>(...); }

# view AndroidManifest.xml #generated:56
-keep class com.google.android.gms.ads.AdActivity { <init>(...); }

# view large-land\res/layout-large-land/activity_main.xml #generated:13
# view large-port\res/layout-large-port/activity_main.xml #generated:13
# view res/layout/activity_main.xml #generated:26
# view xlarge-land\res/layout-xlarge-land/activity_main.xml #generated:13
# view xlarge-port\res/layout-xlarge-port/activity_main.xml #generated:15
-keep class com.google.android.gms.ads.AdView { <init>(...); }

# view res/layout/google_map_dialog_preference.xml #generated:7
-keep class com.google.android.gms.maps.MapFragment { <init>(...); }

# view res/layout/google_map.xml #generated:2
# view res/layout/google_map_support_dialog_preference.xml #generated:7
-keep class com.google.android.gms.maps.SupportMapFragment { <init>(...); }

# view res/layout/text_bubble.xml #generated:8
-keep class com.google.maps.android.ui.RotationLayout { <init>(...); }

# view large-land\res/layout-large-land/activity_main.xml #generated:24
# view large-port\res/layout-large-port/activity_main.xml #generated:24
# view xlarge-land\res/layout-xlarge-land/activity_main.xml #generated:24
# view xlarge-port\res/layout-xlarge-port/activity_main.xml #generated:26
-keep class com.kd7uiy.hamfinder.LocationDisplayFragment { <init>(...); }

# view large-land\res/layout-large-land/activity_main.xml #generated:34
# view large-port\res/layout-large-port/activity_main.xml #generated:44
# view xlarge-land\res/layout-xlarge-land/activity_main.xml #generated:35
# view xlarge-port\res/layout-xlarge-port/activity_main.xml #generated:46
-keep class com.kd7uiy.hamfinder.LogBookFragment { <init>(...); }

# view AndroidManifest.xml #generated:40
-keep class com.kd7uiy.hamfinder.MainActivity { <init>(...); }

# view AndroidManifest.xml #generated:49
-keep class com.kd7uiy.hamfinder.MainSettingsActivity { <init>(...); }

# view res/xml/pref_location.xml #generated:43
-keep class com.kd7uiy.hamfinder.MapDialogPreference { <init>(...); }

# view large-land\res/layout-large-land/activity_main.xml #generated:45
# view large-port\res/layout-large-port/activity_main.xml #generated:33
# view xlarge-land\res/layout-xlarge-land/activity_main.xml #generated:47
# view xlarge-port\res/layout-xlarge-port/activity_main.xml #generated:35
-keep class com.kd7uiy.hamfinder.dialogs.SimpleLogFragment { <init>(...); }

# view res/layout/list_item_simple_checkable.xml #generated:3
# view v11\res/layout-v11/list_item_simple_checkable.xml #generated:3
-keep class com.kd7uiy.library.CheckableLinearLayout { <init>(...); }

# view AndroidManifest.xml #generated:59
-keep class com.kd7uiy.library.ManageAddOnPurchaseActivity { <init>(...); }

# view res/layout/mistake_form.xml #generated:14
-keep class com.kd7uiy.library.MapSpinner { <init>(...); }

# view res/layout/offline_map_dialog_preference.xml #generated:6
-keep class com.kd7uiy.library.SimpleMapView { <init>(...); }

# view res/xml/pref_general.xml #generated:19
# view res/xml/pref_general.xml #generated:26
# view res/xml/pref_location.xml #generated:4
-keep class com.kd7uiy.library.SortableListPreference { <init>(...); }

# view res/layout/wise_sayings_fragment.xml #generated:2
-keep class com.kd7uiy.library.WiseSayings { <init>(...); }

# view res/layout/sort_list_array_dialog_preference.xml #generated:2
-keep class com.mobeta.android.dslv.DragSortListView { <init>(...); }

# view res/xml/pref_location.xml #generated:12
# view res/xml/pref_location.xml #generated:20
# view res/xml/pref_location.xml #generated:28
-keep class com.robobunny.SeekBarPreference { <init>(...); }

I've also tried compiling with the ignorewarnings flag disabled. The errors listed are huge, but here's a sampling of them, from the end:

[2014-02-26 10:03:37 - HamFinder] Proguard returned with error code 1. See console
[2014-02-26 10:03:37 - HamFinder] Warning: com.kd7uiy.hamfinder.MainActivity: can't find superclass or interface com.kd7uiy.hamfinder.LogBookFragment$OnEditView
[2014-02-26 10:03:37 - HamFinder] Warning: com.kd7uiy.hamfinder.MapQuestReverseCoder: can't find superclass or interface com.kd7uiy.hamfinder.AbstractWebReverseGeoCoder
[2014-02-26 10:03:37 - HamFinder] Warning: com.kd7uiy.hamfinder.OfflineLocator: can't find superclass or interface com.kd7uiy.hamfinder.AbstractReverseGeoCoder
[2014-02-26 10:03:37 - HamFinder] Warning: com.google.android.gms.auth.GoogleAuthUtil: can't find referenced class com.google.android.gms.R
...Continues like this. My searching shows mainly R files missing, although I did see this:
[2014-02-26 10:03:37 - HamFinder] Warning: com.kd7uiy.hamfinder.MainActivity: can't find referenced class com.kd7uiy.hamfinder.MainActivity$2
[2014-02-26 10:03:37 - HamFinder] Warning: com.kd7uiy.hamfinder.MainActivity: can't find referenced class com.kd7uiy.hamfinder.MainActivity$2
[2014-02-26 10:03:37 - HamFinder] Warning: com.kd7uiy.hamfinder.MainActivity: can't find referenced class com.kd7uiy.hamfinder.MainActivity$3
[2014-02-26 10:03:37 - HamFinder] Warning: com.kd7uiy.hamfinder.MainActivity: can't find referenced class com.kd7uiy.hamfinder.MainActivity$3
...
[2014-02-26 10:03:37 - HamFinder] Warning: eu.inmite.android.lib.dialogs.SimpleTimePickerDialogFragment: can't find referenced class eu.inmite.android.lib.dialogs.R$layout
[2014-02-26 10:03:37 - HamFinder] Warning: eu.inmite.android.lib.dialogs.SimpleTimePickerDialogFragment: can't find referenced class eu.inmite.android.lib.dialogs.R$layout
[2014-02-26 10:03:37 - HamFinder] Warning: eu.inmite.android.lib.dialogs.SimpleTimePickerDialogFragment: can't find referenced class eu.inmite.android.lib.dialogs.R
[2014-02-26 10:03:37 - HamFinder] Warning: there were 678 unresolved references to classes or interfaces.
[2014-02-26 10:03:37 - HamFinder]          You may need to add missing library jars or update their versions.
[2014-02-26 10:03:37 - HamFinder]          If your code works fine without the missing classes, you can suppress
[2014-02-26 10:03:37 - HamFinder]          the warnings with '-dontwarn' options.
[2014-02-26 10:03:37 - HamFinder]          (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
[2014-02-26 10:03:37 - HamFinder] Warning: there were 11 unresolved references to program class members.
[2014-02-26 10:03:37 - HamFinder]          Your input classes appear to be inconsistent.
[2014-02-26 10:03:37 - HamFinder]          You may need to recompile the code.
[2014-02-26 10:03:37 - HamFinder]          (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
[2014-02-26 10:03:37 - HamFinder] java.io.IOException: Please correct the above warnings first.
[2014-02-26 10:03:37 - HamFinder]   at proguard.Initializer.execute(Initializer.java:369)
[2014-02-26 10:03:37 - HamFinder]   at proguard.ProGuard.initialize(ProGuard.java:211)
[2014-02-26 10:03:37 - HamFinder]   at proguard.ProGuard.execute(ProGuard.java:86)
[2014-02-26 10:03:37 - HamFinder]   at proguard.ProGuard.main(ProGuard.java:483)

I've tried quite a number of things to get this to work, including upgrading proguard, updating the SDK, updating the Eclipse tools, downloading a new version of Eclipse and starting from scratch, numerous changes to the proguard file, none of which seems to help in the slightest. Any other ideas?

EDIT- Here's a few things that I'm leaning towards, as a possibility.

  1. I've noticed that the warning list changes, even if I do nothing more than clean the project and re-build.
  2. The number of errors seems to grow with the number of times I've had eclipse opened and build the build.
  3. Eclipse seems to be crashing more frequently with heap errors.

Not sure if any of this helps, but I thought I'd toss it in there.

解决方案

Summary: I'm pretty sure the key problem was the folder with the /java source folder instead of /src. Make sure any dependent libraries have their source code in a /src folder, if at all possible.

As I hinted in my edit, I believe this is a memory problem. In fact, I was able to get the build built with a lot of trial and error, and a few adjustments made to my eclipse memory configuration. Specifically, I used the advice from this article, namely:

  1. Increase the -Xmx256m to -Xmx2048m in the eclipse.ini file.
  2. Add -XX:MaxPermSize=256m to the eclipse.ini file.
  3. Add -Xms256M -Xmx512M to the JVM, found at Window-> Preferences -> Java -> Installed JREs -> clicking on JRE -> Edit
  4. Removing -ignorewarnings. That just masked the problem, I would have figured out what was going on a lot earlier if I hadn't done that. -dontwarn for the known issues (A lib I use optionally uses java.awt, but not for the stuff I use...
  5. Try multiple times to get the build to work, you'll know it works if there are no console errors.
  6. Use Ant/ Gradle to make

These steps helped, but in the end, I was able to fix it, although I did several things all at once, any of which could have fixed the problem. The things I did:

  1. Set the order of dependencies correctly, so that the first library included is compiled first, and so on. I have a few libraries that depend on libraries, so...
  2. One of my projects had the code in /java instead of /src. This might have caused some confusion, I'm not sure.
  3. Making sure all libraries target the latest Android build.

My project.properties looks like this now:

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-19
android.library.reference.1=../../../workspace/android-support-v7-appcompat
android.library.reference.2=..\\..\\..\\workspace\\google-play-services_lib
android.library.reference.3=..\\..\\..\\Documents\\GitHub\\android-styled-dialogs\\library\\src\\main
android.library.reference.4=..\\..\\..\\Documents\\GitHub\\drag-sort-listview\\library
android.library.reference.5=..\\..\\..\\Documents\\GitHub\\android-maps-utils\\library

这篇关于Proguard似乎删除了路径中包含的整个包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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