12

I have downloaded an 3rd party Android library project, the project contains no java class file but an jar file under libs/ folder:

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

This library project can be maven built to apklib archive. I built it & I have installed this archive into my local maven repository.

Then in my own Android project, I have added the dependency of this apklib project:

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

In my Java code, I have used the class from the CustomService.jar , but when I maven build my project I constantly get the following error:

[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

The above error complains that it cannot find the UserService class from the library apklib archive. Then, I checked the content of the library jar file by command:

jar tf CustomService.jar

I see that the class is in CustomService.jar of the library project

com/custom/service/user/UserService.class

This class is in the jar, Why I get the error then????

user842225
  • 5,445
  • 15
  • 69
  • 119
  • 2
    I doubt anyone can answer your question at this point, because almost everyone using gradle + .aar instead of maven + .apklib now. – Dmide Aug 17 '15 at 17:42
  • 1
    apklib is deprecated. Try to generate aar file instead http://simpligility.github.io/android-maven-plugin/aar.html and then add dependency to aar – balbusm Aug 18 '15 at 08:36
  • Could you please share your Maven logs about installation of Custom-service.jar to your local repository? It seems to me that dependency properties may be wrong. – saver Aug 20 '15 at 17:00
  • Check your maven settings file. When you run from console it may be getting a different xml file. – Pedro Madrid Aug 20 '15 at 17:07
  • Do you have access to the source file? You could might as well compile it! – Parth Sane Aug 22 '15 at 15:53

2 Answers2

0

Try to add scope :

<dependency>
   <groupId>com.custom.service</groupId>
   <artifactId>custom-service</artifactId>
   <type>apklib</type>
   <version>1.0</version>
   <scope>compile</scope>
 </dependency>
IBJ
  • 31
  • 3
0

Make sure your project is of type apk or any other type compatible withapklib libraries. Default jar type will ignore apklib dependencies.

<project>

    <modelVersion>4.0.0</modelVersion>

    <groupId>...</groupId>
    <artifactId>...</artifactId>
    <packaging>apk</packaging>
...
</project>