[英]Proguard and Scoreloop
I'm trying to use Proguard on my Android projet and keep getting the same error at runtime on the Scoreloop (version 3.0.3) library... 我正在尝试在Android Projet上使用Proguard,并在运行时在Scoreloop(版本3.0.3)库中保持相同的错误...
I defined the proguard config file as follow in the project.properties file: 我在project.properties文件中定义了proguard配置文件,如下所示:
proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt
proguard.enabled=true
And here is my proguard-project.txt file (with everything included in case I did something wrong somewhere...): 这是我的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.** { *; }
I'm getting this error at runtime: 我在运行时遇到此错误:
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)
From the file mapping.txt, I found this regarding the problematic classes and calls: 从文件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:
[...]
So I thought the error said that it couldn't find the constructor of Client taking a Session. 所以我以为错误表明无法找到进行Session的Client的构造函数。 I tried adding the following to my proguard conf: 我尝试将以下内容添加到我的proguard conf中:
-keep class com.scoreloop.client.android.core.model.** {*;}
-keepclassmembers class com.scoreloop.client.android.core.model.**
With no luck, now I'm getting this error: 运气不好,现在我得到这个错误:
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)
And now I'm a bit lost on what to try next... Any idea and enlightenment on this error ? 现在,我对下一步的尝试感到迷茫...对这个错误有任何想法和启示吗?
After a response from Scoreloop support and some tests on my side, here is the ProGuard configuration for Scoreloop: 在获得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.** { *; }
The code performs reflection and can't find a constructor, so you indeed have to make sure that it's preserved. 该代码执行反射并且找不到构造函数,因此您确实必须确保将其保留。 Your -keep option is preserving all classes/fields/methods in the specified package and its subpackages: 您的-keep选项将保留指定包及其子包中的所有类/字段/方法:
-keep class com.scoreloop.client.android.core.model.** {*;}
However, the code is probably trying to find the constructor of a class outside this package -- the stack trace unfortunately doesn't tell. 但是,代码可能正在尝试在此程序包之外查找类的构造函数-不幸的是,堆栈跟踪无法说明。 You'll have to figure out which class (or set of classes) this is, and then keep its constructor. 您必须弄清楚这是哪个类(或一组类),然后保留其构造函数。
Note that your -keepclassmembers option doesn't do anything (because it doesn't specify any class members), but it is not necessary. 请注意,您的-keepclassmembers选项不执行任何操作(因为它未指定任何类成员),但这不是必需的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.