代码之家  ›  专栏  ›  技术社区  ›  hasanghaforian

Android Studio offline为Gradle添加Android插件`

  •  0
  • hasanghaforian  · 技术社区  · 6 年前

    我使用 Android Studio 3.1.2 具有 Gradle 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.
    

    我怎样才能解决这个问题?

    编辑

    我知道正常的方式是在线工作,至少在第一次构建时是这样。但必须有一种方法可以离线添加它。难道没有这样的方法吗?

    2 回复  |  直到 6 年前
        1
  •  1
  •   Paraskevas Ntsounos Charith Lakshitha    6 年前

    这是来自android studio手册 this link .

    为Gradle打开脱机模式:如果您有有限的BandSwitch,请打开 在脱机模式下,防止Gradle尝试下载丢失的 生成期间的依赖项。脱机模式打开时,Gradle将 如果缺少任何依赖项,则发出生成失败,而不是 正在尝试下载它们。要打开脱机模式,请按以下步骤继续 跟随:

    • 单击“文件”>设置(在Mac、Android Studio上)为 打开“设置”对话框。

    • 在左侧窗格中,展开Build、Execution、Deployment,然后单击 格拉德尔。

    • 在“全局渐变设置”下,选中“脱机工作”复选框。

    • 单击应用或确定以使更改生效。

        2
  •  0
  •   raghu kambaa    6 年前

    在android studio中,转到 背景 菜单(>); 建造、执行和开发 选项(>); 格拉德尔 &燃气轮机;标记/取消标记 离线作业 选项并同步项目。试试这个。