我创建了使用android-async依赖关系的android库。这个显示所有内容的库项目都很好。但是,当我将该库发布到本地关系中,然后尝试在其他项目中使用它时,然后在该异步库正在使用show error的类中使用它:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/loopj/android/http/SyncHttpClient;
at com.myproject.installer.InstallerService.onHandleIntent(InstallerService.java:46)
这是库的gradle文件:
buildscript {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
}
}
repositories {
jcenter()
mavenLocal()
mavenCentral()
maven {
url "http://nexus.local:8081/nexus/content/groups/public"
}
maven {
url 'https://maven.google.com'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 17
targetSdkVersion 17
versionCode 5
versionName "0.1.4.1"
}
lintOptions {
abortOnError false
}
}
dependencies {
compile 'com.loopj.android:android-async-http:1.4.9'
}
apply plugin: 'maven-publish'
publishing {
publications {
myPublication(MavenPublication) {
artifacts {
groupId 'com.myproject.android'
artifactId 'installer-lib'
version project.android.defaultConfig.versionName
artifact 'build/outputs/aar/app-release.aar'
}
//The publication doesn't know about our dependencies, so we have to manually add them to the pom
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
//Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
configurations.compile.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
repositories {
maven {
url 'http://nexus.local:8081/nexus/content/repositories/thirdparty'
credentials {
username = 'admin'
password = getNexusPassword()
}
}
}
}
def getNexusPassword() {
Properties props = new Properties();
props.load(project.file('local.properties').newDataInputStream());
return props.getProperty('nexuspassword')
}
因此要构建和发布此库项目,我使用
之类的命令gradle clean build and gradle publish
添加其他信息: 我检查过该库是否显示出它包含依赖项。这是pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject.android</groupId>
<artifactId>installer-lib</artifactId>
<version>0.1.4</version>
<packaging>aar</packaging>
<dependencies>
<dependency>
<groupId>com.loopj.android</groupId>
<artifactId>android-async-http</artifactId>
<version>1.4.9</version>
</dependency>
</dependencies>
</project>
有人知道为什么我收到有关依赖项的NoClassDefFoundError错误消息吗?
答案 0 :(得分:0)
我有一个与您类似的问题,described here。
但是,就我而言,我可以在应用程序中使用库的依赖项。我认为与您的不同之处在于,我的pom文件包含每个依赖项的<scope>compile</scope>
字段。
我所要做的就是使用具有以下配置的 Maven 插件:
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
repository(url: "$url") {
authentication(userName: "$user", password: "$password")
}
pom.groupId = "com.test.common"
pom.artifactId = "CommonLib"
pom.version = VERSION_NAME + "." + VERSION_CODE
}
}
}
我希望这会对您有所帮助。