- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我使用 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.**
这是我的文件的快照
这是我的构建路径
查看其他一些文件,我在 /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 文件进行了大量更改,没有其中似乎有丝毫帮助。还有其他想法吗?
编辑 - 作为一种可能性,我倾向于以下几点。
不确定这些是否有帮助,但我想我会把它扔进去。
最佳答案
现在你有
# 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/
https://www.guardsquare.com/en/proguard/manual/optimizations说 class/unboxing/enum Simplifies enum ty
我想使用 ProGuard 重命名变量和函数。我希望生成的类文件在所有方面都与源 jar 相同,除了名称。有没有办法做到这一点? 我尝试使用 dontoptimize 和 dontshrink 无效。
例如,这条规则在 proguard 中意味着什么: -keep class myjava.** {*;} 我理解 {*;} 部分意味着类中的所有成员和方法。但是包名中的 2 个星号是什么意思? 提前致
我有一个即将使用 ProGuard 混淆的库。 “图书馆模式”几乎适用于我的用例,即保留所有公共(public)和 protected 类和类成员几乎没问题。 然而,由于 Java 的可见性要求,一些
在我的 Playstore 中,我注意到去混淆后的代码包含相当多的 在堆栈跟踪中。 (例如 at .onAttach(ProfileLandingFragment.java) )。 有什么用真正意思?
我收到了一封来自 Google 的关于 unsafe implementation of TrustManager 的电子邮件唯一的线索是有问题的代码在 com.b.a.af 类中。显然,这是混淆的名
我读自 http://proguard.sourceforge.net/manual/usage.html关于assumenosideeffects的使用。我的问题涉及以下段落: -assumenos
什么是智能 ProGuard 配置来混淆特定类 com.acme.Algorithm 的私有(private)方法和常量? 我想对此进行混淆,因为它包含一个算法,当意外打开 .jar 时,该算法不应该
最近将 Pushwoosh 库集成到我的 Android 应用程序中。它运作良好。但是在导出为签名应用程序时遇到以下错误。请帮忙。提前致谢。 Proguard returned with error
有没有人有使用ProGuard的经验是否已经有超出类加载时间的应用程序性能测量? 我有一个相当复杂的应用程序,可能需要改进,但为 ProGuard 准备它需要几天时间,所以我想先听听一些意见。 最佳答
当我尝试使用 android studio 3.2 canary 17 构建应用程序包时,我收到以下错误消息。我不知道我所有的 proguard 文件中缺少什么角括号,一切似乎都很好,并且在旧版本的
我遇到了 proguard 的问题,我刚刚配置了 Bugsense 并且使用了它们的配置建议,我在 google 和 stackoverflow 上进行了搜索,通常 ppl 可以在控制台中看到该行或问
我第一次尝试使用 Proguard,我收到此错误,有人可以帮我吗?谢谢 [2014-09-03 11:44:58 - P - Photos] Proguard returned with error
当我收到此错误时,我正在尝试导出启用了 proguard 的 android 应用程序:- Proguard returned with error code 1. See console pro
看起来有两个用于运行 ProGuard 的 SBT 插件。任何人都可以谈谈他们的相对优势和劣势吗?我还没有在网上找到比较。 xsbt-proguard-plugin - https://github.
Proguard 会条纹 kotlin.Unit 独立对象(在 Kotlin 运行时库中),如果您使用此类型,则会导致编译错误。以下规则无助于保留此元素(可能是因为 Unit 不是一个类,它是一个对象
构建 Android 发行版 apk 时,Smack 4.1 的正确 ProGuard 规则是什么? 目前,我正在使用 aSmack github 存储库上 README.asmack 文件中的 aS
尝试使用 Proguard Maven 插件时出现 OutOfMemoryErrors。我尝试通过将 MAVEN_OPTS 环境变量设置为 -Xmx2g 来为 Maven 分配更多内存,但这没有任何区
我有一个 pom.xml 文件如下。当我运行 mvn clean install 时,出现错误 [proguard] Error: Can't read [C:\Program Files\Java\
我已经将支持库从 v22.2.1 更新到 v23.0.0,在构建应用程序后(使用 minifyEnabled true)我有“AppCompat 不支持当前主题功能”异常: 08-23 05:46:1
我是一名优秀的程序员,十分优秀!