12

我已经下载了一个 3rd 方 Android 库项目,该项目不包含 java 类文件,但文件夹下有一个jarlibs/文件:

libs/
    - CustomService.jar
res/
   -…
pom.xml

这个库项目可以构建为apklib存档。我构建了它并已将此存档安装到我的本地 maven 存储库中。

然后在我自己的Android项目中,添加了这个apklib项目的依赖:

<dependency>
   <groupId>com.custom.service</groupId>
   <artifactId>custom-service</artifactId>
   <type>apklib</type>
   <version>1.0</version>
 </dependency>

在我的 Java 代码中,我使用了CustomService.jar中的类,但是当我构建我的项目时,我经常收到以下错误:

[ERROR] package com.custom.service.user does not exist
[ERROR] location: class com.my.app.MyClass
[ERROR] /Users/Johon/MyApp/src/main/java/com/my/app/MyClass.java:[34,17] cannot find symbol
[ERROR] symbol:   variable UserService

上述错误抱怨它无法UserService从库 apklib 存档中找到该类。然后,我通过命令检查了库 jar 文件的内容:

jar tf CustomService.jar

我看到该类在库项目的CustomService.jar中

com/custom/service/user/UserService.class

这个类在罐子里,为什么我得到错误呢????

4

2 回答 2

0

尝试添加范围:

<dependency>
   <groupId>com.custom.service</groupId>
   <artifactId>custom-service</artifactId>
   <type>apklib</type>
   <version>1.0</version>
   <scope>compile</scope>
 </dependency>
于 2015-08-27T08:36:27.740 回答
0

确保您的项目是类型或与库兼容apk的任何其他类型。默认类型将忽略依赖项。apklibjar apklib

<project>

    <modelVersion>4.0.0</modelVersion>

    <groupId>...</groupId>
    <artifactId>...</artifactId>
    <packaging>apk</packaging>
...
</project>
于 2016-07-27T08:50:57.390 回答