簡體   English   中英

將gradle依賴項添加到庫aar包中

[英]Adding gradle dependency to library aar package

我正在為供應商制作一個圖書館項目,它需要Android Volley作為依賴項。 在Android Studio中使用了這個創建aar文件來創建.aar文件,並將其包含在我正在使用的測試項目中。 使用“flatDirs”將本地.aar文件添加到Gradle構建不起作用 庫鏈接正常,項目編譯中沒有錯誤。 但是在運行時,測試應用程序崩潰說它無法找到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

庫項目的My Gradle文件是這樣的

    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'
}

在測試項目中,gradle就是這個

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庫的依賴。 有人可以對此有所了解嗎?

據我所知,你必須為.aar庫添加“@aar”。 此外,jar文件不是必需的,它會自行下載。 嘗試這個:

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

另一種解決方案是將依賴庫作為靜態jar文件放在項目的“libs”文件夾中,而不是使用gradle依賴項。 生成aar文件時,libs文件夾下的jar文件將包含在aar中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM