本文介绍了更新从本地 aar 创建的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的设置:我有一个在导出时创建 aar 的 android 库,我有一个使用该库作为模块的 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 或.AAR 包,然后我选择导出的 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应用程序项目中删除Module中的模块Settings(或Project Structure)窗口,我删除了项目根目录下的模块文件夹,然后再次导入.每次我想测试我的库时,整个操作大约需要 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-debuglib-release
  • versionpackage 可以在 AndroidManifest.xml 里面找到.aar 文件.(如何打开 .aar 文件?)
  • In compile 'package:name:version@aar', name is physical file nameof the library. For example lib-debug or lib-release etc.
  • version and package can be found in AndroidManifest.xml inside.aar file. (How to open .aar file?)

这篇关于更新从本地 aar 创建的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 04:58