0

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)

GorillaApe
  • 3,611
  • 10
  • 63
  • 106

2 Answers2

1

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.

amsurana
  • 234
  • 3
  • 11
0

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

}
Community
  • 1
  • 1
Chogos
  • 13
  • 1
  • 4
  • project doesnt produce a jar . I cant find a way. The only thing i get is apk for whole project not the module I need. Solutions dont work for me. – GorillaApe Dec 12 '13 at 19:54
  • @Parhs Unfortunately you can't reuse an APK file in your project. Your best shot is to create a [library project.](https://developer.android.com/tools/projects/index.html#LibraryProjects) – Chogos Dec 12 '13 at 21:50
  • this seems what I need. I should select android library ? However not sure if it is compatible with older android version – GorillaApe Dec 12 '13 at 21:53
  • Just make sure that your android library requires the same or lower API level then your new project. – Chogos Dec 12 '13 at 21:57