hasanghaforian
hasanghaforian

Reputation: 14042

Android Studio offline add `Android plugin for Gradle`

I use Android Studio 3.1.2 with Gradle 4.4 and have to force Gradle to do off-line work, because when I use it normally (on-line), it takes to long to sync and fails. At first I got this error:

No cached version of com.android.tools.build:gradle:3.1.2 available for offline mode.
Disable Gradle 'offline mode' and sync project

So I downloaded gradle-3.1.2.jar, put it in <project root>/libs/ and change build.gradle of my project to this state:

buildscript {

    repositories {
        google()
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

Now it seems that previous error is solved but another one is raised:

Unable to load class 'com.android.tools.lint.gradle.api.ToolingRegistryProvider'.
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)</li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)</li><li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

How I can solve this problem?

Edit

I know the normal way is working on-line, at least for the first build. But there must be a way to add it off-line. Isn't there such way?

Upvotes: 0

Views: 1405

Answers (2)

Paraskevas Ntsounos
Paraskevas Ntsounos

Reputation: 1777

This is from android studio manual from this link.

Turn on Offline Mode for Gradle: If you have limited bandwitch, turn on Offline Mode to prevent Gradle from attempting to download missing dependencies during your build. When Offline Mode is on, Gradle will issue a build failure if you are missing any dependencies, instead of attempting to download them. To turn on Offline Mode, proceed as follows:

  • Click File > Settings (on a Mac, Android Studio > Preferences) to open the Settings dialog.

  • In the left pane, expand Build, Execution, Deployment and then click Gradle.

  • Under Global Gradle settings, check the Offline work checkbox.

  • Click Apply or OK for your changes to take effect.

Upvotes: 1

raghu kambaa
raghu kambaa

Reputation: 115

In android studio Go to setting menu > Built,Execution and development option > Gradle > mark/unmark on your offline work option and sync your project.try this.

Upvotes: 0

Related Questions