2

我正在尝试在我的 Android 项目上使用 Proguard,并在运行时在 Scoreloop(版本 3.0.3)库上不断收到相同的错误...

我在 project.properties 文件中定义了 proguard 配置文件,如下所示:

proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt
proguard.enabled=true

这是我的 proguard-project.txt 文件(包含所有内容,以防我在某处做错了什么......):

# ####### #
# Project #
# ####### #
-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.BackupAgentHelper
-keep public class * extends android.preference.Preference


# ##### #
# AdMob #
# ##### #
-keep public class com.google.ads.** {*;}
-keep public class com.google.gson.** {*;}


# #### #
# ACRA #
# #### #
# we need line numbers in our stack traces otherwise they are pretty useless
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

# ACRA needs "annotations" so add this... 
-keepattributes *Annotation*

# keep this class so that logging will show 'ACRA' and not a obfuscated name like 'a'.
# Note: if you are removing log messages elsewhere in this file then this isn't necessary
-keep class org.acra.ACRA {*;}

# keep this around for some enums and classes that ACRA needs
-keep class org.acra.ReportingInteractionMode {*;}
#-keep class org.acra.ReportField {*;}
-keepnames class org.acra.ReportField {*;}

# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter {
    public void addCustomData(java.lang.String,java.lang.String);
}
-keep public class org.acra.ErrorReporter {
    public org.acra.ErrorReporter$ReportsSenderWorker handleSilentException(java.lang.Throwable);
}


# ######### #
# Scoreloop #
# ######### #
-dontwarn com.scoreloop.client.android.core.paymentprovider.**
-keep class com.scoreloop.client.android.core.paymentprovider.fortumo.FortumoPaymentProviderController {*;}
-keep class com.scoreloop.client.android.core.paymentprovider.fortumo.FortumoPaymentProvider {*;}
-keep class com.scoreloop.client.android.core.paymentprovider.paypalx.PayPalXPaymentProviderController {*;}
-dontwarn com.scoreloop.client.android.core.ui.WebViewDialog
-keep class com.scoreloop.client.android.core.ui.WebViewDialog {*;}
-keep class com.facebook.android.** {*;}


# ############## #
# In-App Billing #
# ############## #
# -keep class com.android.vending.billing.**


# ####### #
# OrmLite #
# ####### #
# OrmLite uses reflection
-keep class com.j256.**
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**
-keepclassmembers interface com.j256.** { *; }

我在运行时收到此错误:

Caused by: java.lang.IllegalArgumentException: java.lang.NoSuchMethodException: <init> [class com.scoreloop.client.android.core.b.aw]
    at com.scoreloop.client.android.core.b.j.a(SourceFile:692)
    at com.scoreloop.client.android.core.b.j.<init>(SourceFile:368)
    at com.sofresh.games.megaflux.MegaFluxApplication.onCreate(SourceFile:106)
    at com.sofresh.games.megaflux.MegaFluxApplication_.onCreate(SourceFile:19)
    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1000)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4391)
    ... 10 more
 Caused by: java.lang.NoSuchMethodException: <init> [class com.scoreloop.client.android.core.b.aw]
    at java.lang.Class.getConstructorOrMethod(Class.java:460)
    at java.lang.Class.getConstructor(Class.java:431)
    at com.scoreloop.client.android.core.b.j.a(SourceFile:684)

从文件 mapping.txt 中,我发现了关于有问题的类和调用:

com.scoreloop.client.android.core.model.Client -> com.scoreloop.client.android.core.b.j:
    java.util.Map a -> a
    com.scoreloop.client.android.core.model.ClientObserver b -> b
    com.scoreloop.client.android.core.model.Session c -> c
    103:104:boolean a(java.util.Properties,java.lang.String,boolean) -> a
    155:178:java.util.Properties a(android.content.Context) -> a
    182:185:void a(java.util.Properties,java.lang.String) -> a
    188:194:void a(java.util.Properties,java.lang.String,java.lang.String) -> a
    198:232:void a(android.content.Context,java.lang.String) -> a
    380:387:void a(java.util.Properties) -> a
    638:640:int b(java.util.Properties,java.lang.String) -> b
    684:692:void a(java.lang.Class) -> a
    708:711:void a$2a1b557e(com.scoreloop.client.android.core.model.Session) -> a
    715:718:boolean a(com.scoreloop.client.android.core.model.Session) -> b
    722:723:void b(android.content.Context) -> b
[...]
com.scoreloop.client.android.core.model.Session -> com.scoreloop.client.android.core.b.aw:
[...]

所以我以为报错说找不到Client接受Session的构造函数。我尝试将以下内容添加到我的 proguard conf 中:

-keep class com.scoreloop.client.android.core.model.** {*;}
-keepclassmembers class com.scoreloop.client.android.core.model.**

没有运气,现在我收到了这个错误:

Caused by: java.lang.IllegalArgumentException: java.lang.NoSuchMethodException: <init> [class com.scoreloop.client.android.core.model.Session]
    at com.scoreloop.client.android.core.model.Client.a(SourceFile:692)
    at com.scoreloop.client.android.core.model.Client.a(SourceFile:605)
    at com.scoreloop.client.android.core.model.Client.<init>(SourceFile:368)
    at com.blabla.MyApplication.onCreate(SourceFile:106)
    at com.blabla.MyApplication_.onCreate(SourceFile:19)
    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1000)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4391)
    ... 10 more
 Caused by: java.lang.NoSuchMethodException: <init> [class com.scoreloop.client.android.core.model.Session]
    at java.lang.Class.getConstructorOrMethod(Class.java:460)
    at java.lang.Class.getConstructor(Class.java:431)
    at com.scoreloop.client.android.core.model.Client.a(SourceFile:684)

现在我对接下来要尝试什么有点迷失了......关于这个错误的任何想法和启示?

4

2 回答 2

3

在收到 Scoreloop 支持的响应和我这边的一些测试后,这里是 Scoreloop 的 ProGuard 配置:

# ######### #
# Scoreloop #
# ######### #
-dontwarn com.scoreloop.client.android.core.paymentprovider.**
-keep class com.scoreloop.client.android.core.paymentprovider.fortumo.FortumoPaymentProviderController {*;}
-keep class com.scoreloop.client.android.core.paymentprovider.fortumo.FortumoPaymentProvider {*;}
-keep class com.scoreloop.client.android.core.paymentprovider.paypalx.PayPalXPaymentProviderController {*;}
-dontwarn com.scoreloop.client.android.core.ui.WebViewDialog
-keep class com.scoreloop.client.android.core.ui.WebViewDialog {*;}
-keep class com.facebook.android.** {*;}
-keep class com.scoreloop.client.android.core.** { *; }
于 2013-02-27T15:35:37.913 回答
2

该代码执行反射并且找不到构造函数,因此您确实必须确保它被保留。您的 -keep 选项保留指定包及其子包中的所有类/字段/方法:

-keep class com.scoreloop.client.android.core.model.** {*;}

然而,代码可能试图在这个包之外找到一个类的构造函数——不幸的是堆栈跟踪没有告诉。您必须弄清楚这是哪个类(或一组类),然后保留其构造函数。

请注意,您的 -keepclassmembers 选项不会做任何事情(因为它没有指定任何类成员),但这不是必需的。

于 2013-01-16T01:45:54.617 回答