我尝试使用Proguard在MAC上使用eclipse ADT v21.1.0-569685来优化我的Android应用程序代码。 我使用了project-> Android Tools->导出已签名的应用程序包选项,用于使用我的私有证书进行签名,签名完成后出现以下错误,
project.properties
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-17
android.library.reference.1=../google-play-services_lib
proguard的-project.txt
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
控制台日志:
[2013-04-12 10:41:53 - MyApp] Proguard returned with error code 1. See console
[2013-04-12 10:41:53 - MyApp] proguard.ParseException: Expecting class member name before '@' in line 82 of file '/Users/MyOrg/Android_workspace/MyApp/bin/proguard.txt',
[2013-04-12 10:41:53 - MyApp] included from argument number 6
[2013-04-12 10:41:53 - MyApp] at proguard.ConfigurationParser.readNextWord(ConfigurationParser.java:1133)
[2013-04-12 10:41:53 - MyApp] at proguard.ConfigurationParser.readNextWord(ConfigurationParser.java:1117)
[2013-04-12 10:41:53 - MyApp] at proguard.ConfigurationParser.parseMemberSpecificationArguments(ConfigurationParser.java:845)
[2013-04-12 10:41:53 - MyApp] at proguard.ConfigurationParser.parseClassSpecificationArguments(ConfigurationParser.java:697)
[2013-04-12 10:41:53 - MyApp] at proguard.ConfigurationParser.parseKeepClassSpecificationArguments(ConfigurationParser.java:490)
[2013-04-12 10:41:53 - MyApp] at proguard.ConfigurationParser.parse(ConfigurationParser.java:139)
[2013-04-12 10:41:53 - MyApp] at proguard.ProGuard.main(ProGuard.java:484)
如果您的项目使用带有JS的WebView,请取消注释以下内容 为JavaScript接口指定完全限定的类名 类:
我在WebAppInterface.java类的两个活动中使用了webview。如何做上面的语句?
答案 0 :(得分:5)
在布局文件的 android:onClick 属性中引用资源名称“ @ string / on_click_handler_name ”即可。但是,proguard无法解决这些引用。
查看http://android.okhelp.cz/proguard-parseexception-expecting-class-member-name-before/了解详情。
在 string.xml 中找到 @ string / tha_lf_et_todate_onclick 的相应值并更新:
android:onClick="@string/tha_lf_et_todate_onclick"
到
android:onClick="onClickXXX"
布局文件中的。 对于第二个问题, 取消注释该段代码,并替换“fqcn.of.javascript.interface.for.webview” 使用班级的完全限定名称。