2

編集 2: Proguard は文字列を壊さない: ソース ファイルの文字エンコーディング管理が悪い!

(私の最初の質問は以下です)

これを一言で言えば、Eclipse でのコンパイルは問題ありません (Java ソースの char エンコーディングが何であれ)。しかし、私はリリースのために Jenkins でコンパイルします。

ソースエンコーディングを ISO-8859-1 から UTF-8 に変更する必要がありました (私は Mac を使用していますが、これが Windows で発生するかどうかはわかりません)。

iconv -f ISO-8859-1 -t UTF-8 "$file" > "${file%.java}.utf8.java"; 

Javac コンパイラーにそれを認識させます。

export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8

私のすべてのJavaファイルについて:

find /path_to_mys_workspace/workspace -name \*.java -type f | \
    (while read file; do
        iconv -f ISO-8859-1 -t UTF-8 "$file" > "${file%.java}.utf8.java";
        rm "$file";
        mv "${file%.java}.utf8.java" "$file";
    done);

(また、EclipseにUTF-8で動作するように指示しました)

Preferences
  -> General
     -> Workspace
       -> DefaultFile encoding : UTF-8

そして今、それは機能します!

(また、コードにハードコードされたフランス語の文字列がいくつかあるため、この問題に遭遇しました...私にとっては-1です。)


私の最初の質問:

Proguard は優れていますが、設定が常に簡単であるとは限りません...

Proguard を使用して、一連の Android アプリのリリース バージョンをビルドしています (アプリが連携しています)。

私はほとんどそこにいますが、いくつかの文字列関連の問題に直面しています:

1 - 文字列エンコーディングの問題

デバッグ モードで正しく表示される一部の外部文字 (コード内の文字列内) は、リリース時 (つまり、proguard 処理後) に、UTF REPLACEMENT CHARACTERに置き換えられるようになりました。

例:

The french 'à' is now displayed as � 

* ̶2̶ ̶-̶ ̶B̶r̶o̶k̶e̶n̶ ̶B̶r̶o̶a̶d̶c̶a̶s̶t̶ ̶a̶c̶t̶i̶o̶n̶s̶ *

編集: ブロードキャストはまったく壊れていません: いくつかのプロガード ステートメントを忘れたり、間違いを犯したりしました。

̶I̶ ̶d̶e̶f̶i̶n̶e̶d̶ ̶s̶o̶m̶e̶ ̶p̶u̶b̶l̶i̶c̶ ̶s̶t̶a̶t̶i̶c̶ ̶f̶i̶n̶a̶l̶ ̶s̶t̶r̶i̶n̶g̶s̶ ̶i̶n̶ ̶m̶y̶

c̶o̶m̶.̶<̶m̶y̶_̶a̶p̶p̶_̶n̶a̶m̶e̶>̶.̶i̶n̶t̶e̶n̶t̶.̶C̶o̶n̶s̶t̶a̶n̶t̶s̶

̶c̶l̶a̶s̶s̶,̶ ̶s̶o̶ ̶I̶ ̶a̶d̶d̶e̶d̶

-̶k̶e̶e̶p̶ ̶p̶u̶b̶l̶i̶c̶ ̶c̶l̶a̶s̶s̶ ̶c̶o̶m̶.̶<̶m̶y̶_̶a̶p̶p̶_̶n̶a̶m̶e̶>̶.̶i̶n̶t̶e̶n̶t̶.̶*̶

̶i̶n̶ ̶m̶y̶ ̶P̶r̶o̶g̶u̶a̶r̶d̶ ̶c̶o̶n̶f̶i̶g̶ ̶f̶i̶l̶e̶.̶

̶I̶n̶ ̶r̶e̶l̶e̶a̶s̶e̶,̶ ̶*̶*̶m̶y̶ ̶b̶r̶o̶a̶d̶c̶a̶s̶t̶s̶ ̶d̶o̶ ̶n̶o̶t̶ ̶w̶o̶r̶k̶*̶*̶,̶ ̶s̶o̶ ̶t̶h̶e̶ ̶s̶t̶r̶i̶n̶g̶ ̶h̶a̶v̶e̶ ̶p̶r̶o̶b̶a̶b̶l̶y̶ ̶b̶e̶e̶n̶ ̶'̶b̶r̶o̶k̶e̶n̶'̶ ̶b̶y̶ ̶p̶r̶o̶g̶u̶a̶r̶d̶ ̶p̶r̶o̶c̶e̶s̶s̶i̶n̶g̶.̶ How can I fix those problems?

重要な注意点:

1 つのライブラリ プロジェクトと、そのライブラリ プロジェクトを使用する多くのアプリ プロジェクトがあります。ブロードキャスト定数はライブラリ プロジェクトで定義され、アプリ プロジェクトで使用されます。すべてのアプリを保護しながら、これらの文字列を「保護」する適切な方法は何ですか?

-injars in.jar -outjars out.jar -libraryjars などで遊ぶ必要がありますか?

追加情報:

リリース ビルドは Jenkins Factory で行われます。役に立つ情報かどうかはわかりませんが、説明を完全にするために言及したかったのです。


これは、すべてのアプリとライブラリ プロジェクトで使用される Proguard 構成ファイルです。

##
## my rules
##

-dontwarn org.joda.time.**,org.apache.harmony.**,com.google.vending.licensing.**,javax.security.**,java.beans.**,java.awt.**

-keep public class com.<my_package>.intent.**
{
     *;
}

#-keep public class * extends android.app.BaseActivity
-keep public class * extends com.<my_package>.shared.fragment.BaseFragment

-keepclassmembers class * extends com.<my_package>.shared.activity.BaseActivity {
   public boolean *();
   public boolean *(android.view.View);
   public void *();
   public void *(android.view.View);
}

-keepclassmembers class * extends com.<my_package>.shared.fragment.BaseFragment {
   public boolean *();
   public boolean *(android.view.View);
   public void *();
   public void *(android.view.View);
}

##
## common rules
##

-keep public class com.bugsense.*

#-repackageclasses ''
#-allowaccessmodification
#-optimizations !code/simplification/arithmetic

-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

-keepclassmembers class * extends android.content.Context {
   public void *(android.view.View);
   public void *(android.view.MenuItem);
}

-keep public class * extends android.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

##
## base proguard file content
##

-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.**

助けてくれてありがとう。

4

1 に答える 1

1

ProGuard は文字列をまったく変更すべきではありません。Android SDK (android-sdk/tools/proguard/lib/proguard.jar) 内で最新のリリース (現時点では 4.8 または 4.9 ベータ版) を使用していることを確認する必要があります。使用しているバージョンを確認できます

java -jar android-sdk/tools/proguard/lib/proguard.jar

関連する注意事項として、SDK r20 の時点で、プロジェクト固有の構成とプロジェクトに依存しない構成が個別に指定されるようになったため、構成は古い Android SDK を使用していることを示唆しています (それぞれ proguard-project.txt と android-sdk/tools で) /proguard/proguard-android.txt)。SDK をアップグレードするだけでも効果がある場合があります。

問題が解決しない場合は、 ProGuard Web サイトでバグ レポートを提出できます。

于 2013-02-27T00:09:33.670 に答える