zoukankan      html  css  js  c++  java
  • Enable Android progurad in the case of multiple JAR lib

    View the version of Proguard:

    1.open command window of windows.

    2.enter the folder of proguard,step into bin directory.

    cd <your SDK path>\android-sdk\tools\proguard\bin

    3.run proguard

      


    A.Normal Condition

      Set the configuration file for progurad in project.properties

    # This file is automatically generated by Android Tools.
    # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
    #
    # This file must be checked in Version Control Systems.
    #
    # To customize properties used by the Ant build system use,
    # "ant.properties", and override values to adapt the script to your
    # project structure.
    
    proguard.config=proguard.cfg
    # Project target.
    target=android-8

      default proguard.cfg:

    -optimizationpasses 5
    -dontusemixedcaseclassnames
    -dontskipnonpubliclibraryclasses
    -dontpreverify
    -verbose
    -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
    
    -keep public class * extends android.app.Activity
    -keep public class * extends android.app.Application
    -keep public class * extends android.app.Service
    -keep public class * extends android.content.BroadcastReceiver
    -keep public class * extends android.content.ContentProvider
    -keep public class * extends android.app.backup.BackupAgentHelper
    -keep public class * extends android.preference.Preference
    -keep public class com.android.vending.licensing.ILicensingService
    
    -keepclasseswithmembernames class * {
        native <methods>;
    }
    
    -keepclasseswithmembernames class * {
        public <init>(android.content.Context, android.util.AttributeSet);
    }
    
    -keepclasseswithmembernames class * {
        public <init>(android.content.Context, android.util.AttributeSet, int);
    }
    
    -keepclassmembers enum * {
        public static **[] values();
        public static ** valueOf(java.lang.String);
    }
    
    -keep class * implements android.os.Parcelable {
      public static final android.os.Parcelable$Creator *;
    }

      Now the system will use the configurations in proguard.cfg when enable proguard.If you remove the blue line(just add '#' before it to make annotation),the proguard function will be shutdown.As a result,you apps can be decompiled very easily.Of course,it still can be decompiled if you set the proguard,but the result they get is obscure.So,for sake of security,you had better enable the proguard.

    B.Multiple Jar Package

      If you add other jar package to lib and use it in code,it may run well when you debug your project.However,while you are exporting signed application package,the question comes:

              

    [2012-07-23 16:00:48 - AndroidReader] Proguard returned with error code 1. See console
    [2012-07-23 16:00:48 - AndroidReader] Warning: nl.siegmann.epublib.utilities.StreamWriterDelegate: can't find superclass or interface javax.xml.stream.XMLStreamWriter
    [2012-07-23 16:00:48 - AndroidReader] Warning: org.htmlcleaner.HtmlCleanerForAnt: can't find superclass or interface org.apache.tools.ant.Task
    [2012-07-23 16:00:48 - AndroidReader] Warning: nl.siegmann.epublib.utilities.StreamWriterDelegate: can't find referenced class javax.xml.stream.XMLStreamWriter
    ......
    [2012-07-23 16:00:48 - AndroidReader] Warning: org.htmlcleaner.HtmlCleanerForAnt: can't find referenced class org.apache.tools.ant.Task
    [2012-07-23 16:00:48 - AndroidReader] Warning: org.htmlcleaner.HtmlCleanerForAnt: can't find referenced class org.apache.tools.ant.BuildException
    ......
    [2012-07-23 16:00:48 - AndroidReader] Warning: org.htmlcleaner.HtmlCleanerForAnt: can't find referenced class org.apache.tools.ant.Task
    [2012-07-23 16:00:48 - AndroidReader] Warning: org.htmlcleaner.JDomSerializer: can't find referenced class org.jdom.DefaultJDOMFactory
    ......
    [2012-07-23 16:00:48 - AndroidReader] Warning: org.htmlcleaner.JDomSerializer: can't find referenced class org.jdom.Element
    [2012-07-23 16:00:48 - AndroidReader]       You should check if you need to specify additional program jars.
    [2012-07-23 16:00:48 - AndroidReader] Warning: there were 80 unresolved references to classes or interfaces.
    [2012-07-23 16:00:48 - AndroidReader]          You may need to specify additional library jars (using '-libraryjars').
    [2012-07-23 16:00:48 - AndroidReader] java.io.IOException: Please correct the above warnings first.
    [2012-07-23 16:00:48 - AndroidReader]     at proguard.Initializer.execute(Initializer.java:321)
    [2012-07-23 16:00:48 - AndroidReader]     at proguard.ProGuard.initialize(ProGuard.java:211)
    [2012-07-23 16:00:48 - AndroidReader]     at proguard.ProGuard.execute(ProGuard.java:86)
    [2012-07-23 16:00:48 - AndroidReader]     at proguard.ProGuard.main(ProGuard.java:492)

     1.According to the error infomation,I should specify additional library jars (using '-libraryjars').

      My file tree:

        

    ProGuard outputs the following files after it runs:

    dump.txt

    Describes the internal structure of all the class files in the .apk file

    mapping.txt

    Lists the mapping between the original and obfuscated class, method, and field names. This file is important when you receive a bug report from arelease build, because it translates the obfuscated stack trace back to the original class, method, and member names. See Decoding ObfuscatedStack Traces for more information.

    seeds.txt

    Lists the classes and members that are not obfuscated

    usage.txt

    Lists the code that was stripped from the .apk 

    These files are located in the following directories:

    • <project_root>/bin/proguard if you are using Ant.
    • <project_root>/proguard if you are using Eclipse.

    so I add the following to the end of proguard.cfg:

    -libraryjars lib/acra-4.2.3.jar
    -libraryjars lib/epublib-core-latest.jar
    -libraryjars lib/htmlcleaner-2.2.jar
    -libraryjars lib/slf4j-api-1.6.4.jar
    -libraryjars lib/slf4j-jdk14-1.6.4.jar
    -libraryjars lib/xnio-api-2.0.2.GA.jar

    Shit! The errors still occur.

    2.Then I consulted google and realized that I just need to enable proguard for my own code,needn't for the external jar libs.

    refer: http://hi.baidu.com/bufferhayes/item/346c3a0a8148a16ad55a1108

    So I modifed the content:

    -keep class nl.siegmann.epublib.** {*;}
    -keep class org.htmlcleaner.** {*;}
    -keep class org.slf4j.** {*;}
     
    -dontwarn nl.siegmann.epublib.**
    -dontwarn org.htmlcleaner.**
    -dontwarn org.slf4j.**
     
    -libraryjars lib/acra-4.2.3.jar
    -libraryjars lib/epublib-core-latest.jar
    -libraryjars lib/htmlcleaner-2.2.jar
    -libraryjars lib/slf4j-api-1.6.4.jar
    -libraryjars lib/slf4j-jdk14-1.6.4.jar

    you can alse add the following if necessary:

    -keep interface nl.siegmann.epublib.** {*;}
    -keep interface org.htmlcleaner.** {*;}
    -keep interface org.slf4j.** {*;}

    Keep the class which may throw errors.The class and package name can be obtained from the Referenced Libraries directory.

    Then I can generate the apk succesfully.

    And the you can install it and maybe run it normally,but I still get errors:Can't find the my custom view in xml file!  

    The activity related to custom views all crashed!(Others can)

    3.Someone pointed that it is caused by the bugs of the Proguard(4.7) itself.

    So I replace it with 4.7 beta1.(just need to override the tools\proguard folder with 4.7beta1's contents)....

    ADB server didn't ACK:

    Try below steps:

    1. Close the Eclipse if running
    2. Go to the platform-tools directory in Command Prompt
    3. type adb kill-server
    4. then type adb start-server
    5. No error message is thrown while starting ADB server, then adb is started successfully.
    6. Now you can start Eclipse again.
  • 相关阅读:
    cyren提供安全规则
    AC自动机——1 Trie树(字典树)介绍
    代码静态分析工具——splint的学习与使用
    Aria2+WebUI,迅雷倒下之后的代替品
    立华科技
    centos平台基于snort、barnyard2以及base的IDS(入侵检测系统)的搭建与测试及所遇问题汇总
    Iperf使用方法与参数说明
    网络基本功(一):细说网络传输
    TCP窗口扩大选项
    TCP Nagle算法&&延迟确认机制
  • 原文地址:https://www.cnblogs.com/qiengo/p/2498991.html
Copyright © 2011-2022 走看看