gpt4 book ai didi

android - Proguard 似乎删除了路径中包含的整个包

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:43:51 27 4
gpt4 key购买 nike

我使用 Proguard 来混淆我的代码,并使其更小。我使用 Eclipse 进行构建,并且使用了一段时间。我最近有一个在调试版本中运行良好的构建,我正在尝试发布它。在过去一天的大部分时间里,我一直在努力完成这项工作,但当我尝试使用已发布的构建运行我的代码时,我不断收到以下错误(如果有帮助,我可以生成更多)。

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]]

真正奇怪的是,我没有更改我的proguard 文件,至少不是我第一次这样做。从那以后我就一直在玩它,看看我能不能得到任何东西让它工作,但似乎没有什么能解决问题。自此构建以来,我在我的代码库中添加了一个新库 Google Maps utility library .我的最后一次构建是在几天前。

在尝试解决此问题时,我发现路径列表中没有出现整个文件夹。我在已编译的二进制类中看到了这个文件夹,但它们无法在这个过程中存活下来。如果我停止使用 Proguard,发布版本将按预期运行。

我的代码依赖于 /src 目录中的 6 个包。我没有为这个版本显着改变这个结构,虽然我可能添加了一两个文件到不同的文件夹,并且可能移动了一两个文件夹。这 6 个包是:

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

其中,我在我的 proguard 映射文件中找不到以下包的直接证据,至少对于这个特定的试验而言

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

有些引用了一些变量名,但没有包含整个包的证据。我检查了 .dex 文件,它也不包含丢失的包。我应该补充一点,有时看似随机的一些其他包会出现,但永远不会出现我的 MainActivity 所在的 com.kd7uiy.hamfinder。有时它们都不出现。

这是我的 project.properties 文件:

# 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

还有我原来的 proguard-project.txt 文件,它已被证明不起作用。

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

我确实对其进行了更改,以便为 Proguard 添加适当的 Google map 所需的更改。都没有用。

-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

作为引用,这是我的 proguard-android.txt 文件,位于正确的位置。

# 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.**

这是我的文件的快照

enter image description here

这是我的构建路径

enter image description here

查看其他一些文件,我在 /bin/proguard.txt 文件中看到了这些文件的证据,但之后它们似乎就消失了。编译后的大小也没有明显变小,但这可能是因为我的非代码内容比代码多得多,很难检测到几个 java 文件的差异。这是整个/bin/proguard.txt 文件。

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

我还尝试在禁用 ignorewarnings 标志的情况下进行编译。列出的错误很大,但这里是其中的一个示例,从最后开始:

[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)

我已经尝试了很多方法来让它工作,包括升级 proguard、更新 SDK、更新 Eclipse 工具、下载新版本的 Eclipse 并从头开始,对 proguard 文件进行了大量更改,没有其中似乎有丝毫帮助。还有其他想法吗?

编辑 - 作为一种可能性,我倾向于以下几点。

  1. 我注意到警告列表发生了变化,即使我只是清理项目并重新构建。
  2. 错误的数量似乎随着我打开 eclipse 和构建构建的次数而增加。
  3. Eclipse 似乎因堆错误而更频繁地崩溃。

不确定这些是否有帮助,但我想我会把它扔进去。

最佳答案

现在你有

# 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);
}

您的类扩展了 v7 支持库(从您的 project.properties 判断)而不是标准的 android.app.Activity,因此您需要如下内容:

-dontwarn android.support.v7.**
-keep public class * extends android.support.v7.app.Fragment
-keep public class * extends android.support.v4.app.Activity

或者如果你想尝试保留更多(但更大的最终 apk):

-keep class android.support.v7.** { *; }

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

对于 Fragment 等也是如此


请注意您的日志显示无法找到 LogBookFragment$OnEditView 这是一个内部类 View 。要么将它们一一列出以由混淆器保存,要么将它们移出到它们自己的类文件中。

关于android - Proguard 似乎删除了路径中包含的整个包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22027219/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com