在其他项目中使用.AAR文件的问题 [英] Issue with using .AAR file in other project

查看:142
本文介绍了在其他项目中使用.AAR文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在另一个项目中使用我的android库项目(具有资源).这是我到目前为止所做的:

I have to use my android library project (which has resources), in another project. Here is what I did so far:

  1. 在Android Studio中创建了一个库项目.构建该项目,生成.aar文件,如下所示:..\MyApplication\mylibrary\build\outputs\aar\mylibrary-debug.aar

在Android Studio中创建了一个新的Android项目.然后,我遵循了:

Created a new Android project in Android Studio. Then, I followed this:

文件>>新模块>>导入.JAR或.AAR包

File >> New Module >> Import .JAR or .AAR package

这为我的项目提供了以下结构:

This gives me following structure in my project:

gradle同步或我制作项目时没有任何错误.

There was no any error in gradle sync or while I make the project.

但是,现在,如果我尝试使用我的Library项目的类名,则不会在自动提示中显示.我的图书馆项目中有一个类MyClass.java.在IDE中,如果尝试编写MyC,则看不到MyClass.而是显示没有建议.

But now, if I try to use class name of my Library project, it doesn't get shown in auto suggest. There is one class MyClass.java in my library project. In IDE, if I try to write MyC, I am not able to see MyClass. It shows No suggestions instead.

我缺少一些配置吗?

如果您需要有关文件夹结构或build.gradle文件的其他信息,请告诉我.

Let me know in case you want other information related to folder structure or build.gradle file.

推荐答案

This alternative (credits go to Dwayne) seems to work fine for me. Summarizing:

  • 声明您的平面文件存储库.此存储库声明放在项目模块中的gradle.build文件中,而不是在父目录中的顶级gradle.build文件中:

  • Declare your flat file repository. This repository declaration goes in the gradle.build file in your project module and not the top level gradle.build file in the parent directory:

repositories{
   flatDir {
     dirs 'libs'
   }
}

  • 将您的mylibrary-release.aar或mylibrary-debug.aar从..\MyLibraryProject\mylibrary\build\outputs\aar\复制到应用程序模块..\MyApplicationProject\app\libs中的libs文件夹.

  • Copy your mylibrary-release.aar or mylibrary-debug.aar from ..\MyLibraryProject\mylibrary\build\outputs\aar\ to the libs folder in your application module ..\MyApplicationProject\app\libs.

    声明您对库的依赖.

    dependencies {
       compile 'com.example.library:mylibrary:release@aar'
    }
    

  • 请注意,平面文件"存储库将忽略依赖项声明的命名空间部分(com.example.library),而在依赖项声明中使用不正确的命名空间不会产生任何影响,您应该确保命名空间正确,以防万一您以后可以移至图书馆资料库.

    Note the namespace section (com.example.library) of the dependency declaration is ignored by the ‘flat file’ repository, while having an incorrect namespace in the dependency declaration doesn’t effect anything you should ensure the namespace is correct incase you move to a library repository at a later date.

    另一种替代方法可能是创建本地Maven存储库,如此处,但我没有尝试过此选项.

    Another alternative may be creating a local Maven repository as explained here, but I haven't tried this option.

    这篇关于在其他项目中使用.AAR文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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