问题描述
这是我的设置:我有一个Android库,该库在导出时会创建aar,并且我有一个使用该库作为模块的android应用(这是导入本地aar文件的唯一方法).
Here is my setup : I have an android library that creates an aar when exported and I have an android app that uses the library as a module (it's the only way to import a local aar file).
要将aar文件作为模块导入到我的android应用程序中,请单击File
-> New Module...
-> Import .JAR or .AAR Package
,然后选择导出的aar文件.之后,我只需要在gradle文件中添加compile project
行即可使用我的库.
To import the aar file as a module in my android app, I click on File
-> New Module...
-> Import .JAR or .AAR Package
and I choose my exported aar file. After that I only need to add a compile project
line in my gradle file to be able to use my library.
我经常更新我的库,因为我目前正在开发它,并且我想经常对其进行测试.问题是我不知道如何更新我的android应用项目中的模块...
I update very often my library because I am currently developing it and I want to test it frequently. The problem is that I don't know how to update the module in my android app project...
我现在正在做的是在我的android库项目中发出gradlew assembleRelease
来创建新的aar文件,然后在我的android app项目中删除Module Settings
(或Project Structure
)窗口中的模块,我删除了项目根目录下的module文件夹,然后再次导入它.每次我要测试我的磁带库时,整个操作大约需要3分钟,我对此感到厌倦.您知道是否有更新从aar文件创建的android模块的更快方法吗?
What I am doing now is that I issue a gradlew assembleRelease
in my android library project to create the new aar file, then in my android app project I delete the module in the Module Settings
(or Project Structure
) window, I delete the module folder at the root of my project and then I import it again. This whole operation takes around 3 minutes each time I want to test my library and I am tired of this. Do you know if there is a faster way of updating an android module created from an aar file?
推荐答案
我认为将aar文件作为模块导入是包括本地aar文件的唯一解决方案,但似乎可以通过模拟aar文件来轻松实现.具有固定目录的存储库.
I thought that importing a aar file as a module was the only solution to include a local aar file, but it seems that it can be done easily by simulating a repository with a flat directory.
在项目gradle文件中的allprojects
.repositories
标记中,添加以下内容:
In your project gradle file in the allprojects
.repositories
tag, add the following :
flatDir {
dirs 'libs'
}
在您的应用模块中,请确保您有一个libs
文件夹,其中包含aar文件.然后在应用模块gradle文件的dependencies
标记中添加compile
行.
In your app module, make sure you have a libs
folder with the aar file in it. Then add the compile
line in the dependencies
tag of your app module gradle file.
dependencies {
compile 'package:name:version@aar'
}
现在,当您更新libs目录中的aar文件时,您的应用将使用库的更新版本.
Now, when you update the aar file in your libs directory, your app will use the updated version of your library.
注意:
- 在
compile 'package:name:version@aar'
中,name
是物理文件名图书馆.例如lib-debug
或lib-release
等 -
version
和package
可以在AndroidManifest.xml
内部找到.aar文件. (如何打开.aar文件?)
- In
compile 'package:name:version@aar'
,name
is physical file nameof the library. For examplelib-debug
orlib-release
etc. version
andpackage
can be found inAndroidManifest.xml
inside.aar file. (How to open .aar file?)
这篇关于从本地AAR创建的更新模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!