之前一直有使用Leancloud,就这次不行,看log猜测是这个项目中使用了Gson,和sdk中的混淆导致的。
App进行初始化时报错:
2022-07-27 20:38:40.667 7497-7497/cn.spacexc.wearbili E/AndroidRuntime: FATAL EXCEPTION: main
Process: cn.spacexc.wearbili, PID: 7497
java.lang.NoSuchMethodError: No direct method <init>(Ljava/util/Map;)V in class Lcom/google/gson/internal/ConstructorConstructor; or its super classes (declaration of 'com.google.gson.internal.ConstructorConstructor' appears in /data/app/~~ARsCx9TjclW4rvO2XaEssA==/cn.spacexc.wearbili-CmU68Hk2IGK9lqsiWt2Tug==/base.apk!classes14.dex)
at cn.leancloud.gson.GeneralObjectAdapter.<init>(GeneralObjectAdapter.java:20)
at cn.leancloud.gson.GsonWrapper.<clinit>(GsonWrapper.java:57)
at cn.leancloud.gson.GsonWrapper.getGsonInstance(GsonWrapper.java:70)
at cn.leancloud.gson.GSONConverterFactory.generateRetrofitConverterFactory(GSONConverterFactory.java:9)
at cn.leancloud.core.AppConfiguration.<clinit>(AppConfiguration.java:45)
at cn.leancloud.core.AppConfiguration.getRetrofitConverterFactory(AppConfiguration.java:100)
at cn.leancloud.core.AppRouter.<init>(AppRouter.java:107)
at cn.leancloud.core.AppRouter.getInstance(AppRouter.java:37)
at cn.leancloud.core.LeanCloud.setServer(LeanCloud.java:104)
at cn.leancloud.core.LeanCloud.setServerURLs(LeanCloud.java:114)
at cn.leancloud.LeanCloud.initializeSecurely(LeanCloud.java:123)
at cn.spacexc.wearbili.Application.onCreate(Application.kt:54)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6707)
at android.app.ActivityThread.access$1300(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7651)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
我发现问题时认为是代码混淆没有配置,于是翻阅文档,发现找不到里面所说的proguard.cfg,上网一查貌似已经被弃用了(?)。到sdk目录下找到了proguard-android.txt
、proguard-android-optmize.txt
、proguard-project.txt
,其中两个都写着被弃用了,三个文件都copy了配置,包括项目内的proguard-rules.pro
,但貌似没什么用,依旧报错。下面是我的初始化代码:
override fun onCreate() {
super.onCreate()
context = this
AppCenter.start(
this, "0365b962-2310-4b53-ba45-d92d84171f57",
Analytics::class.java, Crashes::class.java
)
LeanCloud.initializeSecurely(this, "MAE7LopsPz1kgP3deSjzQ67g-gzGzoHsz", "https://mae7lops.lc-cn-n1-shared.com")
}
请问各位大佬问题到底出在哪里呢,代码混淆在最新版agp(7.2.1)怎么配置呢?先行谢过。