【问题标题】:Offline Android Gradle Plugin离线 Android Gradle 插件
【发布时间】:2020-08-24 23:22:12
【问题描述】:

请问有人知道我可以从哪个网站下载离线 android gradle 插件吗? 我之前从官方 developer.android 网站下载了它,但他们只有 beta 版本,没有插件本身,它一直给我错误插件,id 'com.android.application' not found,我运行的是 Android 4.0 btw

【问题讨论】:

    标签: android android-studio gradle plugins offline


    【解决方案1】:

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

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

    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 { repositories { ... }}

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

    名为 com.example.myplugin 的插件应该在 Gradle 插件存储库 (https://plugins.gradle.org/m2) 中具有 com.example.myplugin:com.example.myplugin.gradle.plugin:... 的对应工件。这个工件也应该在本地镜像,以便id "com.example.myplugin" 工作。

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

      <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>
    

    运行mvn dependency:resolve 后,工件将驻留在~/.m2/repository 中,所以剩下的就是将mavenLocal() 添加到pluginManagement { repositories { ... } }(或buildscript { repositories { ... } } 用于旧式应用插件)。

    【讨论】:

    • 我已经下载了离线依赖,唯一的问题是离线插件,他们可能发布了错误的插件,因为它说“运行后找不到ID为'com.android.application'的插件
    • 当然。请参阅 gist.github.com/r4zzz4k/064d286a5b4e2322475b3efae1cc69b0 pom.xml 有我必须下载的所有依赖项的列表。然后我跑了mvn dependency:resolve。之后gradle tasks 成功获取插件(注意除了mavenLocal() 之外没有存储库),由于未完成配置,AGP 本身将我丢弃compileSdkVersion is not specified
    • 我刚刚更新了 4.0.0,它需要一个额外的依赖项。如果它帮助您解决问题,请不要忘记接受答案:)
    • 好的,在反复解决这个问题后,我发现错误与我的 Build.app 模块源代码有关,请您将完整的 build.app 模块源代码发送给我,以便我可以检查我是否可以配置它
    • 我不确定“Build.app 模块源代码”是什么意思。你能澄清一下吗?
    猜你喜欢
    • 2021-12-17
    • 1970-01-01
    • 2016-09-05
    • 1970-01-01
    • 2017-10-21
    • 1970-01-01
    • 2018-10-21
    • 1970-01-01
    • 2020-07-08
    相关资源
    最近更新 更多