生成包含所有依赖项的AAR文件

时间:2017-10-05 06:21:55

标签: android facebook google-play-services facebook-android-sdk aar

我在生成具有所有必需依赖项的AAR文件时遇到问题。以下是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'
}

我正在尝试使用File>添加生成的AAR文件;新模块>导入.JAR / .AAR包。但是,它无法包含所有外部依赖项,Facebook和Google Play服务是具体的。错误说:

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

而且,它无法在AndroidManifest.xml中找到com.facebook.FacebookActivity。

请帮我解决这个问题。

更新

尝试使用pom.xml构建,但没有用。

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

2 个答案:

答案 0 :(得分:3)

如果您计划发布lib,最好不要在打包的aar中包含依赖库,而是在应用程序的构建脚本中添加lib build脚本中的相同compile依赖项。这样:

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

这样,当您的图书馆的用户使用像您的图书馆一样的公共图书库时,他们不会遇到合并冲突,gradle会自动解决它们。

答案 1 :(得分:0)

您应该生成pom文件,其中将存储所有依赖项。