将gradle依赖项添加到库aar包中 [英] Adding gradle dependency to library aar package

查看:797
本文介绍了将gradle依赖项添加到库aar包中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为供应商开发一个库项目,它需要Android Volley作为依赖项.我已使用此在Android Studio中创建aar文件来创建.aar文件并将其包含在测试项目中,我正在使用.库链接良好,项目编译中没有错误.但是在运行时,测试应用程序崩溃,提示它找不到Volley

I am making a library project for a vendor and it needs Android Volley as a dependency. I have used this Create aar file in Android Studio to create the .aar file and to include this in a test project I am using this Adding local .aar files to Gradle build using "flatDirs" is not working. The library is linked fine and there are no errors in the project compilation. But at runtime the test application crashes saying it cannot find Volley

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/android/volley/toolbox/Volley;
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.android.volley.toolbox.Volley" on path: DexPathList[[zip file "/data/app/in.gridsync.acttest-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

我在图书馆项目中使用的Gradle文件是这样的

My Gradle file for the library project is like this

    apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.mcxiaoke.volley:library:1.0.19'
}

在测试项目中,最重要的是

and in the test project the gradle is this

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "in.gridsync.acttest"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile project(':openapp-library')
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.0'
}

我假设,当创建.aar包时,它将使用并包括其对Volley库的依赖关系.有人可以请问一下吗?

I assumed, when the .aar package was created, it'd use and include the dependency it has on Volley library. Can someone please throw some light on this?

推荐答案

据我所知,您必须为.aar库添加"@aar".另外,不需要jar文件,它会自行下载. 试试这个:

Far as I know, you must add "@aar" for the .aar libraries. Also the jar file isn't required, it downloads that by itself. Try this:

compile 'com.mcxiaoke.volley:library:1.0.19@aar'

这篇关于将gradle依赖项添加到库aar包中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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