amplitude / Amplitude-Flutter

Official Amplitude Flutter SDK
https://developers.amplitude.com/docs/flutter-setup
MIT License
114 stars 75 forks source link

error from OkHttp with Amplitude init() from android app #58

Closed chong901 closed 3 years ago

chong901 commented 3 years ago

Steps to Reproduce

  1. use flutter command to create a new project
  2. try to init amplitude

    void initState() {
    super.initState();
    final amplitude =
        Amplitude.getInstance(instanceName: 'INSTANCE_NAME');
    
    amplitude.init('MY_API_KEY');
    }
  3. run the app on android and there are error messages from OkHttp
    W/.amplitude_tes(17596): Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setUseSessionTickets(Z)V (greylist-max-q,core-platform-api, reflection, denied)
    W/OkHttp  (17596): unable to load android socket classes
    W/OkHttp  (17596): java.lang.NoSuchMethodException: com.android.org.conscrypt.OpenSSLSocketImpl.setUseSessionTickets [boolean]
    W/OkHttp  (17596):  at java.lang.Class.getMethod(Class.java:2072)
    W/OkHttp  (17596):  at java.lang.Class.getDeclaredMethod(Class.java:2050)
    W/OkHttp  (17596):  at okhttp3.internal.platform.android.AndroidSocketAdapter.<init>(AndroidSocketAdapter.kt:34)
    W/OkHttp  (17596):  at okhttp3.internal.platform.android.StandardAndroidSocketAdapter.<init>(StandardAndroidSocketAdapter.kt:31)
    W/OkHttp  (17596):  at okhttp3.internal.platform.android.StandardAndroidSocketAdapter$Companion.buildIfSupported(StandardAndroidSocketAdapter.kt:57)
    W/OkHttp  (17596):  at okhttp3.internal.platform.android.StandardAndroidSocketAdapter$Companion.buildIfSupported$default(StandardAndroidSocketAdapter.kt:50)
    W/OkHttp  (17596):  at okhttp3.internal.platform.AndroidPlatform.<init>(AndroidPlatform.kt:44)
    W/OkHttp  (17596):  at okhttp3.internal.platform.AndroidPlatform$Companion.buildIfSupported(AndroidPlatform.kt:239)
    W/OkHttp  (17596):  at okhttp3.internal.platform.Platform$Companion.findPlatform(Platform.kt:211)
    W/OkHttp  (17596):  at okhttp3.internal.platform.Platform$Companion.access$findPlatform(Platform.kt:179)
    W/OkHttp  (17596):  at okhttp3.internal.platform.Platform.<clinit>(Platform.kt:180)
    W/OkHttp  (17596):  at okhttp3.OkHttpClient.<init>(OkHttpClient.kt:219)
    W/OkHttp  (17596):  at okhttp3.OkHttpClient.<init>(OkHttpClient.kt:211)
    W/OkHttp  (17596):  at com.amplitude.api.AmplitudeClient.lambda$initialize$0$AmplitudeClient(AmplitudeClient.java:287)
    W/OkHttp  (17596):  at com.amplitude.api.-$$Lambda$AmplitudeClient$9NDt_YKBCJ8Ih0Ic4HFC4DZmSRA.run(Unknown Source:8)
    W/OkHttp  (17596):  at android.os.Handler.handleCallback(Handler.java:938)
    W/OkHttp  (17596):  at android.os.Handler.dispatchMessage(Handler.java:99)
    W/OkHttp  (17596):  at android.os.Looper.loop(Looper.java:223)

Environment

SDK Version: v3.2.1 Flutter v2.2.1

not sure is here the right place to ask, but seems amplitude functionality is working properly, just wonder is there a way to avoid this error message?

Abhishek01039 commented 3 years ago

Hello @aaa59891 Is Amplitude-Flutter is free? How you setup the server ?

Thanks

qingzhuozhen commented 3 years ago

Hi @aaa59891, that error message is from okhttp3 in android, it could be caused for reflection in okhttp library didn't success. Can you try upgrade the okhttp version and try again? They may already have a fix in new version.

btw @Abhishek01039 yeah, Amplitude-Flutter is free to use. This is developer docs for reference.

Abhishek01039 commented 3 years ago

Thanks @qingzhuozhen

MahdiGhiasi commented 2 years ago

We're having the same issue. Is there currently any workaround for this? @qingzhuozhen

eleojasmil commented 2 years ago

Please open this issue. this is not fixed yet.

it only happen in Android 11. please update dependencies.

@qingzhuozhen or at least specify work around

izaaz commented 2 years ago

Here are a couple of workarounds that worked for me. Both involve editing the android/app/build.gradle file

  1. Set the compileSdkVersion to 28
  2. Under dependencies, add the latest version of the okhttp package
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation "com.squareup.okhttp3:okhttp:4.9.1"
}
erfanegtfi commented 1 year ago

This issue not fix yet

justin-fiedler commented 9 months ago

Hello, this is likely related to OkHttps use of reflection. See this answer for more information about OkHttp version and Android API version.

https://stackoverflow.com/a/70357341/5046784