Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Proguard似乎要删除路径中包含的整个包_Android_Eclipse_Proguard - Fatal编程技术网

Android Proguard似乎要删除路径中包含的整个包

Android Proguard似乎要删除路径中包含的整个包,android,eclipse,proguard,Android,Eclipse,Proguard,我使用Proguard来混淆我的代码,并使其更小。我使用Eclipse进行构建,并且已经有一段时间了。我最近有一个在调试版本中运行良好的构建,我正在尝试发布这个版本。在最后一天的大部分时间里,我一直在尝试完成这项工作,当我尝试使用发布的构建运行代码时,我不断遇到以下错误(如果有帮助的话,我可以生成更多) 02-25 16:39:58.844:E/AndroidRuntime(27593):由以下原因引起: java.lang.ClassNotFoundException:未找到类 路径:DexP

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

02-25 16:39:58.844:E/AndroidRuntime(27593):由以下原因引起: java.lang.ClassNotFoundException:未找到类 路径:DexPathList[[zip文件]上的“com.kd7uiy.hamfinder.MainActivity” “/data/app/com.kd7uiy.hamfinder-2.apk”],nativeLibraryDirectories=[/data/app-lib/com.kd7uiy.hamfinder-2, /供应商/lib,/system/lib]]

真正奇怪的是,我没有更改我的proguard文件,至少不是第一次这样做。从那以后,我一直在玩它,想看看我能不能找到什么东西让它发挥作用,但似乎什么也做不到。自构建以来,我在代码库中添加了一个新库,即。我的上一次构建是几天前

尝试解决此问题时,我发现路径列表中没有显示整个文件夹。我在编译过的二进制类中看到了这个文件夹,但它们在这个过程中无法生存。如果我停止使用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地图更改。两者都不起作用

-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.**
我还尝试过在禁用
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文件进行了大量的更改,但这些似乎都没有任何帮助。还有其他想法吗

编辑-这里有一些我倾向于的东西,作为一种可能性

  • 我注意到警告列表发生了变化,即使我只是清理项目并重新构建
  • 错误的数量似乎随着我打开eclipse并构建构建的次数的增加而增加
  • 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):

    对于
    Fragment
    s等也一样



    注意,您的日志显示找不到属于内部类视图的
    LogBookFragment$OnEditView
    。可以逐个列出这些文件以供proguard保存,也可以将它们移到自己的类文件中。

    摘要:我很确定关键的问题是文件夹中有
    /java
    源文件夹,而不是
    /src
    。如果可能的话,确保所有依赖库的源代码都位于
    /src
    文件夹中

    正如我在编辑中所暗示的,我认为这是一个记忆问题。事实上,我通过大量的尝试和错误,以及对eclipse内存配置的一些调整,就能够构建这个构建。具体而言,我使用了来自的建议,即:

  • 将eclipse.ini文件中的
    -Xmx256m
    增加到
    -Xmx2048m
  • 将-XX:MaxPermSize=256m添加到eclipse.ini文件中
  • -Xms256M-Xmx512M
    添加到JVM,可在窗口->首选项->Java->安装的JRE->单击JRE->编辑中找到
  • 正在删除
    -ignorewarnings
    。这只是掩盖了问题,如果我没有这么做,我早就知道发生了什么
    -dontwarn
    用于已知问题(我使用的lib可以选择使用
    java.awt
    ,但不用于我使用的东西
  • 尝试多次以使构建正常工作,如果没有控制台错误,您将知道它正常工作
  • 使用Ant/Gradle制作
  • 这些步骤很有帮助,但最终我还是能够解决问题,尽管我一次做了几件事情,其中任何一件都可以解决问题。我做的事情:

  • 正确设置依赖项的顺序,以便首先编译包含的第一个库,依此类推
  • 我的一个项目的代码是/java而不是/src。这可能会引起一些混乱,我不确定
  • 确保所有库都以最新的Android版本为目标
  • 我的project.properties现在看起来像这样:

    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
    

    在Windows中使用Eclipse中的ProGuard进行构建时,我偶尔会收到关于缺少类的报告。原因到目前为止还是个谜。ProGuard在Eclipse中作为单独的脚本/java进程运行。问题是偶然发生的。我猜编译的类文件可能是
    -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);
    }
    
    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