0

I'm using an Android Gradle command line, not Android Studio, build and I'd like to be able to build/compile in a library from mavenCentral().

I'd like to know how to be able to do that for any general library, but one thing I want is to get a certain version of 'com.google.android.gms:play-services-maps' for my build.

From: https://mvnrepository.com/artifact/com.google.android.gms/play-services-maps

I can, for most versions, get the pom and the aar files so what do I have to do in my build.gradle, if I have access to these files, to get it to build in the project?

Most articles I saw are about how to generate a pom file, but not about how to use one in your project.

I'd really like to know how to just use a pom file in my build or how to use the information from it, but if I can get info on how to build using the aar file, that would be cool too.

Or how to use the information it gives in the 'Gradle' tab:

// https://mvnrepository.com/artifact/com.google.android.gms/play-services-maps
compile group: 'com.google.android.gms', name: 'play-services-maps', version: '12.0.0'

This is what I currently have, many things omitted, that doesn't work:

> Could not resolve all dependencies for configuration ':_debugApkCopy'.
    > Could not find com.google.android.gms:play-services-maps:12.0.0.
        Searched in the following locations:


buildscript {
    repositories {
        mavenCentral()
    }
}

dependencies {
    //compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services-maps:12.0.0'
}

I've also tried using the info from the 'Gradle' tab:

repositories {
    maven {
        url "https://mvnrepository.com/artifact/com.google.android.gms/play-services-maps"
    }
}

and

dependencies {
    compile group: 'com.google.android.gms', name: 'play-services-maps', version: '12.0.0'
}

Thanks!

user1572522
  • 569
  • 2
  • 11
  • 26
  • You can simply download and import aar file in AS. No need to worry about pom. For more details, please refer links [1](https://stackoverflow.com/questions/16682847/how-to-manually-include-external-aar-package-using-new-gradle-android-build-syst) and [2](https://stackoverflow.com/questions/29826717/how-to-import-a-aar-file-into-android-studio-1-1-0-and-use-it-in-my-code/38749847). – NightFury Jul 16 '18 at 20:05
  • @user1572522, let us know if my answer worked for you. – Amit K. Saha Jul 16 '18 at 20:37
  • I'm not using Android Studio. – user1572522 Jul 16 '18 at 22:31

2 Answers2

0

In your gradle file you need to add google() in repository-

 buildscript {
        repositories {
            mavenCentral()
            google()
        }
    }

How did I understand that : in the maven link there is -

Note: this artifact it located at Google repository (https://maven.google.com/)

But I see only mavenCentral() if you add google() in the repositories the following should work -

compile 'com.google.android.gms:play-services-maps:12.0.0'
Amit K. Saha
  • 5,871
  • 2
  • 27
  • 35
  • Adding 'google()' to repositories didn't work, it gets the same error message, and all the places it said it searched where local on my machine, it looked like it never tried to go out to get it. – user1572522 Jul 16 '18 at 22:42
  • Are you using a separate gradle i.e. not using the gradle bundled with the Android Studio? – Amit K. Saha Jul 17 '18 at 04:00
  • @user1572522, Make sure Gradle is not set to offline by unchecking button at File>Settings>Gradle>Offline Work. – Amit K. Saha Jul 17 '18 at 04:01
  • Yes, I'm using Gradle that isn't part of Android Studio. '--offline' is usually a command line option, and I'm not using it. The build error happens when I do 'gradle clean' on my project. – user1572522 Jul 17 '18 at 13:20
  • can you post your gradle.properties file both from you project and .gradle dir? – Amit K. Saha Jul 17 '18 at 14:39
0

I think I finally found the problem.

I read one post where they said that the main

buildscript {

}

block was mainly for the Android Plugin and you needed to create another repositories block to reference the download of the library you needed.

So my final build.gradle now looks like this:

buildscript {
    repositories {
    }
}

apply plugin: 'android'

repositories {
    maven {
        url "https://maven.google.com"
    }
    google()
}

dependencies {
    compile group: 'com.google.android.gms', name: 'play-services-maps', version: '12.0.0'
}

And when I saw it build, I could see it downloading from the repository, and it built clean!

I'm not sure which repository reference "worked" but what's there seemed to work.

Thanks!

user1572522
  • 569
  • 2
  • 11
  • 26