离线Android Gradle插件 [英] Offline Android Gradle Plugin

查看:163
本文介绍了离线Android Gradle插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问有人对我可以从中下载离线android gradle插件的其他网站有想法吗?我以前是从developer.android官方网站上下载的,但是它们只有beta版本,而没有插件本身,它一直在给我错误ID为'com.android.application'的错误插件,我运行的是Android 4.0 btw

Please does anyone have idea of another site I can download the offline android gradle plugin from? I previously downloaded it from the official developer.android site but they only have the beta version and not the plugin itself,it keeps giving me error plugin with id 'com.android.application' not found,I run Android 4.0 btw

推荐答案

Android Gradle插件托管在Google的Maven存储库中:https://maven.google.com/您可以使用所需的 com.android.tools.build:gradle 工件来制作 pom.xml ,并使用 mvn依赖项:resolve 来下载插件及其所有依赖项,包括可传递的依赖项.Gradle不支持开箱即用的类似操作,请参阅此问题的答案,以了解使用Gradle完成相同任务的方法.

Android Gradle Plugin is hosted at Google's Maven repository: https://maven.google.com/ You can craft pom.xml with the needed com.android.tools.build:gradle artifact and use mvn dependency:resolve to download both the plugin and all it's dependencies, including transitive ones. Gradle doesn't support similar action out of the box, see answers to this question for the ways to achieve the same task with Gradle.

我不记得 id'com.android.application'可以通过 settings.gradle 中的 pluginManagement {...} 进行任何修改而工作了代码>,类似于以下内容:

I don't recall id 'com.android.application' working without any modifications via pluginManagement { ... } in settings.gradle, similar to the following:

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()

        mavenLocal() // one should add this for artifacts mirrored locally
    }
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id.startsWith("com.android.")) {
                useModule("com.android.tools.build:gradle:${requested.version}")
            }
        }
    }
}

如果使用相同的方法,请不要忘记将本地存储库(无论是 mavenLocal()还是其他内容)添加到 pluginManagement {存储库{...}} .

If you use the same way, don't forget to add your local repository, be it mavenLocal() or anything else, to pluginManagement { repositories { ... }}.

对于与Android插件无关的一般情况(还?):

For the general case unrelated to Android plugin (yet?):

名为 com.example.myplugin 的插件应具有 com.example.myplugin:com.example.myplugin.gradle.plugin:... 的相应工件在Gradle插件存储库中( https://plugins.gradle.org/m2 ).还应在本地镜像此工件,以使 id"com.example.myplugin" 正常工作.

A plugin called com.example.myplugin should have the corresponding artifact of com.example.myplugin:com.example.myplugin.gradle.plugin:... in Gradle plugins repository (https://plugins.gradle.org/m2). This artifact should also be mirrored locally for id "com.example.myplugin" to work.

作为参考,这是完整的 pom.xml ,我用它下载了AGP 4.0.0所需的所有工件:

For the reference, here's the full pom.xml that I've used to download all needed artifacts for AGP 4.0.0:

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>my-app</artifactId>
  <version>1</version>
  <dependencies>
    <dependency>
      <groupId>com.android.tools.build</groupId>
      <artifactId>gradle</artifactId>
      <version>3.6.3</version>
    </dependency>
    <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-stdlib-jdk8</artifactId>
      <version>1.3.61</version>
    </dependency>
    <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-reflect</artifactId>
      <version>1.3.61</version>
    </dependency>
    <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-stdlib</artifactId>
      <version>1.3.61</version>
    </dependency>
    <dependency>
      <groupId>com.google.code.findbugs</groupId>
      <artifactId>jsr305</artifactId>
      <version>3.0.2</version>
    </dependency>
    <!-- addendum for 4.0.0 -->
    <dependency>
      <groupId>com.google.errorprone</groupId>
      <artifactId>error_prone_annotations</artifactId>
      <version>2.3.2</version>
    </dependency>
  </dependencies>
  <repositories>
    <repository>
      <id>goog</id>
      <url>https://dl.google.com/android/maven2</url>
    </repository>
    <repository>
      <id>jcr</id>
      <url>https://jcenter.bintray.com</url>
    </repository>
  </repositories>
</project>

运行 mvndependency:resolve 工件将驻留在〜/.m2/repository 中,因此剩下的就是添加 mavenLocal() pluginManagement {存储库{...}} (或使用旧样式的插件使用 buildscript {存储库{...}} ).

After running mvn dependency:resolve artifacts would reside in ~/.m2/repository, so all that's left is to add mavenLocal() to pluginManagement { repositories { ... } } (or buildscript { repositories { ... } } for old style of applying plugins).

这篇关于离线Android Gradle插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆