简体   繁体   English

Android Studio:使用其他项目中的JARS

[英]Android studio: Use JARS from other Project

My app uses several JARS, AAR's and JNI Libs from another (big) Android Studio Project, that has like 20 modules, some of them JAR's, and some of them AAR's. 我的应用程序使用了另一个(大型)Android Studio项目中的多个JARS,AAR和JNI库,该库具有20个模块,其中一些包含JAR,而另一些包含AAR。

At the moment I'm manually copying all stuff into the App project "libs/" folder, and also importing the AAR's as new modules. 目前,我正在将所有内容手动复制到App项目的“ libs /”文件夹中,并且还将AAR导入为新模块。

Is there an easier way to do it? 有更简单的方法吗? Both projects are local on my development machine, but are separate Android Studio projects. 这两个项目在我的开发机器上都是本地的,但是是单独的 Android Studio项目。 I'd like to keep them this way, as the big library project is an active GitHub project that I frequently update. 我想这样保留它们,因为大型图书馆项目是一个活跃的GitHub项目,我经常对其进行更新。

Ideally I'd like to reference the JARS and AAR's from the other project without the need to copy them. 理想情况下,我想引用其他项目中的JARS和AAR,而无需复制它们。

Add the module into your project as project library. 将模块作为项目库添加​​到您的项目中。 In the build.gradle file of your application add following dependencies with the library location. 在应用程序的build.gradle文件中,添加以下依赖项以及库位置。 For example you want to add library lib1 from your library project mylibproject with the path libproject\\lib1 , 例如,你想添加库lib1从资料库中的项目mylibproject与路径libproject\\lib1

dependencies {
     ...
     compile project(':mylibproject:lib1')
 }

Do it for the selective libraries you want to include. 对要包括的选择性库执行此操作。 It will work 会工作的

You can try creating symbolic links between the jar files and your project. 您可以尝试在jar文件和您的项目之间创建符号链接。

On Linux or Mac it's: 在Linux或Mac上,它是:

ln -s source dest ln -s源目标

try 尝试

project
 | build.gradle
 | settings.gradle
 + app/
    | build.gradle
 + mylib1/
    | build.gradle
 + mylib2/
    | build.gradle

in project/setting.gradle add: project / setting.gradle中添加:

default: 默认:

include ':app'

modified: 改性:

include ':app', ':mylib1', ':mylib2'

and in project/app/build.gradle add: 并在project / app / build.gradle中添加:

compile project(':mylib1')
compile project(':mylib2')

More info: Creating-a-Library-Project 更多信息: 创建一个图书馆项目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM