Android的依赖AAR [英] Android aar dependencies

查看:766
本文介绍了Android的依赖AAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的摇篮构建系统,我有一个库项目,其中包括像改造的依赖,okhttp等。

我编译我的项目,并创建了一个AAR文件。我创建了一个虚拟的项目,并添加我的图书馆AAR作为一个依赖。

现在,如果我没有在我的虚拟应用程序的的build.gradle文件中添加和改造作为okhttp依赖,我与类的应用程序崩溃未发​​现异常。

我的问题是:由于库AAR文件已经包括改造和okhttp的依赖性那么为什么我需要在虚拟应用程序的的build.gradle文件中明确添加它们吗?有一种解决方法。

下面是我的媒体库的build.gradle

 应用插件:'com.android.library
    buildscript {
        库{
            mavenCentral()
            jcenter()
        }
    依赖{
        类路径'com.android.tools.build:gradle:1.0.+
    }
}
allprojects {
    库{
        jcenter()
    }
}
安卓{
    compileSdkVersion 22
    buildToolsVersion21.1.2    defaultConfig {
        14的minSdkVersion
        targetSdkVersion 22
        版本code 1
        的versionName1.0
    }
    buildTypes {
        发布 {
            minifyEnabled假
            proguardFiles getDefaultProguardFile('proguard的-android.txt'),'proguard-rules.pro
        }
    }}
    依赖{
    编译文件树(导演:'库',包括:['的* .jar'])
    编译com.android.support:appcompat-v7:22.+
    编译com.android.support:recyclerview-v7:21.+
    编译com.android.support:cardview-v7:21.+
    编译com.google.android.gms:游戏服务:87年6月5日
    编译com.squareup.okhttp:okhttp:2.2.0
    编译com.squareup.retrofit:改造:1.9.0
    }


解决方案

我能够通过添加AAR文件到本地仓库来解决这个问题。不知怎的,只是添加的libs文件夹AAR和包括它作为一个依赖不解决问题。

如果您遇到类似的问题,只需要修改你的库项目的build.gradle这些新增

 应用插件:'行家'   版本=1.0
   组=com.example.libbuildscript {
    库{
        mavenCentral()
        mavenLocal()
    }    依赖{
        类路径'com.github.dcendents:Android的Maven的插件:1.0
    }
}
    库{
       mavenLocal()
     }uploadArchives {
    库{
        mavenDeployer {
            库(URL:文件:// $ {} System.env.HOME /.m2/repository/)
        }
    }
}

在Android的工作室本身提供的./gradlew uploadArchives

终端运行任务

然后在你的应用程序模块的build.gradle文件,添加库依赖

 编译('com.example.app:ExampleLibrary:1.0@aar'){
        传递= TRUE;
    }

I am new to Gradle build system, I have a library project which includes dependencies like Retrofit, okhttp etc.

I compiled my project and created an aar file. I created a dummy project and added my library aar as a dependency.

Now if I don't add Retrofit and okhttp as dependency in my dummy app's build.gradle file, my app crashes with class not found exception.

My Question is : Since the library aar file already includes Retrofit and okhttp as dependency then why do I need to add them explicitly in dummy app's build.gradle file too? Is there a workaround.

Here is my library build.gradle

    apply plugin: 'com.android.library'
    buildscript {
        repositories {
            mavenCentral()
            jcenter()
        }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.+'
    }
}
allprojects {
    repositories {
        jcenter()
    }
}
android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }}
    dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.+'
    compile 'com.android.support:recyclerview-v7:21.+'
    compile 'com.android.support:cardview-v7:21.+'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.squareup.okhttp:okhttp:2.2.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    }

解决方案

I was able to resolve this by adding the aar file to a local maven repository. Somehow just adding aar in libs folder and including it as a dependency does not fixes the problem.

If you encounter similar problem just modify your library project build.gradle with these additions

 apply plugin: 'maven'

   version = "1.0"
   group = "com.example.lib"



buildscript {
    repositories {
        mavenCentral()
        mavenLocal()
    }

    dependencies {
        classpath 'com.github.dcendents:android-maven-plugin:1.0'
    }
}
    repositories {
       mavenLocal()
     }

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "file://${System.env.HOME}/.m2/repository/")
        }
    }
}

Run the task in the terminal provided in the Android studio itself as ./gradlew uploadArchives

Then in your app module's build.gradle file, add the library as dependency

compile ('com.example.app:ExampleLibrary:1.0@aar') {
        transitive = true;
    }  

这篇关于Android的依赖AAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆