android - Android Studio离线添加 `Android plugin for Gradle`

标签 android android-studio gradle

我将Android Studio 3.1.2Gradle 4.4结合使用,并且不得不强制Gradle进行离线工作,因为当我正常(在线)使用它时,同步需要很长时间,并且失败。起初我得到这个错误:

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

所以我下载了gradle-3.1.2.jar,将其放在<project root>/libs/中,然后将项目的build.gradle更改为以下状态:
buildscript {

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

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

现在看来以前的错误已解决,但又引发了另一个错误:
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.

我该如何解决这个问题?

编辑

我知道正常的方式是在线工作,至少对于第一个版本。但是必须有一种离线添加的方法。不是这样吗?

最佳答案

这来自this link的android studio手册。

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:


  • 单击文件>设置(在Mac上为Android Studio>首选项)以
    打开设置对话框。
  • 在左 Pane 中,展开“构建,执行,部署”,然后单击“确定”。
    Gradle 。
  • 在“全局Gradle”设置下,选中“脱机工作”复选框。
  • 单击“应用”或“确定”使更改生效。
  • 关于android - Android Studio离线添加 `Android plugin for Gradle`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50678385/

    相关文章:

    更改sdk路径后Android studio报错

    android - 运行android应用程序时出现java.lang.UnsatisfiedLinkError

    android - Protobuf Android在生成的文件夹中包含构建类型

    javascript - Android 和 svg 中的平面图

    android - Jetpack Compose LazyColumn 文本消失

    android - setVisibility() 和 setAlpha() 之间的区别

    android -/dev/kvm 权限被拒绝的 android 模拟器

    android - 从 Android Studio 2.1 切换到 2.2 时出错

    android - Libgdx项目导入构建路径错误

    eclipse - 如何在 Eclipse 中使用 Buildship 刷新项目依赖项?