GetStream / stream-chat-android

:speech_balloon: Android Chat SDK ➜ Stream Chat API. UI component libraries for chat apps. Kotlin & Jetpack Compose messaging SDK for Android chat
https://getstream.io/chat/sdk/android/
Other
1.47k stars 273 forks source link

Getting Error in Release Builds. #4614

Closed rethinavelsmitch closed 1 year ago

rethinavelsmitch commented 1 year ago

Describe the bug GetStream is one of the best chat SDK. The app is working very fine when I run the debug build. But unfortunately, I am getting error while taking the release build. I had added the screenshots for reference.

Unexpected signature for public final io.getstream.chat.android.client.api2.model.dto.DownstreamMessageDto io.getstream.chat.android.client.parser2.adapters.DownstreamMessageDtoAdapter.fromJson(com.squareup.moshi.JsonReader,com.squareup.moshi.JsonAdapter,com.squareup.moshi.JsonAdapter).

image
Error Logs : `FATAL EXCEPTION: main
                 Process: com.mysmitch.care, PID: 30907
                 java.lang.RuntimeException: Unable to create application com.mysmitch.care.ui.MainApplication: java.lang.IllegalArgumentException: Unexpected signature for public final io.getstream.chat.android.client.api2.model.dto.DownstreamMessageDto io.getstream.chat.android.client.parser2.adapters.DownstreamMessageDtoAdapter.fromJson(com.squareup.moshi.JsonReader,com.squareup.moshi.JsonAdapter,com.squareup.moshi.JsonAdapter).
                 @FromJson method signatures may have one of the following structures:
                     <any access modifier> R fromJson(JsonReader jsonReader) throws <any>;
                     <any access modifier> R fromJson(JsonReader jsonReader, JsonAdapter<any> delegate, <any more delegates>) throws <any>;
                     <any access modifier> R fromJson(T value) throws <any>;
                    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7593)
                    at android.app.ActivityThread.access$1700(ActivityThread.java:315)
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2286)
                    at android.os.Handler.dispatchMessage(Handler.java:106)
                    at android.os.Looper.loopOnce(Looper.java:226)
                    at android.os.Looper.loop(Looper.java:313)
                    at android.app.ActivityThread.main(ActivityThread.java:8751)
                    at java.lang.reflect.Method.invoke(Native Method)
                    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
                 Caused by: java.lang.IllegalArgumentException: Unexpected signature for public final io.getstream.chat.android.client.api2.model.dto.DownstreamMessageDto io.getstream.chat.android.client.parser2.adapters.DownstreamMessageDtoAdapter.fromJson(com.squareup.moshi.JsonReader,com.squareup.moshi.JsonAdapter,com.squareup.moshi.JsonAdapter).
                 @FromJson method signatures may have one of the following structures:
                     <any access modifier> R fromJson(JsonReader jsonReader) throws <any>;
                     <any access modifier> R fromJson(JsonReader jsonReader, JsonAdapter<any> delegate, <any more delegates>) throws <any>;
                     <any access modifier> R fromJson(T value) throws <any>;

                    at com.squareup.moshi.AdapterMethodsFactory.fromAdapter(SourceFile:301)
                    at com.squareup.moshi.AdapterMethodsFactory.get(SourceFile:135)
                    at com.squareup.moshi.Moshi$Builder.add(SourceFile:224)
                    at io.getstream.chat.android.client.parser2.MoshiChatParser$moshi$2.invoke(SourceFile:65)
                    at io.getstream.chat.android.client.parser2.MoshiChatParser$moshi$2.invoke(SourceFile:60)
                    at kotlin.SynchronizedLazyImpl.getValue(SourceFile:74)
                    at io.getstream.chat.android.client.parser2.MoshiChatParser.getMoshi(SourceFile:60)
                    at io.getstream.chat.android.client.parser2.MoshiChatParser.<init>(SourceFile:93)`

To Reproduce Steps to reproduce the behavior:

 ChatClient.instance().connectUser(chatUser, prefs.chatAccessToken).enqueue { result ->
                if (result.isSuccess) {
                    Timber.e("--> Chat User set successfully")
                    FirebaseLogger.userId = result.data().user.id
                    chatApplication.userRepository.setType("")
                    chatApplication.userRepository.setUser(
                        SampleUser(
                            apiKey = GET_STREAM_API_KEY,
                            id = prefs.smitchId,
                            name = prefs.loggedUserName,
                            subText = "",
                            token = prefs.chatAccessToken,
                            image = "https://getstream.io/random_png?id=${prefs.smitchId}&name=${prefs.loggedUserName}&size=200"
                        )
                    )
                } else {
                    Timber.e("Failed to set user ${result.error()}")
                }
            }

Expected behavior It should create a connection

Device:

apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'androidx.navigation.safeargs.kotlin' apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.firebase.crashlytics' //apply plugin: 'com.huawei.agconnect' apply plugin: 'shot' apply plugin: 'kotlin-parcelize' apply plugin: 'com.google.devtools.ksp'

android { compileSdk 33 defaultConfig { buildConfigField 'String', 'STREAM_CHAT_VERSION', "\"$version\"" testApplicationId "io.getstream.chat.ui.sample" minSdk 23 targetSdk 33 }

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
    debug {
        minifyEnabled false
    }
    profile {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

packagingOptions {
    exclude 'META-INF/*'
}

lintOptions {
    abortOnError false
    xmlReport true
    checkDependencies true
    disable 'MissingTranslation'
}

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/ASL2.0'
}

buildFeatures {
    viewBinding true
}
sourceSets {
    all {
        it.java.srcDir "src/$it.name/kotlin"
    }
}

} `

This is my build.gradle file. I converted the sample app into a module and added into my app. Since it is a module and publicly available, I set minifyenabled property to false.

filbabic commented 1 year ago

Hey there @rethinavelsmitch !

Could you verify that there is no mismatch between the moshi versions in your app and our SDK?

And could you share your Stream SDK version so that we can look into this a bit more?

rethinavelsmitch commented 1 year ago

Hey @filbabic!

I am not using Moshi in my app. It is only used in Getstream Library module. Am using GsonConverter in my app. Is that a problem?

Get Stream SDK Version is : [5.11.8] Moshi Converter Version is : [internal const val MOSHI = "1.14.0"]

filbabic commented 1 year ago

@rethinavelsmitch

Thank you for the input!

Looking at the logs again and what you provided, it seems that the thing that's failing is the mismatch between the generated code.

Now this can be due to many things, different versions in the project setup, the way that generation is done or something similar.

Would you be able to provide a public repo with the absolute minimum setup required for this to be replicable? Maybe we can figure out if it's a kotlin version mismatch, kapt/KSP or something like that, that's generating incorrect (or mismatched) code.

rethinavelsmitch commented 1 year ago

@filbabic

Thanks for the response. I really can't disclose the source code. The app works fine when I set minifyenabled to false. I tried to keep the classes by writing the following proguard rules.

# Keep ToJson/FromJson-annotated methods -keepclassmembers class * { @com.squareup.moshi.FromJson <methods>; @com.squareup.moshi.ToJson <methods>; }

Why code obfuscation is happening if I still has the above lines in proguard rules.pro? Is that possible to keep all the classes in release build?

I will create a sample application and share it with you asap.

MarinTolic commented 1 year ago

Closing the issue until further feedback as some time has elapsed since the last response.