Adding a Maven Project to an Android Studio App as a Dependency
Asked Answered
R

1

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.

Recommendatory answered 28/5, 2015 at 14:5 Comment(0)
R
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.

Recommendatory answered 18/7, 2015 at 13:39 Comment(3)
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.Plebeian
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.Recommendatory
Dude!! It's not grandle. It's gradle.Prettypretty

© 2022 - 2024 — McMap. All rights reserved.