Gradle play-services aar dependency not work

一世执手 提交于 2019-12-25 07:16:07

问题


I am writing a java jar library. I just want to add play-services dependency for gradle's project. My gradle build script:

Properties local = new Properties()
local.load(project.file('local.properties').newDataInputStream())

ext {

    gdxVersion = '1.9.2';
    sdkPath = local.getProperty("sdk.dir")
}

repositories {

    maven { url "$sdkPath\\extras\\google\\m2repository\\" }
    maven { url "$sdkPath\\extras\\android\\m2repository\\" }

    maven { url "https://oss.sonatype.org/content/repositories/releases/" }

    mavenCentral()
}

apply plugin: 'java'
apply plugin: 'idea'

buildDir = 'gen'
libsDirName = '../bin'

sourceCompatibility = 1.8

sourceSets {

     main {

         java {

             srcDir 'src'
         }
     }
}

dependencies {

    compile "com.google.android.gms:play-services-ads:9.0.2";
    compile "com.google.android:android:4.1.1.4"
    compile "com.badlogicgames.gdx:gdx:$gdxVersion"
    compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
}

clean {

    delete fileTree(project.libsDir)
}

Gradle sync completes good and android studio tells that all ok but when I try to build:

error: package com.google.android.gms.ads does not exist

Google support repository and library are installed.

SDK MANAGER SCREENSHOT

Android studio gradle section: gradle screenshot

My gradle version 2.13. Also I used the latest gradle release candidate. Nothing.


回答1:


The problem was with the gradle script. If you want to build the aar dependency you need to use gradle plugin 'com.android.library'.

buildscript {

    repositories {

        maven { url "https://oss.sonatype.org/content/repositories/releases/" }

        mavenCentral()
    }

    dependencies {

        classpath "com.android.tools.build:gradle:2.1.2"
    }
}

apply plugin: 'com.android.library'


来源:https://stackoverflow.com/questions/37688329/gradle-play-services-aar-dependency-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!