如何从我的Andr​​oid库的构建目标中排除一个jar文件 [英] How to exclude a jar-file from my Android library build target

查看:169
本文介绍了如何从我的Andr​​oid库的构建目标中排除一个jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Andr​​oid Studio和有依赖于相同的code进行几个应用程序。让我感动的共享code到一个单独的库,以便将其包含在我的应用程序。

I am using Android Studio and have a several apps that rely on the same code. I moved shared code to a separate library in order to include it in my apps.

库项目( MyLib中),我为此目的而创建需要一个jar文件进行编译,所以我把它添加到项目的libs目录。

The library project (MyLib) that I created for this purpose requires a jar-file to compile, so I added it to project's libs directory.

我的的build.gradle MyLib中主要模块如下所示:

My build.gradle of MyLib main module looks like this:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 21
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.example.android"
        minSdkVersion 9
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {

        }
    }
}

dependencies {
    compile files('./libs/external-java-lib.jar')
}

当我生成项目,gradle这个生成的jar文件包含外部Java的lib.jar

When I build the project, gradle generates a jar-file that contains external-java-lib.jar.

我想我的Andr​​oid应用项目提供外部Java的lib.jar,而不是MyLib中。因为在我的应用我可能会使用不同版本的外部Java的lib.jar的

I want my Android application projects to provide "external-java-lib.jar", not the MyLib. Because in my apps I may use different versions of external-java-lib.jar.

如何配置摇篮排除外部Java的lib.jar 从我的库项目的建设?

How do I configure Gradle to exclude external-java-lib.jar from the build of my library project?

我找不到答案,我在网络上的问题,所以我有一种感觉,我想要的东西是一件糟糕的设计。我还能怎么办?

I couldn't find the answer to my question on the net, so I have a feeling that the thing I want is a piece of bad design. What else can I do?

感谢您提前。

推荐答案

我终于解决了我的问题。

I finally solved my problem.

在我的图书馆项目中,我增加了一个空的模块和移动外部Java的lib.jar 文件夹中。

In my library project I added another empty libraries module and moved external-java-lib.jar to its libs folder.

的build.gradle 模块的,我加了依赖性:

In the build.gradle of the main module, I added dependency:

dependencies {
    compile project(':libraries')     
}

我的目录结构现在是:

My directory structure is now:

MyLibrary
├── build.gradle
├── gradle.properties
├── main
│   ├── build.gradle
│   └── src
│       └── main
│           ├── AndroidManifest.xml
│           ├── java ...
│           └── res  ...
├── libraries
│   ├── build.gradle
│   ├── libs
│   │   ├── external-lib-1.jar
│   │   └── external-lib-2.jar
│   └── src
│       └── main
│           ├── AndroidManifest.xml
│           ├── java ...
│           └── res  ...
└── settings.gradle

我建库后,输出AAR-包,它没有外部Java的lib.jar 。所以,这正是我想要的。

After I build the library, the output aar-package had no external-java-lib.jar in it. So, this is exactly what I want.

这篇关于如何从我的Andr​​oid库的构建目标中排除一个jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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