简体   繁体   English

Android:在项目中添加Android库作为maven依赖项

[英]Android: Adding Android library as maven dependency in project

I have created an Android Library. 我创建了一个Android库。 That has all the main code. 这有所有主要代码。 Also I have created a project called App1. 我还创建了一个名为App1的项目。 I have referenced the library through maven in the App1. 我在App1中通过maven引用了库。 Also I have made it reference through the Project->Properties->Android-> Reference to the library. 我也通过项目 - >属性 - > Android->参考库来引用它。

When I build the project through cygwin using " mvn install " I get following error. 当我使用“ mvn install ”通过cygwin构建项目时,我得到以下错误。

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.
3.2:compile (default-compile) on project App1: Compilation failure: Compil
ation failure:
[ERROR] \LIBRARYPROJECT\Branding-Private\App1\src\main\java\comxyz\main\AApplication.java:[3,42] cannot find symbol
[ERROR] symbol  : class AApplication

**This class AAplication is in the Library project. **此类AAplication在Library项目中。 It is not able to reference it. 它无法参考它。 This project was able to reference it without maven before. 这个项目之前没有maven就可以引用它。 After using maven it is not able to reference it. 使用maven后无法引用它。

Can anyone help? 有人可以帮忙吗?

Thanks, Sneha 谢谢,Sneha

你可以试试maven-android-plugin ApkLib

You need install the library project into local repository, because the reference library is not built when using maven. 您需要将库项目安装到本地存储库中,因为在使用maven时不会构建引用库。

1) Install the library into local repository like this: 1)将库安装到本地存储库中,如下所示:

-Dfile means where your .jar is. -Dfile表示.jar所在的位置。

mvn install:install-file \
    -DgroupId=com.admogo \
    -DartifactId=AdsMOGO-SDK \
    -Dpackaging=jar \
    -Dversion=1.0 \
    -Dfile=AdsMOGO-SDK-Android.jar \
    -DgeneratePom=true

2) Add the dependency in your pom.xml file like this: 2)在pom.xml文件中添加依赖项,如下所示:

<dependency>
    <groupId>com.admogo</groupId>
    <artifactId>AdsMOGO-SDK</artifactId>
    <version>1.1</version>
</dependency>

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

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