Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to instantiate the client #4597

Closed
desokroshan opened this issue Feb 6, 2019 · 7 comments
Closed

Unable to instantiate the client #4597

desokroshan opened this issue Feb 6, 2019 · 7 comments
Labels
bug Bug in existing code

Comments

@desokroshan
Copy link

While trying to instantiate OkHttpClient as follows inside the MainActivity of android:

OkHttpClient client = new OkHttpClient();

Stacktrace :

java.lang.BootstrapMethodError: Exception from call site #5 bootstrap method
    at okhttp3.internal.Util.<clinit>(Util.java:87)
    at okhttp3.internal.Util.immutableList(Util.java:234)
    at okhttp3.OkHttpClient.<clinit>(OkHttpClient.java:127)
    at com.amazonaws.transcribestreaminghttpclient.MainActivity.<init>(MainActivity.java:28)
    at java.lang.Class.newInstance(Native Method)
    at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:69)
    at android.support.v4.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:43)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1215)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2831)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)

Happens only on 3.13.1. Works well on 3.12.1.
Any insights?

@desokroshan desokroshan added the bug Bug in existing code label Feb 6, 2019
@JakeWharton
Copy link
Collaborator

Per the release notes, OkHttp requires that you enable Java 8 in your builds to function as of 3.13 and newer. You can learn more about how to enable this at https://developer.android.com/studio/write/java8-support.

You need to add something like

android {
    compileOptions {
        targetCompatibility = "8"
        sourceCompatibility = "8"
    }
}

to your application build.gradle.

@CHENGCHANGHU
Copy link

hello, i enabled JAVA 8 but it still did not work
`OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://www.baidu.com")
.build();
try {

                Response response = client.newCall(request).execute();
                String responseData = response.body().string();
                showResponse(responseData);
            } catch (IOException e) {
                e.printStackTrace();
            }`

compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }

@eddex
Copy link

eddex commented Mar 18, 2019

@CHENGCHANGHU make sure to do a Clean Project (Build > Clean Project) after you change the build.gradle file.

@mckasap
Copy link

mckasap commented Mar 20, 2019

After adding compileOption... cleaning and Building the project solved my problem thanks guys

@leetyk
Copy link

leetyk commented Mar 22, 2019

@CHENGCHANGHU make sure to do a Clean Project (Build > Clean Project) after you change the build.gradle file.

I have the same problem. Thank you for sharing.

facebook-github-bot pushed a commit to facebook/flipper that referenced this issue Apr 15, 2019
Summary:
Requires some compile options as it uses newer Java features.
Post here: square/okhttp#4597 (comment)

Reviewed By: jknoxville

Differential Revision: D14933502

fbshipit-source-id: 265c43f2d9ae61fa9f6f42516fc6eb899af7f072
@phamthelong
Copy link

Per the release notes, OkHttp requires that you enable Java 8 in your builds to function as of 3.13 and newer. You can learn more about how to enable this at https://developer.android.com/studio/write/java8-support.

You need to add something like

android {
    compileOptions {
        targetCompatibility = "8"
        sourceCompatibility = "8"
    }
}

to your application build.gradle.

thanks you

@michalharakal
Copy link

Just a hint for somebody wanting to add the compile options into build.gradle.kts

compileOptions {
        targetCompatibility = JavaVersion.VERSION_1_8
        sourceCompatibility = JavaVersion.VERSION_1_8
}

Dabami pushed a commit to helios-h2020/h.extension-RewardingModel that referenced this issue Jul 15, 2020
- Replaced kotlinx serializer by gson serializer due to open issue in github Kotlin/kotlinx.serialization#576
- Replaced okhttp android client by ktor android client due to issues related to kotlin. It seems that it is related to latest version of okjhttp but even compiling with jvm target 1.8 is still failing:
square/okhttp#4597
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug in existing code
Projects
None yet
Development

No branches or pull requests

8 participants