Generate AAR file with all dependencies

2020-05-06 12:17发布

问题:

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>

回答1:

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.



回答2:

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