GorillaApe
GorillaApe

Reputation: 3641

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)

Upvotes: 0

Views: 2679

Answers (2)

amsurana
amsurana

Reputation: 234

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.

Upvotes: 1

Chogos
Chogos

Reputation: 13

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')

}

Upvotes: 0

Related Questions