Как включить зависимость .aar в файл .aar библиотеки Android

Я пишу какую-то библиотеку, в которой есть часть пользовательского интерфейса. Кроме того, эта библиотека использует другие библиотеки. Я хочу предоставить выпуск .aar для использования этой части пользовательского интерфейса в любом приложении.

Моя библиотека имеет следующие зависимости:

    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'

Когда я построил .aar, все в порядке, но когда я включаю этот .aar в другое приложение, у меня возникают следующие проблемы:

1). ./gradlew clean build

/home/user/projects/MainApp/app/build/intermediates/exploded-aar/com.my.sdk/SDK/0.0.1/res/values/values.xml:78:21-29 : Подходящий ресурс не найден данное имя: attr 'fontPath'.

/home/user/projects/MainApp/app/build/intermediates/exploded-aar/com.my.sdk/SDK/0.0.1/res/values/values.xml:78:21-29 : Подходящий ресурс не найден данное имя: attr 'fontPath'.

/home/user/projects/MainApp/app/build/intermediates/exploded-aar/com.my.sdk/SDK/0.0.1/res/values/values.xml:78:21-29 : Подходящий ресурс не найден данное имя: attr 'fontPath'.

/home/user/projects/MainApp/app/build/intermediates/exploded-aar/com.my.sdk/SDK/0.0.1/res/values/values.xml:78:21-29 : Подходящий ресурс не найден данное имя: attr 'fontPath'.

/home/user/projects/MainApp/app/build/intermediates/exploded-aar/com.my.sdk/SDK/0.0.1/res/values/values.xml:78:21-29 : Подходящий ресурс не найден данное имя: attr 'fontPath'.

/home/user/projects/MainApp/app/build/intermediates/exploded-aar/com.my.sdk/SDK/0.0.1/res/values/values.xml:78:21-29 : Подходящий ресурс не найден данное имя: attr 'fontPath'.

:app:processDebugResources ОШИБКА

Решение очень простое - добавьте в MainApp/app/build.gradle следующую строку:

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

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.

То же самое с другими зависимостями.

В результате мне нужно всего copy-paste всех моих зависимостей от моего проекта library до проекта MainApp.

Можно ли сделать так, чтобы library aar содержал все необходимые зависимости?

build.gradle библиотеки:

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

MainApp/app/build.gradle:

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'
    //************************************************
}

ОБНОВИТЬ

Сгенерированный файл POM:

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

person Aleksandr    schedule 27.12.2015    source источник
comment
Изучите созданный вашей библиотекой файл POM и убедитесь, что в нем перечислены все зависимости.   -  person CommonsWare    schedule 27.12.2015
comment
@CommonsWare, он не содержит никаких зависимостей, как я могу это решить? (Я добавил файл pom к вопросу)   -  person Aleksandr    schedule 27.12.2015
comment
Я лично не пользуюсь плагином maven-publish, поэтому не знаю, где что-то идет не так. Но если вы можете исправить свой POM, это должно решить вашу общую проблему.   -  person CommonsWare    schedule 27.12.2015
comment
@Александр Вы смогли решить эту проблему? Я столкнулся с очень похожей проблемой на моем конце. Вы можете помочь?   -  person Ganesh K    schedule 26.03.2020


Ответы (1)


Если у кого-то возникла такая же проблема, вы можете получить правильный ответ здесь
Результат build.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/"
        }
    }
}
person Aleksandr    schedule 30.12.2015