我正在为我们公司开发一个Android库,这个库有第三方依赖项,并存储在我们自己的Artifactory仓库中。
问题是,自从我们升级到Gradle 3之后,在使用该库的不同项目中,我们无法看到库的依赖关系。
我是否遗漏了什么?以下是库的build.gradle文件:
例如,当我的库想要从我的应用程序访问volley库而不需要再次导入依赖项时,因此它已经在我的库中导入,我会得到以下信息:
问题是,自从我们升级到Gradle 3之后,在使用该库的不同项目中,我们无法看到库的依赖关系。
我是否遗漏了什么?以下是库的build.gradle文件:
apply plugin: 'com.android.library'
//Skitude Plugins
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
repositories {
maven { url "https://jitpack.io" }
mavenCentral()
}
//Artifactory ID
def libraryGroupId = 'com.company.companylibrary'
def libraryArtifactId = 'library'
def libraryVersion = '0.0.6'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 17
targetSdkVersion 27
versionCode 6
versionName "0.0.6"
vectorDrawables.useSupportLibrary= true
}
buildTypes {
defaultConfig {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//Dependencies ANDROID
api 'com.android.support:appcompat-v7:27.1.1'
api 'com.android.support:support-v13:27.1.1'
api 'com.android.support:support-annotations:27.1.1'
api 'com.android.support:support-vector-drawable:27.1.1'
api 'com.android.support.constraint:constraint-layout:1.1.0'
api 'com.android.support:design:27.1.1'
api 'com.android.support:cardview-v7:27.1.1'
api 'com.android.support:recyclerview-v7:27.1.1'
api 'com.android.support:customtabs:27.1.1'
api 'com.android.volley:volley:1.0.0'
...
}
publishing {
publications {
aar(MavenPublication) {
groupId libraryGroupId
version libraryVersion
artifactId libraryArtifactId
artifact("$buildDir/outputs/aar/${artifactId}-release.aar")
pom.withXml {
def dependencies = asNode().appendNode('dependencies')
configurations.compile.allDependencies.each {
def dependency = dependencies.appendNode('dependency')
dependency.appendNode('groupId', it.moduleGroup)
dependency.appendNode('artifactId', it.moduleName)
dependency.appendNode('version', it.moduleVersion)
}
}
}
}
}
artifactory {
contextUrl = 'http://artifactory.company.com/artifactory/'
publish {
repository {
repoKey = 'library-core-release-local'
username = artifactory_username
password = artifactory_password
}
defaults {
publications('aar')
publishArtifacts = true
properties = ['qa.level': 'basic', 'q.os': 'android', 'dev.team': 'core']
publishPom = true
}
}
}
例如,当我的库想要从我的应用程序访问volley库而不需要再次导入依赖项时,因此它已经在我的库中导入,我会得到以下信息:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.skitude.Valdesqui, PID: 28489
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/android/volley/toolbox/DiskBasedCache;
at com.blabsolutions.skitudelibrary.Helpers.ProfileHelper.setupVolley(ProfileHelper.java:81)
at com.blabsolutions.skitudelibrary.SkitudeApplication.onCreate(SkitudeApplication.java:132)
at com.skitude.Valdesqui.CoorpApplication.onCreate(CoorpApplication.java:32)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1032)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5885)
at android.app.ActivityThread.-wrap3(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1703)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.android.volley.toolbox.DiskBasedCache" on path: DexPathList[[zip file "/data/app/com.skitude.Valdesqui-1/base.apk", zip file "/data/app/com.skitude.Valdesqui-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.skitude.Valdesqui-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.skitude.Valdesqui-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.skitude.Valdesqui-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.skitude.Valdesqui-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.skitude.Valdesqui-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.skitude.Valdesqui-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.skitude.Valdesqui-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.skitude.Valdesqui-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.skitude.Valdesqui-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.skitude.Valdesqui-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.skitude.Valdesqui-1/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.blabsolutions.skitudelibrary.Helpers.ProfileHelper.setupVolley(ProfileHelper.java:81)
at com.blabsolutions.skitudelibrary.SkitudeApplication.onCreate(SkitudeApplication.java:132)
at com.skitude.Valdesqui.CoorpApplication.onCreate(CoorpApplication.java:32)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1032)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5885)
at android.app.ActivityThread.-wrap3(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1703)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Suppressed: java.io.IOException: No original dex files found for dex location (arm64) /data/app/com.skitude.Valdesqui-1/split_lib_slice_6_apk.apk ()
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:373)
at dalvik.system.DexFile.<init>(DexFile.java:113)
at dalvik.system.DexFile.<init>(DexFile.java:78)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:359)
at dalvik.system.DexPathList.makeElements(DexPathList.java:323)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:263)
at dalvik.system.DexPathList.<init>(DexPathList.java:126)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:48)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.PathClassLoaderFactory.createClassLoader(PathClassLoaderFactory.java:43)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:58)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:535)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:568)
at android.app.ActivityThread.getTopLevelResources(ActivityThread.java:2046)
at android.app.LoadedApk.getResources(LoadedApk.java:787)
at android.app.ContextImpl.<init>(ContextImpl.java:2261)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2201)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2192)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5776)
... 8 more
我尝试过的事情:
- 从Gradle 3.1.0升级到Gradle 4.4
- 禁用默认的Proguard
谢谢