当前位置: 首页 > 知识库问答 >
问题:

如何将.aar依赖项包含到Android库.aar文件中

严昀
2023-03-14

我写了一些库,其中有一部分UI。此外,这个库使用另一个库。我想提供发行版.aar来在任何应用程序中使用这部分UI。

我得库有下一个依赖项:

    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
    compile ('com.android.support:recyclerview-v7:22.2.1'){
        exclude group: 'com.android.support', module: 'support-v4'
    }
    compile 'com.inthecheesefactory.thecheeselibrary:stated-fragment-support-v4:0.10.0'

    //Http communication, websockets, etc.
    compile 'com.squareup.okhttp:okhttp:2.4.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'

    //Fonts
    compile 'uk.co.chrisjenx:calligraphy:2.1.0'

    //Unit tests
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:1.9.5'

    //Other
    compile ('org.apache.commons:commons-lang3:3.4'){
        exclude group: 'org.apache.httpcomponents'
    }

    //Reactive programmnig
    compile 'io.reactivex:rxjava:1.0.13'
    compile 'io.reactivex:rxandroid:0.25.0'

    compile 'com.github.bumptech.glide:glide:3.6.1'

/home/user/projects/mainapp/app/build/intermediates/explodede-aar/com.my.sdk/sdk/0.0.1/res/values/values.xml:78:21-29:找不到与给定名称匹配的资源:attr“font path”。

/home/user/projects/mainapp/app/build/intermediates/explodede-aar/com.my.sdk/sdk/0.0.1/res/values/values.xml:78:21-29:找不到与给定名称匹配的资源:attr“font path”。

/home/user/projects/mainapp/app/build/intermediates/explodede-aar/com.my.sdk/sdk/0.0.1/res/values/values.xml:78:21-29:找不到与给定名称匹配的资源:attr“font path”。

2)。运行mainapp时收到此错误:

java.lang.NoClassDeffounderRor:com.my.sdk.ui.fragment.DialogAppNotInstalledFragment

要解决这个问题,我需要将compile'com.inthecheesefactory.thecheeselibrary:stated-fragment-support-v4:0.10.0'添加mainapp/app/build.gradle中。

其他受抚养人也一样。

结果,我只需要复制-粘贴我的所有依赖项从我的项目到MainApp项目。

是否可以使库AAR包含所有必要的依赖项?

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
    }
}
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
//apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "0.0.1"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }

    dexOptions {
        preDexLibraries = false
        incremental true
        javaMaxHeapSize "4g"
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude '.readme'
    }

    lintOptions {
        abortOnError false
    }

    sourceSets {
        main {
            assets.srcDirs = ['src/main/assets', 'src/main/assets/']
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
    compile ('com.android.support:recyclerview-v7:22.2.1'){
        exclude group: 'com.android.support', module: 'support-v4'
    }
    compile 'com.inthecheesefactory.thecheeselibrary:stated-fragment-support-v4:0.10.0'

    //Http communication, websockets, etc.
    compile 'com.squareup.okhttp:okhttp:2.4.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'

    //Fonts
    compile 'uk.co.chrisjenx:calligraphy:2.1.0'

    //Unit tests
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:1.9.5'

    //Other
    compile ('org.apache.commons:commons-lang3:3.4'){
        exclude group: 'org.apache.httpcomponents'
    }

    //Reactive programmnig
    compile 'io.reactivex:rxjava:1.0.13'
    compile 'io.reactivex:rxandroid:0.25.0'

    compile 'com.github.bumptech.glide:glide:3.6.1'
}

// To publish to maven local execute "gradle clean build publishToMavenLocal"
// To publish to nexus execute "gradle clean build publish"
android.libraryVariants
publishing {
    publications {
        maven(MavenPublication) {
            artifact "${project.buildDir}/outputs/aar/${project.name}-release.aar"
            artifactId = POM_ARTIFACT_ID
            groupId = GROUP
            version = VERSION_NAME

            // Task androidSourcesJar is provided by gradle-mvn-push.gradle
            //artifact androidSourcesJar {
            //    classifier "sources"
            //}
        }
    }

    repositories {
        maven {
            credentials {
                username System.getenv('NEXUS_USER_NAME')
                password System.getenv('NEXUS_PASSWORD')
            }
            url "http://my-nexus-url/"
        }
    }
}
buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
    maven { url 'http://my-nexus-url/' }
    flatDir {
        dirs 'libs'
    }
}


android {
    signingConfigs {
        some_config {
            keyAlias 'some alias'
            keyPassword '741789654uppy'
            storeFile file('../my-keystore.jks')
            storePassword 'some_password'
        }
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    defaultConfig {
        applicationId "com.company.app.android"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 9
        versionName "1.0.0"
    }
    dexOptions {
        preDexLibraries = false
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            signingConfig signingConfigs.some_config
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
    compile files('libs/StartAppInApp-2.3.1.jar')
//    compile files('libs/android-support-v4.jar')
    compile files('libs/applovin-sdk-5.2.0.jar')
    compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
        transitive = true;
    }

    //here is my library!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    compile('com.my.sdk:SDK:0.0.1@aar'){
        transitive = true;
        exclude(group:'android.support', module: 'support-v4')
    }


    //***********************************************
    //Dependecies from library
    //***********************************************
    compile 'uk.co.chrisjenx:calligraphy:2.1.0'
    compile 'com.squareup.okhttp:okhttp:2.4.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'io.reactivex:rxjava:1.0.13'
    compile 'io.reactivex:rxandroid:0.25.0'
    compile 'com.github.bumptech.glide:glide:3.6.1'
    compile ('com.android.support:recyclerview-v7:22.2.1'){
        exclude group: 'com.android.support', module: 'support-v4'
    }
    compile 'org.lucasr.twowayview:twowayview:0.1.4'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile ('org.apache.commons:commons-lang3:3.4'){
        exclude group: 'org.apache.httpcomponents'
    }
    compile 'com.inthecheesefactory.thecheeselibrary:stated-fragment-support-v4:0.10.0'
    //************************************************
}
<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.my.sdk</groupId>
<artifactId>SDK</artifactId>
<version>0.0.1</version>
<packaging>aar</packaging>
</project>

共有1个答案

贺栋
2023-03-14

如果有人有同样的问题,您可以在这里获得正确答案
Resultbuild.gradle是:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
    }
}
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "0.0.1"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }

    dexOptions {
        preDexLibraries = false
        incremental true
        javaMaxHeapSize "4g"
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude '.readme'
    }

    lintOptions {
        abortOnError false
    }

    sourceSets {
        main {
            assets.srcDirs = ['src/main/assets', 'src/main/assets/']
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
    compile ('com.android.support:recyclerview-v7:22.2.1'){
        exclude group: 'com.android.support', module: 'support-v4'
    }
    compile 'com.inthecheesefactory.thecheeselibrary:stated-fragment-support-v4:0.10.0'

    //Http communication, websockets, etc.
    compile 'com.squareup.okhttp:okhttp:2.4.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'

    //Fonts
    compile 'uk.co.chrisjenx:calligraphy:2.1.0'

    //Unit tests
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:1.9.5'

    //Other
    compile ('org.apache.commons:commons-lang3:3.4'){
        exclude group: 'org.apache.httpcomponents'
    }

    //Reactive programmnig
    compile 'io.reactivex:rxjava:1.0.13'
    compile 'io.reactivex:rxandroid:0.25.0'

    compile 'com.github.bumptech.glide:glide:3.6.1'
}


// To publish to maven local execute "gradle clean build publishToMavenLocal"
// To publish to nexus execute "gradle clean build publish"
android.libraryVariants
publishing {

    publications {
        maven(MavenPublication) {
            artifact "${project.buildDir}/outputs/aar/${project.name}-release.aar"
            artifactId = POM_ARTIFACT_ID
            groupId = GROUP
            version = VERSION_NAME

            pom.withXml {
                def depsNode  = asNode().appendNode('dependencies')

                configurations.compile.allDependencies.each {  dep ->
                    if(dep.name != null && dep.group != null && dep.version != null) {
                        def depNode = depsNode.appendNode('dependency')
                        depNode.appendNode('groupId', dep.group)
                        depNode.appendNode('artifactId', dep.name)
                        depNode.appendNode('version', dep.version)
                        //optional add scope
                        //optional add transitive exclusions
                    }
                }
            }
        }
    }

    repositories {
        maven {
            credentials {
                username System.getenv('NEXUS_USER_NAME')
                password System.getenv('NEXUS_PASSWORD')
            }
            url "http://nexus-repository-url/"
        }
    }
}
 类似资料:
  • 我使用的是Android Studio1.4

  • 问题内容: 我看到了类似的问题,但未找到可接受的答案。问题-我有一些小功能我自己的android库。我的库使用其他库-fe Hawk(无sql数据库)。我的图书馆gradle文件: 图书馆工作正常。如果我将它用作另一个项目中的项目-它也可以工作。但是当我生成文件(带有-> )并包含到单独的项目中时-失败。项目仅查看我的图书馆的班级。Hawk com.orhanobut.hawk软件包和off其他软

  • 问题内容: 摘要: 我有一个依赖于JAR文件的AAR文件,当我构建AAR项目时,它不包含JAR代码。 细节: 我有一个Java SDK库项目,其中包含我们用于Java Web项目的代码,此类库是使用内部Nexus服务器(如JAR)创建的,并驻留在内部。 目的是通过一个AAR库提供此JAR库的“ Android配置”版本,多个Android应用程序可以使用该版本,并最大程度地减少了实现它的工作量(和

  • 摘要: 我有一个AAR文件,它依赖于一个JAR文件,当我构建AAR项目时,它不包含JAR代码。 我的AAR项目包含了Java SDK库(JAR)的gradle依赖项,但在构建时,AAR不包含来自它的任何类。 代码: 这是Java SDK项目的gradle文件: 注意2:我尝试在Android项目中添加到我的AAR依赖项,但这没有解决任何问题,真正的问题是在构建AAR项目时,JAR项目代码没有被捆绑

  • 我正在用Tianium框架构建一个Android模块,我必须以AAR格式包含一个外部依赖项。我试图从AAR(即归档文件)中只提取类JAR,并将其包含在模块中,但这种技巧只适用于不依赖于任何资源的库(这就是制作AAR而不是JAR的原因)。 有没有办法在钛模块(使用Ant作为构建工具)的构建过程中包含AAR? 编辑:似乎在Appcelerator会有人做这件事:https://jira.appcele

  • 我正在为一个供应商做一个库项目,它需要Android Volley作为一个依赖项。我已经在Android Studio中使用了这个Create aar文件来创建.aar文件,并将其包含在一个测试项目中,我正在使用这个添加本地.aar文件到使用“flatdirs”的Gradle build中是不起作用的。库链接精细,项目编制无差错。但在运行时,测试应用程序崩溃,说它找不到Volley 我的图书馆项目