我已经构建了一个安卓.aar库,我正在尝试将它与其中的一个项目集成起来。当应用程序试图打开.aar库的初始屏幕时,我可以使用修改来调用API。我得到了下面的例外
java.lang.NoClassDefFoundError:失败的解决方案:Lokhttp3 3/OkHttpClient$Builder;
在我的.aar项目中,我没有混淆或者启用职业守卫。
下面是我的.aar级依赖项
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:converter-gson:2.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'发布于 2020-03-29 19:07:01
好吧,这是一个常见的问题。在其他项目中有几种使用android库(Aar)的方法。例如:
implementation project(':mylibrary')将此aar作为模块导入到您的示例项目中。注意:
我推荐什么?
我建议开发人员使用MavenLocal(),它在将aar发布到诸如Jitpack之类的公共存储库或您想要的任何东西之前,都会复制一个真实的场景。
,我该怎么做?
apply plugin: 'maven-publish'
project.afterEvaluate {
publishing {
publications {
library(MavenPublication) {
setGroupId 'YOUR_GROUP_ID'
//You can either define these here or get them from project conf elsewhere
setArtifactId 'YOUR_ARTIFACT_ID'
version android.defaultConfig.versionName
artifact bundleReleaseAar //aar artifact you want to publish
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.implementation.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
}运行assemble和publishToMavenLocal分级任务。你会看到这样的东西:

allprojects {
repositories {
mavenLocal()
...
}
}implementation '${YOUR_GROUP_ID}:${YOUR_ARTIFACT_ID}:${YOUR_VERSION}'
发布于 2019-07-11 16:23:02
让我们假设您已经构建了您的.aar,并将其发布到了一个maven存储库中(工件,nexus,您有什么)--例如,"implementation 'com.mycompany:library:1.0@aar'“。任何子依赖项都需要包含在服务器交付的pom.xml中,以便在您的应用程序中可用。
由于您使用了"implementation“关键字,这些依赖关系被认为是.aar的私有属性,并且不会在pom.xml中列出。因此,它们不会在您的aar中可用,也不会被gradle自动导入到项目中。
如果您将api关键字改为"api“而不是实现,则这些依赖项将成为公共的,并且应该在生成的pom.xml中列出,因此应该自动导入到项目中。
这实际上也适用于aar的内部模块,而不是通过外部系统引用(例如,实现项目(‘:mylibrary’) )。如果您需要我的库的依赖项来运行项目,那么它们需要是api。
作为参考,您可能需要查看一下Android依赖项配置文档。
但是,如果您是通过文件语句(例如,实现文件(‘libs/my.aar’)手动包含arr,那么就不能获得自动依赖管理,您还必须手动地将您的arr所需的库添加到主项目中,在build.gradle文件之间进行复制和粘贴。
发布于 2022-06-24 17:01:02
您可以尝试使用fat-aar来解决这个https://github.com/kezong/fat-aar-android。
https://stackoverflow.com/questions/56989569
复制相似问题