Cannot find the class from library project's jar when maven build my project
Asked Answered
I

2

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????

Idoux answered 14/8, 2015 at 13:54 Comment(5)
I doubt anyone can answer your question at this point, because almost everyone using gradle + .aar instead of maven + .apklib now.Salpa
apklib is deprecated. Try to generate aar file instead simpligility.github.io/android-maven-plugin/aar.html and then add dependency to aarTowill
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.Unhook
Check your maven settings file. When you run from console it may be getting a different xml file.Hildick
Do you have access to the source file? You could might as well compile it!Epizootic
H
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>
Harless answered 27/8, 2015 at 8:36 Comment(1)
Compile scope is default in Maven, so adding it will have no effect.Punke
S
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>
Splasher answered 27/7, 2016 at 8:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.