编辑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 Compiler了解这一点:
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̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶̶
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̶.̶
在释放,̶̶*̶*我的广播不工作* *̶̶,̶因此字符串可能一直由̶'̶b̶r̶o̶k̶e̶n̶'̶的ProGuard̶p̶r̶o̶c̶e̶s̶s̶i̶n̶g̶.̶ 我该如何解决这些问题呢?
重要提示:
我有一个图书馆项目和许多使用图书馆项目的应用项目。 广播常量在库项目中定义,并在app项目中使用。在预测所有应用程序的同时“保护”这些字符串的有效方法是什么?
我应该使用-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.**
感谢您的帮助。
答案 0 :(得分:1)
ProGuard根本不应修改任何字符串。您应确保在Android SDK(android-sdk / tools / proguard / lib / proguard.jar)中使用最新版本(此时为4.8或4.9 beta)。您可以查看
的版本java -jar android-sdk/tools/proguard/lib/proguard.jar
在相关的说明中,您的配置建议您使用较旧的Android SDK,因为现在单独指定项目特定和项目无关的配置,从SDK r20开始(分别在proguard-project.txt和android-中) SDK /工具/ proguard的/ proguard的-android.txt)。只需升级SDK可能已经有所帮助。
如果问题仍然存在,您可以在ProGuard website上提交错误报告。