Could not resolve com.android.tools.build:gradle:2.2.3

It turns out the solution to my particular issue was relatively simple. The error message was a bit deceiving as this was not a problem with the offline mode switch, but rather confusion with the gradle file. Here are a few steps I took to fix the issue:

  1. For Android Studio 2.3 go to File>Settings>Gradle and select the "Use default gradle wrapper" option. Also make sure the checkbox next to "Offline work" is unchecked just in case.
  2. Click the "Apply" button
  3. Within the build.gradle file (the one named after your project) under the "Gradle Scripts" section of Android Studio make certain that your current build gradle class path matches the current version of Android Studio. An example for Android Studio 2.3:

    buildscript {
        repositories {
        jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.3.0'
        }
    }
    
  4. Also within the Gradle Scripts section make sure that your gradle-wrapper.properties file is referencing the correct gradle file in the distribution URL. For example for gradle 3.3:

    distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
    
  5. Navigate to C:\Program Files\Android\Android Studio\gradle and ensure there is a gradle folder with the same name as the gradle you are using. In my case I ensured there is a folder named gradle-3.3 with a zip file named gradle-3.3-all.zip. It is relatively easy to find this zip file online.

  6. Delete the .gradle folder in C:\Users\yourUser with yourUser being whichever user your Android Studio project is under.
  7. Close Android Studio and restart. It should begin the gradle sync process and rebuild the .gradle file.

For me when I did this it also complained about not finding the gradle-3.3-all.zip file in the .gradle folder. I was able to fix this by adding the gradle-3.3-all.zip file to C:\Users\yourUser.gradle\wrapper\dists\gradle-3.3-all\55gk2rcmfc6p2dg9u9ohc3hw9. I'm not sure if the folder has the same name for everyone, but whatever the name, that is the location I went to. If all this doesn't work I would try a variation of these steps, and hopefully it works for you.