简体   繁体   中英

Android Studio: I am receiving an error when trying to implement OKHTTP3 into the build.gradle

I'm getting the following error in android studio when I add OKHTTP3 to the app level build.gradle and attempt to sync the build.gradle:

ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.squareup.okhttp3:okhttp:4.4.0.

My code for implementing the dependency looks like this:

dependencies {
    ...
    implementation 'com.squareup.okhttp3:okhttp:4.4.0'
    ...
}

This is the latest version of OKHTTP3 that I took from https://search.maven.org/artifact/com.squareup.okhttp3/okhttp/4.4.0/jar so this should work fine.

In the project level build.gradle I have jcenter() included within the repositories at both the buildscript and allprojects levels so I am unsure why I am receiving the above error as, from other stackoverflow questions, I can see that jcenter() is the maven central repository which this library comes from.

I have looked at all other stackoverflow questions on this matter but none of their solutions are working for me and I am receiving the same error regardless of any attempts.

I appreciate any suggestion anyone may have. Thank you in advance.

For anyone who runs into the above problem. This is what worked for me:

I did some research into the new Android Studio version as I figured out that I had done everything else correctly and the error was most likely to do with the recent Android Studio update. To fix the above solution, I toggled the build.gradle offline mode to off which resolved the entire problem.

To perform the same steps, this is taken from Android Studio's 3.6 blog post:

New location to toggle Gradle's offline mode To enable or disable Gradle's offline mode, first select View > Tool Windows > Gradle from the menu bar. Then, near the top of the Gradle window, click Toggle Offline Mode Gradle offline button in the Gradle panel..

This post can be found here https://developer.android.com/studio/preview/features#gradle-offline-ui

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM