编辑 2:Proguard 不会破坏字符串:源文件字符编码管理错误!
(我最初的问题如下)
简而言之:在 eclipse 上编译很好(无论 java 源字符编码是什么)。但我确实与 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 - 字符串编码问题
一些在调试模式下正确显示的外来字符(在代码中的字符串中)现在被替换为 UTF REPLACEMENT CHARACTER,在发布中(即,在 proguard 处理之后)。
例子:
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̶ *
编辑:广播根本没有中断:我在一些 proguard 语句中忘记/犯了错误。
̶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?
重要的提示:
我有一个库项目和许多使用库项目的应用程序项目。广播常量在库项目中定义并在应用项目中使用。在保护所有应用程序的同时“保护”这些字符串的正确方法是什么?
我应该玩 -injars in.jar -outjars out.jar -libraryjars 等吗?
附加信息:
发布构建在 Jenkins 工厂中完成。不确定这是有用的信息,但为了我的解释的完整性想提一下。
这是所有应用程序和库项目使用的我的 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.**
感谢您的帮助。