5

I am currently developing an Android App using Android Studio 1.2 .
I want to use an external Java Project as a Dependency in my Android App. This Java Project is a Maven Project.
How can I add this project right into my Android App as a dependency, so I can refer to Classes of the Java/Maven Project withtin my Android App?

The Android App is built using Grandle.

Daniel Hitzel
  • 1,342
  • 2
  • 12
  • 27

1 Answers1

0

I found the answer. You need to have Maven installed. Then you build the external project with maven. (you can use e.g. eclipse)

After that, the whole project can be found in your 'local maven repository'. The location is /{USER}/.m2/repository on a Windows machine.

Follow the structure to the project, you've just built.

Convert this path to a name space path:

/{USER}/.m2/repositoryorg/tuda/cdc/pp/classes/1.0

is converted to

org.tuda.cdc.pp:classes-plain:1.0

Pay attention to the double points at the end.

Now add the maevnLocal() thing to you project's grandle file:

allprojects {
    repositories {
        jcenter()
        mavenLocal()
    } 
}

And then add the following to your app's grandle file under dependencies:

compile 'org.tuda.cdc.pp:classes-plain:1.0'

Then you need to rebuild / sync the project with the changes of the grandle file. After that you are good to go.

Daniel Hitzel
  • 1,342
  • 2
  • 12
  • 27
  • Your solution forces the build of the Maven project outside of Android Studio, which can be time consuming if you are constantly modifying code both from the Android and the Maven project. – Jaime Hablutzel Nov 12 '15 at 23:08
  • Yeah, that may be true. I have a scenario where my maven code is build once and very rarely updated. Feel free to provide a more sophisticated solution. – Daniel Hitzel Nov 15 '15 at 10:07
  • 1
    Dude!! It's not grandle. It's gradle. – Deepak J Aug 27 '19 at 10:36