Android Proguard пропустить внешнюю банку - PullRequest
15 голосов
/ 06 февраля 2011

Я попытался использовать Proguard в своем проекте Android, я настроил Proguard с помощью командной строки 'android update project / path / to / project' и файл proguard.cfg был создан в корневом каталоге проекта. (В моем Eclipse с Android 2.3 SDK при создании нового проекта файл proguard.cfg не создается автоматически, поэтому я должен добавить его вручную с помощью командной строки).

Когда я экспортирую проект, я получил следующие ошибки

    [2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.client.HttpExchange
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.HttpFields
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.client.HttpExchange
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.io.Buffer
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.client.HttpExchange
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.client.HttpExchange
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.HttpFields
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.HttpFields$Field
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.HttpFields$Field
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.HttpFields$Field
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.client.HttpExchange
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.client.HttpExchange
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.client.Address
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.client.HttpExchange
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.client.HttpExchange
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.HttpFields
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.io.Buffer
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.client.Address
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.client.HttpExchange
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.client.HttpExchange
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.client.HttpExchange
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.HttpFields
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.HttpFields
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.HttpFields$Field
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.HttpRequestAdapter: can't find referenced class org.mortbay.jetty.HttpFields
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.CommonsLoggingLoggerFactory: can't find referenced class org.apache.commons.logging.LogFactory
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.CommonsLoggingLoggerFactory: can't find referenced class org.apache.commons.logging.LogFactory
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.SLF4JLoggerFactory: can't find referenced class org.slf4j.LoggerFactory
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.SLF4JLoggerFactory: can't find referenced class org.slf4j.LoggerFactory
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.jetty.JettyOAuthConsumer: can't find referenced class org.mortbay.jetty.client.HttpExchange
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.Log4JLoggerFactory: can't find referenced class org.apache.log4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.Log4JLoggerFactory: can't find referenced class org.apache.log4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.signature.OAuthMessageSigner: can't find referenced class org.apache.commons.codec.binary.Base64
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.signature.OAuthMessageSigner: can't find referenced class org.apache.commons.codec.binary.Base64
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.signature.OAuthMessageSigner: can't find referenced class org.apache.commons.codec.binary.Base64
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.signature.OAuthMessageSigner: can't find referenced class org.apache.commons.codec.binary.Base64
[2011-02-06 09:02:49 - TestProject] Warning: oauth.signpost.signature.OAuthMessageSigner: can't find referenced class org.apache.commons.codec.binary.Base64
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.SLF4JLogger: can't find referenced class org.slf4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.SLF4JLogger: can't find referenced class org.slf4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.SLF4JLogger: can't find referenced class org.slf4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.SLF4JLogger: can't find referenced class org.slf4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.SLF4JLogger: can't find referenced class org.slf4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.SLF4JLogger: can't find referenced class org.slf4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.SLF4JLogger: can't find referenced class org.slf4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.SLF4JLogger: can't find referenced class org.slf4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.SLF4JLogger: can't find referenced class org.slf4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.SLF4JLogger: can't find referenced class org.slf4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.Log4JLogger: can't find referenced class org.apache.log4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.Log4JLogger: can't find referenced class org.apache.log4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.Log4JLogger: can't find referenced class org.apache.log4j.Level
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.Log4JLogger: can't find referenced class org.apache.log4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.Log4JLogger: can't find referenced class org.apache.log4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.Log4JLogger: can't find referenced class org.apache.log4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.Log4JLogger: can't find referenced class org.apache.log4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.Log4JLogger: can't find referenced class org.apache.log4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.Log4JLogger: can't find referenced class org.apache.log4j.Level
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.Log4JLogger: can't find referenced class org.apache.log4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.Log4JLogger: can't find referenced class org.apache.log4j.Logger
[2011-02-06 09:02:49 - TestProject] Warning: twitter4j.internal.logging.Log4JLogger: can't find referenced class org.apache.log4j.Logger
[2011-02-06 09:02:49 - TestProject]       You should check if you need to specify additional program jars.
[2011-02-06 09:02:49 - TestProject] Warning: there were 59 unresolved references to classes or interfaces.
[2011-02-06 09:02:49 - TestProject]          You may need to specify additional library jars (using '-libraryjars'),
[2011-02-06 09:02:49 - TestProject]          or perhaps the '-dontskipnonpubliclibraryclasses' option.
[2011-02-06 09:02:49 - TestProject] java.io.IOException: Please correct the above warnings first.
[2011-02-06 09:02:49 - TestProject]     at proguard.Initializer.execute(Initializer.java:308)
[2011-02-06 09:02:49 - TestProject]     at proguard.ProGuard.initialize(ProGuard.java:210)
[2011-02-06 09:02:49 - TestProject]     at proguard.ProGuard.execute(ProGuard.java:85)
[2011-02-06 09:02:49 - TestProject]     at proguard.ProGuard.main(ProGuard.java:499)

Эти сообщения об ошибках указывают на четыре внешних банок, используемых в моем проекте

(.) * Путь к классам 1008 *

<classpathentry kind="lib" path="/Users/lorensiuswlt/Android/android-sdk-mac_x86/libs/Twitter/signpost-commonshttp4-1.2.1.1.jar"/>
        <classpathentry kind="lib" path="/Users/lorensiuswlt/Android/android-sdk-mac_x86/libs/Twitter/signpost-core-1.2.1.1.jar"/>
        <classpathentry kind="lib" path="/Users/lorensiuswlt/Android/android-sdk-mac_x86/libs/Twitter/signpost-jetty6-1.2.1.1.jar"/>
        <classpathentry kind="lib" path="/Users/lorensiuswlt/Android/android-sdk-mac_x86/libs/Twitter/twitter4j-core-2.1.6.jar"/>

Вот мой файл 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 *;
}

Я попробовал некоторые решения, найденные в сети, добавив параметр '-libraryjars', например:

-libraryjars /Users/lorensiuswlt/Android/android-sdk-mac_x86/libs/Twitter/twitter4j-core-2.1.6.jar

но это не поможет.

Какие-нибудь решения?

1 Ответ

38 голосов
/ 07 февраля 2011

Ваши библиотечные файлы ссылаются на еще больше библиотечных файлов (Mortbay, SLF4J, Apache Commons Logging, Log4j, ...). Добавление этих файлов с дополнительными опциями -libraryjars должно решить проблему.

Если выабсолютно уверены, что ваш код не использует эти библиотеки, вы можете указать '-ignorewarnings' или '-dontwarn', например

-dontwarn org.mortbay.**
-dontwarn org.slf4j.**
-dontwarn org.apache.log4j.**
-dontwarn org.apache.commons.logging.**
-dontwarn org.apache.commons.codec.binary.**
...