Android库发布后无法解决依赖关系 [英] Android library not resolve dependencies after publish

查看:127
本文介绍了Android库发布后无法解决依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了使用android-async依赖关系的android库.这个显示所有内容的图书馆项目都很好.但是,当我将此库发布到本地关系中,然后尝试在其他项目中使用它时,然后在该异步库正在使用show error这样的类中使用它:

I have created android library which use android-async dependency. This library project showing everything is fine. But when i publish this library into local nexus and then try to use it in some other project then in a class where this async library is using show error like this:

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/loopj/android/http/SyncHttpClient;
                                                                    at com.myproject.installer.InstallerService.onHandleIntent(InstallerService.java:46)

这是库的gradle文件:

Here is a gradle file of library:

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

因此要构建和发布此库项目,我使用

so for building and publish of this library project i use command like

gradle clean build and gradle publish

添加其他信息: 我已经检查过该库是否显示出它包含依赖项.这是pom.xml:

adding additional info: I have check that on nexus this library is showing that it included a dependency. Here is a 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错误消息吗?

Does someone have idea why i am getting error message that NoClassDefFoundError for the dependency ?

推荐答案

我遇到了与您类似的问题,

I have a problem similar as yours, described here.

但是,就我而言,我可以在应用程序中使用库的依赖项.我认为与您的不同之处在于,我的pom文件包含每个依赖项的<scope>compile</scope>字段.

But, in my case, I'm able to use the dependencies of my library in my app. The difference with you, I think, is that my pom file contains a <scope>compile</scope> field for each dependencies.

我所要做的就是使用具有以下配置的 Maven 插件:

All I have done is using the Maven plugin with the following configuration :

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

我希望这会对您有所帮助.

I hope this will help you.

这篇关于Android库发布后无法解决依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆