生成具有所有依赖项的AAR文件 [英] Generate AAR file with all dependencies

查看:248
本文介绍了生成具有所有依赖项的AAR文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在生成具有所需所有依赖项的AAR文件时遇到问题.以下是build.gradle的配置:

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

我正在尝试使用文件">新建模块">导入.JAR/.AAR包"来添加生成的AAR文件.但是,它不能包含所有外部依赖项,即Facebook和Google Play服务.错误提示:

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').

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

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

请帮助我解决此问题.

更新

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

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>

推荐答案

如果您打算发布该库,最好不要在打包的aar中包含依赖库,而应添加与找到的相同的compile依赖项在lib构建脚本中,位于应用程序的构建脚本中,例如:

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

那样,当您的图书馆用户使用公共图书馆时,他们不会像使用公共图书馆那样面临合并冲突,gradle将自动解决它们.

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.

这篇关于生成具有所有依赖项的AAR文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆