gpt4 book ai didi

java - 使用 proguard 的 Android 混淆应用程序保留 jar 库

转载 作者:行者123 更新时间:2023-11-30 02:38:52 26 4
gpt4 key购买 nike

我想创建使用混淆器的简单示例。
在我的示例中,我在 libs 文件夹中有 apfloat.jar 库,在 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();

}

}

当我使用此配置的混淆器时

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

当我使用此代码时,我的示例导出正常,但当我在电话中吃午饭并单击按钮时,我的应用程序崩溃了。
那我该如何解决呢?感谢您的帮助。

最佳答案

我终于找到了答案。

-dontwarn org.jscience.**
-dontwarn org.apfloat.**

-keep class apfloat.** { *; }
-keep class org.jscience.** { *; }
-keep class org.apfloat.** { *; }

关于java - 使用 proguard 的 Android 混淆应用程序保留 jar 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26081934/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com