Chinez
Chinez

Reputation: 593

Offline Android Gradle Plugin

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

Upvotes: 0

Views: 3016

Answers (1)

r4zzz4k
r4zzz4k

Reputation: 716

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.

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}")
            }
        }
    }
}

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

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

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.

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>

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

Upvotes: 1

Related Questions