简体   繁体   English

将Maven项目添加到Android Studio应用程序作为依赖项

[英]Adding a Maven Project to an Android Studio App as a Dependency

I am currently developing an Android App using Android Studio 1.2 . 我目前正在使用Android Studio 1.2开发Android应用程序。
I want to use an external Java Project as a Dependency in my Android App. 我想在我的Android应用程序中使用外部Java项目作为依赖项。 This Java Project is a Maven Project. 这个Java项目是一个Maven项目。
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? 如何将此项目作为依赖项添加到我的Android应用程序中,因此我可以使用我的Android应用程序参考Java / Maven项目的类?

The Android App is built using Grandle. Android应用程序是使用Grandle构建的。

I found the answer. 我找到了答案。 You need to have Maven installed. 你需要安装Maven。 Then you build the external project with maven. 然后用maven构建外部项目。 (you can use eg eclipse) (你可以使用例如eclipse)

After that, the whole project can be found in your 'local maven repository'. 之后,整个项目可以在“本地maven存储库”中找到。 The location is /{USER}/.m2/repository on a Windows machine. 位置是Windows机器上的/{USER}/.m2/repository

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: 现在将maevnLocal()添加到项目的grandle文件中:

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

And then add the following to your app's grandle file under dependencies: 然后将以下内容添加到应用程序的依赖项下的grandle文件中:

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

Then you need to rebuild / sync the project with the changes of the grandle file. 然后,您需要使用grandle文件的更改重建/同步项目。 After that you are good to go. 在那之后你很高兴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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