Proguard seeming to remove an entire packages that are included in the path

前端 未结 3 1317
小鲜肉
小鲜肉 2021-01-11 10:50

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, wh

相关标签:
3条回答
  • 2021-01-11 11:36

    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
    
    0 讨论(0)
  • 2021-01-11 11:49

    I occasionally receive reports about missing classes when building with ProGuard in Eclipse, in Windows. The cause is a mystery so far. ProGuard is run as a separate script/java process inside Eclipse. The problem happens spuriously. I am guessing the compiled class files aren't flushed to the file system in time for ProGuard to read them. You could try adding a pause or just list the files in the ProGuard script android-sdk/tools/proguard/bin/proguard.bat.

    I have not received any similar reports about Ant or Gradle, so those may be practical alternatives.

    (I am the developer of ProGuard)

    0 讨论(0)
  • 2021-01-11 11:55

    Right now you have

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

    Your classes extend the support library v7 (judging from your project.properties) not the standard android.app.Activity, so you need something like:

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

    or if you want to try to keep more (but bigger final apk):

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

    or

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

    and the same for Fragments etc


    Note your log says Cannot find LogBookFragment$OnEditView which is an inner class View. Either list these one by one to save by proguard or move them out into their own class file.

    0 讨论(0)
提交回复
热议问题