1

project.properties で「proguard.config=${sdk.dir}/tools/proguard...」をコメントアウトして proguard を無効にしている場合、私のアプリはデバッグ中、および署名付き apk にエクスポートするときにも正常に動作します。

ただし、その行のコメントを外すと、たくさんの警告が表示され、proguard は apk を作成しません。次の行を proguard-project.txt に追加することで、警告を抑制することができます

-dontwarn com.sun.mail.imap.protocol.**
-dontwarn org.apache.harmony.awt.**
-dontwarn javax.activation.**

apk は作成されますが、電話では実行されません。興味深いことに、これらの行を削除して「-dontshrink」を使用すると、引き続きこれらのエラーが発生します。そうすれば問題は解決すると思っていました。

http://developer.android.com/tools/help/proguard.htmlで、構成にいくつかの -keep 行が欠落している可能性があることがわかりましたが、これらが何であるかは明らかではありません。誰でも手がかりを提供できますか?

デフォルトの proguard.cfg ファイルは一般的なケースに対応しようとしますが、ClassNotFoundException などの例外が発生する可能性があります。これは、アプリケーションが呼び出すクラス全体を ProGuard が取り除くときに発生します。

proguard.cfg ファイルに -keep 行を追加することで、ProGuard がコードを削除する際のエラーを修正できます。例えば:

-公開クラスを維持する

    [2013-06-19 14:19:30 - Flashum2] Proguard returned with error code 1. See console
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.DataProxy: can't find superclass or interface java.awt.datatransfer.Transferable
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.NativeClipboard: can't find superclass or interface java.awt.datatransfer.Clipboard
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.Sasl
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.Sasl
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslException
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslException
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.auth.callback.NameCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.auth.callback.NameCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmChoiceCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmChoiceCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmChoiceCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmChoiceCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.auth.callback.NameCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmChoiceCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: javax.activation.CommandInfo: can't find referenced class java.beans.Beans
    [2013-06-19 14:19:30 - Flashum2] Warning: javax.activation.CommandInfo: can't find referenced class java.beans.Beans
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.Toolkit
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.Toolkit
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.Toolkit
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.Toolkit
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.DTK: can't 
.
.
.
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.TextFlavor: can't find referenced class java.awt.datatransfer.SystemFlavorMap
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.TextFlavor: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.TextFlavor: can't find referenced class java.awt.datatransfer.SystemFlavorMap
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.TextFlavor: can't find referenced class java.awt.datatransfer.SystemFlavorMap
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.TextFlavor: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-06-19 14:19:30 - Flashum2]       You should check if you need to specify additional program jars.
    [2013-06-19 14:19:30 - Flashum2] Warning: there were 247 unresolved references to classes or interfaces.
    [2013-06-19 14:19:30 - Flashum2]          You may need to specify additional library jars (using '-libraryjars').
    [2013-06-19 14:19:30 - Flashum2] java.io.IOException: Please correct the above warnings first.
    [2013-06-19 14:19:30 - Flashum2]    at proguard.Initializer.execute(Initializer.java:321)
    [2013-06-19 14:19:30 - Flashum2]    at proguard.ProGuard.initialize(ProGuard.java:211)
    [2013-06-19 14:19:30 - Flashum2]    at proguard.ProGuard.execute(ProGuard.java:86)
    [2013-06-19 14:19:30 - Flashum2]    at proguard.ProGuard.main(ProGuard.java:492)

それが役立つ場合、これは私の libs フォルダー内の jar のリストです。

05/31/2013  10:47 AM    <DIR>          .
05/31/2013  10:47 AM    <DIR>          ..
05/15/2012  09:22 AM            34,093 acra-3.1.2.jar
01/14/2013  09:07 AM            51,643 activation.jar
01/14/2013  09:06 AM            46,184 additionnal.jar
05/25/2013  04:14 PM           501,154 android-support-v13.jar
05/15/2012  09:22 AM           312,866 commons-lang3-3.0.1.jar
05/15/2012  09:22 AM           269,014 commons-net-3.0.1.jar
05/31/2013  10:47 AM           170,927 google-api-client-1.14.1-beta.jar
05/31/2013  10:47 AM             9,068 google-api-client-android-1.14.1-beta.jar
05/31/2013  10:47 AM           137,977 google-api-services-drive-v2-rev76-1.14.2-beta.jar
05/31/2013  10:47 AM           268,450 google-http-client-1.14.1-beta.jar
05/31/2013  10:47 AM            10,072 google-http-client-android-1.14.1-beta.jar
05/31/2013  10:47 AM             7,828 google-http-client-gson-1.14.1-beta.jar
05/31/2013  10:47 AM             6,038 google-http-client-jackson-1.14.1-beta.jar
05/31/2013  10:47 AM             6,076 google-http-client-jackson2-1.14.1-beta.jar
05/31/2013  10:47 AM            64,952 google-oauth-client-1.14.1-beta.jar
05/31/2013  10:47 AM           180,110 gson-2.1.jar
05/31/2013  10:47 AM           206,797 jackson-core-2.1.3.jar
05/31/2013  10:47 AM           232,131 jackson-core-asl-1.9.11.jar
05/31/2013  10:47 AM            33,015 jsr305-1.3.9.jar
01/14/2013  09:06 AM           440,508 mail.jar
05/15/2012  09:22 AM           134,421 zip4j_1.2.5.jar
4

1 に答える 1

0

少し遅いかもしれませんが、同様の問題の解決策を探していると、ライブラリ jar にいくつかのクラスを保持するようにproguardに指示する必要があることがわかりました。Warning: ...および と記載されているログを参照してくださいcan't find referenced class ...

したがって、あなたの場合は次のようになります。

-keep class javax.security.** { *; }
-keep class java.beans.** { *; }
-keep class java.awt.** { *; }

-libraryjars libs/XYZ.jar

/libsそれらのクラスを含むすべてのjarに対して。

于 2014-02-11T14:05:09.173 に答える