gpt4 book ai didi

内部使用库(Artifactory)中的Android第三方依赖

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:17:54 24 4
gpt4 key购买 nike

我正在开发一个供我们公司内部使用的 Android 库,该库具有第三方依赖项并存储在我们自己的 Artifactory 存储库中。

问题是,自从我们升级到 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
  • 禁用默认混淆器

谢谢

最佳答案

升级到 gradle 3+ 后,如您所知,您可以在 gradle 中将编译切换到 implementation/api。但是,您已经为 pom.xml 依赖项创建保留了“编译”行。你应该换行;

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

与;

      pom.withXml {
def dependencies = asNode().appendNode('dependencies')
configurations.implementation.allDependencies.each {
def dependency = dependencies.appendNode('dependency')
dependency.appendNode('groupId', it.group)
dependency.appendNode('artifactId', it.name)
dependency.appendNode('version', it.version)
}
}

关于内部使用库(Artifactory)中的Android第三方依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50248325/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com