简体   繁体   中英

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 ? 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.
  2. In build.gradle of your library module, add code to upload the artifact to local Maven repo.

`

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.
  2. Use this aar file in any other project as a dependency.

Hope this helps.

Here are two other questions on the same matter.

How do I add a library project to Android Studio?

How to create a library project in Android Studio and an application project that uses the library project

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:

dependencies {

    compile files('libs/MyJAR.jar')

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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