简体   繁体   English

其他项目中的Android Studio重用模块库

[英]Android Studio reuse module library at other project

I have a module with some POJO classes that is marked at gradle as apply plugin: 'java' .Is there a way to reuse it at another project ? 我有一个带有一些POJO类的模块,该模块在gradle处标记为apply plugin:'java'。是否有办法在另一个项目中重用它? Everything i tried failed . 我尝试的一切都失败了。 (I dont want to copy pasta it) (我不想复制面食)

I was facing the same issue recently. 我最近面临着同样的问题。

This is how I resolved the code redundancy problem: 这是我解决代码冗余问题的方法:

  1. Create a new Android Studio project 'libs' and add all my APIs in a 'library' module. 创建一个新的Android Studio项目“库”,并将我所有的API添加到“库”模块中。
  2. In build.gradle of your library module, add code to upload the artifact to local Maven repo. 在库模块的build.gradle中,添加代码以将工件上传到本地Maven存储库。

` `

apply plugin: 'maven'
group = 'com.<example>'
version = '1.0'

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "file:///Users/<myuser>/.m2/repository")
        }
    }
}

` `

  1. The archive is uploaded in your maven repo as aar file. 存档以aar文件的形式上传到您的Maven仓库中。
  2. Use this aar file in any other project as a dependency. 在任何其他项目中将此aar文件用作依赖项。

Hope this helps. 希望这可以帮助。

Here are two other questions on the same matter. 这是关于同一问题的另外两个问题。

How do I add a library project to Android Studio? 如何将库项目添加到Android Studio?

How to create a library project in Android Studio and an application project that uses the library project 如何在Android Studio中创建库项目以及使用该库项目的应用程序项目

Personally I didn't use any of the two provided methods. 我个人没有使用提供的两种方法中的任何一种。 I built my project as a JAR, added it to the 'libs' folder, right clicked on it and clicked 'Add as library' and then finally added the dependency in the gradle file like so: 我将项目构建为JAR,将其添加到“ libs”文件夹中,右键单击它,然后单击“添加为库”,然后最终将依存关系添加到gradle文件中,如下所示:

dependencies {

    compile files('libs/MyJAR.jar')

}

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

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