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

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

问题描述:

我目前正在使用 Android Studio 1.2 开发 Android 应用程序.
我想在我的 Android 应用程序中使用外部 Java 项目作为依赖项.这个 Java 项目是一个 Maven 项目.
如何将此项目作为依赖项直接添加到我的 Android 应用程序中,以便我可以在我的 Android 应用程序中引用 Java/Maven 项目的类?

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?

Android 应用程序是使用 Grandle 构建的.

The Android App is built using Grandle.

我找到了答案.您需要安装 Maven.然后你用 maven 构建外部项目.(你可以使用例如eclipse)

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

之后,可以在您的本地 maven 存储库"中找到整个项目.位置是 /{USER}/.m2/repository 在 Windows 机器上.

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

转换为

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

注意最后的双点.

现在将 maevnLocal() 内容添加到您项目的 Grandle 文件中:

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

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

然后将以下内容添加到您的应用程序的依赖项下的grandle文件中:

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

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

然后您需要使用grandle文件的更改重建/同步项目.之后你就可以开始了.

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