天天看點

Java引入依賴aar,添加gradle依賴庫aar包

Java引入依賴aar,添加gradle依賴庫aar包

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

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'

}

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?

解決方案

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:[email protected]'