我正在为供应商制作一个库项目,它需要 Android Volley 作为依赖项。我用过这个在Android Studio中创建aar文件 https://stackoverflow.com/questions/24309950/create-aar-file-in-android-studio创建 .aar 文件并将其包含在我正在使用的测试项目中使用“flatDirs”将本地 .aar 文件添加到 Gradle 构建不起作用 https://stackoverflow.com/questions/24506648/adding-local-aar-files-to-gradle-build-using-flatdirs-is-not-working。该库链接良好,项目编译没有错误。但在运行时测试应用程序崩溃并表示找不到 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 文件是这样的
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 库的依赖项。有人可以解释一下吗?