0

I am facing problems in generating AAR file with all the dependencies required. Following is the configuration for build.gradle:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.3'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "3.5.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

}

dependencies {
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.facebook.android:facebook-android-sdk:4.14.1'
    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.google.code.gson:gson:2.8.1'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
    compile 'com.google.android.gms:play-services:11.0.4'
}

I am trying to add the generated AAR file using File > New Module > Import .JAR/.AAR package. But, it is unable to include all external dependencies, Facebook and Google Play Services to be specific. The error says:

Error:No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version').

And, it is unable to find com.facebook.FacebookActivity in AndroidManifest.xml.

Please help me in resolving this issue.

Update

Tried building using pom.xml, but of no use.

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.loginradius.androidsdk</groupId>
    <artifactId>loginradius-android-sdk</artifactId>
    <version>3.5.0</version>
    <packaging>aar</packaging>

    <properties>
        <!-- use UTF-8 for everything -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.facebook.android</groupId>
            <artifactId>facebook-android-sdk</artifactId>
            <version>4.27.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>google-play-services</artifactId>
            <version>r22</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.9.0-rc.1</version>
                <configuration>
                    <sdk>
                        <platform>19</platform>
                    </sdk>
                    <deleteConflictingFiles>true</deleteConflictingFiles>
                    <undeployBeforeDeploy>true</undeployBeforeDeploy>
                </configuration>
                <extensions>true</extensions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
Hitesh Pamnani
  • 177
  • 3
  • 14

2 Answers2

2

If you are planning to release the lib, it will be better not to include the dependent libraries in the packaged aar and instead add the same compile dependencies found in lib build script inside the build script of the app as such:

app build.gradle:

dependencies {
    compile ':my-lib'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.facebook.android:facebook-android-sdk:4.14.1'
    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.google.code.gson:gson:2.8.1'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
    compile 'com.google.android.gms:play-services:11.0.4'
}

That way users of your library won't face merging conflicts when they use public libraries like your library does, gradle will automatically resolve them.

ahasbini
  • 6,761
  • 2
  • 29
  • 45
  • I've tried doing that. But, I am looking for a better way to include all dependencies in a single library. – Hitesh Pamnani Oct 05 '17 at 09:07
  • I advise that you shouldn't cause then users of your lib will be facing issues as these: https://stackoverflow.com/q/38658378/2949966 https://stackoverflow.com/q/29628067/2949966 Gradle cannot resolve merging conflicts if a aar contains a certain lib packaged inside while the app as well depends on the lib and contains code calling methods from lib. – ahasbini Oct 05 '17 at 09:16
  • 7
    The original poster was asking "How" to accomplish this...not whether this was a good idea or not. Just answering a post with "...you shouldn't be doing that..." isn't really an answer. I'm here because I'm looking to do the same thing, I'm 100% aware of the problems, and I'm willing to deal with the consequences. – Dan Devine Aug 14 '20 at 19:31
  • 1
    I have yet to see a library that requires you to list all the dependencies in your own app. – Johann Sep 23 '21 at 15:11
1

You should generate pom file, where all dependencies will be stored.

shmakova
  • 6,076
  • 3
  • 28
  • 44