初始化SDK时报java.lang.NoSuchMethodError

之前一直有使用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.txtproguard-android-optmize.txtproguard-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)怎么配置呢?先行谢过。

猜测是这个项目中使用了Gson,和sdk中的混淆导致的

看上去不是单纯的混淆问题。 @xiaoxu 有空看看吧

您好,请问您使用哪个 SDK 版本,可以看下这里面的文档说明:https://leancloud.cn/docs/sdk_setup-java.html#hash-1021083530

项目中使用的依赖:

dependencies {
    implementation 'androidx.core:core-ktx:1.8.0'
    implementation 'androidx.appcompat:appcompat:1.4.2'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.wear:wear:1.2.0'
    implementation 'com.google.zxing:core:3.5.0'
    implementation 'jp.wasabeef:glide-transformations:4.3.0'
    implementation 'com.github.ctiao:DanmakuFlameMaster:0.3.8'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.0-alpha01'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.0'
    implementation 'com.blankj:utilcode:1.30.7'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.5.0'
    implementation 'androidx.navigation:navigation-ui-ktx:2.5.0'
    //noinspection GradleCompatible
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'androidx.paging:paging-runtime-ktx:3.1.1'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'com.squareup.okhttp3:okhttp:4.9.3'
    implementation 'com.google.code.gson:gson:2.9.0'
    implementation 'com.github.bumptech.glide:glide:4.12.0'
    annotationProcessor 'com.github.bumptech.glide:glide:4.12.0'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
    implementation 'com.github.chrisbanes:PhotoView:2.3.0'
    def appCenterSdkVersion = '4.3.1'
    //noinspection GradleDependency
    implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
    //noinspection GradleDependency
    implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
    implementation 'com.google.android.exoplayer:exoplayer:2.18.0'
    implementation 'com.github.jxiang112:ExpandCollapseTextView:v1.0.2'
    implementation 'androidx.work:work-runtime-ktx:2.7.1'
    implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.24'
    implementation 'cn.leancloud:storage-android:8.2.5'
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
}