How to reference dependencies packages into an Android Library like .aar file?

偶尔善良 提交于 2019-12-06 00:43:34

问题


I have an android-library plugin that uses several android libraries included as .jar files and referenced directly from my build.gradle file :

compile fileTree(dir: 'libs', include: '*.jar')

I would then issue a gradlew assembleRelease command to create a .aar file that would be usable within an android application. This has always been working well for me up to now.

I now need to use the Google Play Services in my android-library. As it is instructed in the official Android documentation (http://developer.android.com/google/play-services/setup.html#Setup), I need to include the Google Play Services as a library project by importing it from maven :

compile 'com.google.android.gms:play-services:4.3.23'

But when I build my .aar file, the Google Play Services do not seem to be included in it (my .aar file is only 200kb, and the Google Play Services .jar library is > than 1mb).

I've read that the Google Play Services should be referenced as an Android Library Module, but I can't manage to import it like that without compilation errors. Can someone help me to have the Google Play Services packaged into my android-library?

My android-library build.gradle file :

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android-library'

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.google.android.gms:play-services:4.3.23'
    compile fileTree(dir: 'libs', include: '*.jar')
}

android {
    compileSdkVersion 19
    buildToolsVersion '19.0.1'

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
    }
    release {
        runProguard false
    }
}

My android application build.gradle file :

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
    }
    buildTypes {
        release {
            runProguard true
            proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
        }
    }
    productFlavors {
        defaultFlavor {
            proguardFile 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile 'novom.anyware.anywaresdk:anywaresdk:0.1.0@aar'
}

When issuing a gradle dependencies from the root of my main module, here is my result :

Relying on packaging to define the extension of the main artifact has been depre
cated and is scheduled to be removed in Gradle 2.0
:MyOldApp:dependencies

------------------------------------------------------------
Project :MyOldApp
------------------------------------------------------------

_DefaultFlavorDebugApk
+--- com.android.support:appcompat-v7:+ -> 19.1.0
|    \--- com.android.support:support-v4:19.1.0
\--- novom.anyware.anywaresdk:anywaresdk:0.1.0

_DefaultFlavorDebugCompile
+--- com.android.support:appcompat-v7:+ -> 19.1.0
|    \--- com.android.support:support-v4:19.1.0
\--- novom.anyware.anywaresdk:anywaresdk:0.1.0

_DefaultFlavorReleaseApk
+--- com.android.support:appcompat-v7:+ -> 19.1.0
|    \--- com.android.support:support-v4:19.1.0
\--- novom.anyware.anywaresdk:anywaresdk:0.1.0

_DefaultFlavorReleaseCompile
+--- com.android.support:appcompat-v7:+ -> 19.1.0
|    \--- com.android.support:support-v4:19.1.0
\--- novom.anyware.anywaresdk:anywaresdk:0.1.0

_DefaultFlavorTestApk
No dependencies

_DefaultFlavorTestCompile
No dependencies

apk - Classpath packaged with the compiled main classes.
+--- com.android.support:appcompat-v7:+ -> 19.1.0
|    \--- com.android.support:support-v4:19.1.0
\--- novom.anyware.anywaresdk:anywaresdk:0.1.0

archives - Configuration for archive artifacts.
No dependencies

compile - Classpath for compiling the main sources.
+--- com.android.support:appcompat-v7:+ -> 19.1.0
|    \--- com.android.support:support-v4:19.1.0
\--- novom.anyware.anywaresdk:anywaresdk:0.1.0

debugApk - Classpath packaged with the compiled debug classes.
No dependencies

debugCompile - Classpath for compiling the debug sources.
No dependencies

default - Configuration for default artifacts.
No dependencies

defaultFlavorApk - Classpath packaged with the compiled defaultFlavor classes.
No dependencies

defaultFlavorCompile - Classpath for compiling the defaultFlavor sources.
No dependencies

instrumentTestApk - Classpath packaged with the compiled instrumentTest classes.

No dependencies

instrumentTestCompile - Classpath for compiling the instrumentTest sources.
No dependencies

instrumentTestDefaultFlavorApk - Classpath packaged with the compiled instrument
TestDefaultFlavor classes.
No dependencies

instrumentTestDefaultFlavorCompile - Classpath for compiling the instrumentTestD
efaultFlavor sources.
No dependencies

releaseApk - Classpath packaged with the compiled release classes.
No dependencies

releaseCompile - Classpath for compiling the release sources.
No dependencies

BUILD SUCCESSFUL

Total time: 7.388 secs

来源:https://stackoverflow.com/questions/22993976/how-to-reference-dependencies-packages-into-an-android-library-like-aar-file

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