我想创建使用proguard的简单示例 在我的例子中,我在libs文件夹中有apfloat.jar lib,在xml中有onclick监听器。
public void f1(View item) {
if (item.getId() == R.id.button1) {
Apfloat x = new Apfloat("100");
x = x.add(new Apfloat("10"));
Toast.makeText(getApplicationContext(), "clicked "+x.toString(true).toString(), 5).show();
}
}
当我使用带有此配置的proguard时
# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
-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
# If you want to enable optimization, you should include the
# following:
# -optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
# -optimizationpasses 5
# -allowaccessmodification
#
# Note that you cannot just include these flags in your own
# configuration file; if you are including this file, optimization
# will be turned off. You'll need to either edit this file, or
# duplicate the contents of this file and remove the include of this
# file from your project's proguard.config path property.
-keepattributes *Annotation*
-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
-keep public class * extends android.app.backup.BackupAgent
-keep public class * extends android.preference.Preference
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Fragment
-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 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);
}
#-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.**
#-dontwarn apfloat.jar.**
-keep class apfloat.** { *; }
-keepclassmembers class * {
public void *(android.view.View);
}
-assumenosideeffects class android.util.Log { *; }
我收到此错误消息
Proguard returned with error code 1. See console
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.AbstractField: can't find superclass or interface org.jscience.mathematics.number.Number
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.AbstractField: can't find superclass or interface org.jscience.mathematics.structure.Field
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.ApfloatContext: can't find referenced class java.lang.management.ManagementFactory
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.ApfloatContext: can't find referenced class java.lang.management.MemoryMXBean
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.ApfloatContext: can't find referenced class java.lang.management.MemoryUsage
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.ApfloatContext: can't find referenced class java.lang.management.MemoryUsage
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.ApfloatContext: can't find referenced class java.lang.management.ManagementFactory
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.ApfloatContext: can't find referenced class java.lang.management.MemoryMXBean
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.ApfloatContext: can't find referenced class java.lang.management.MemoryUsage
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.AbstractField: can't find referenced class org.jscience.mathematics.number.Number
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.AbstractField: can't find referenced class javolution.text.Text
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.AbstractField: can't find referenced class org.jscience.mathematics.number.Number
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.AbstractField: can't find referenced class org.jscience.mathematics.structure.Field
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.AbstractField: can't find referenced class javolution.text.Text
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.AbstractField: can't find referenced class javolution.text.Text
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.AbstractField: can't find referenced class org.jscience.mathematics.number.Number
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.AbstractField: can't find referenced class org.jscience.mathematics.number.Number
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.AbstractField: can't find referenced class org.jscience.mathematics.number.Number
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.AbstractField: can't find referenced class org.jscience.mathematics.number.Number
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.AbstractField: can't find referenced class org.jscience.mathematics.structure.Field
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.ApcomplexField: can't find referenced class org.jscience.mathematics.number.Number
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.ApfloatField: can't find referenced class org.jscience.mathematics.number.Number
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.AprationalField: can't find referenced class org.jscience.mathematics.number.Number
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.FixedPrecisionApcomplexField: can't find referenced class org.jscience.mathematics.number.Number
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.FixedPrecisionApfloatField: can't find referenced class org.jscience.mathematics.number.Number
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.ModuloApintField: can't find referenced class javolution.context.LocalContext$Reference
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.ModuloApintField: can't find referenced class javolution.context.LocalContext$Reference
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.ModuloApintField: can't find referenced class javolution.context.LocalContext$Reference
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.ModuloApintField: can't find referenced class javolution.context.LocalContext$Reference
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.ModuloApintField: can't find referenced class javolution.context.LocalContext
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.ModuloApintField: can't find referenced class javolution.context.LocalContext$Reference
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.ModuloApintField: can't find referenced class javolution.context.LocalContext$Reference
[2014-09-28 08:38:26 - proguard] Warning: org.apfloat.jscience.ModuloApintField: can't find referenced class org.jscience.mathematics.number.Number
[2014-09-28 08:38:26 - proguard] Warning: there were 33 unresolved references to classes or interfaces.
[2014-09-28 08:38:26 - proguard] You may need to specify additional library jars (using '-libraryjars').
[2014-09-28 08:38:26 - proguard] java.io.IOException: Please correct the above warnings first.
[2014-09-28 08:38:26 - proguard] at proguard.Initializer.execute(Initializer.java:321)
[2014-09-28 08:38:26 - proguard] at proguard.ProGuard.initialize(ProGuard.java:211)
[2014-09-28 08:38:26 - proguard] at proguard.ProGuard.execute(ProGuard.java:86)
[2014-09-28 08:38:26 - proguard] at proguard.ProGuard.main(ProGuard.java:492)
我知道我可以使用
来避免此错误信息-dontwarn org.jscience.**
-dontwarn org.apfloat.**
当我使用此代码时,我的示例导出正常,但当我在手机中点击时,我点击按钮,我的应用程序崩溃 那怎么能解决这个问题呢?谢谢你的帮助。
答案 0 :(得分:1)
最后我找到了答案。
-dontwarn org.jscience.**
-dontwarn org.apfloat.**
-keep class apfloat.** { *; }
-keep class org.jscience.** { *; }
-keep class org.apfloat.** { *; }