0

I have imported a jar file containing a Java library into an Android Studio project by placing it in the app/libs folder. When attempting to import classes from the jar, Android Studio is able to autocomplete the package names, but does not show any specific classes. Attempting to build the project results in 'package does not exist' errors.

I am able to import other third party libraries stored in jars, so the issue seems to be with the specific jar file.

Is there some sort of special setup jar files require before being imported into Android Studio projects? My jar's manifest file is below:

Manifest-Version: 1.0
Created-By: 1.8.0_72 (Oracle Corporation)

Some additional information:

The library I am compiling (for testing purposes) has one file (named Adder.java), shown below:

public class Adder {
  public int add(int x, int y) {
    return x + y;
  }
}

I am creating the jar as follows:

javac -source 1.7 -target 1.7 Adder.java
jar cf Adder.jar Adder.class
M.S.
  • 1,091
  • 1
  • 11
  • 27
  • Which jar file are you importing? Does the third-party say it is supposed to work on Android? – Morrison Chang Jun 12 '17 at 03:13
  • @MorrisonChang I am creating the jar file myself. I added additional details on its contents above. – M.S. Jun 12 '17 at 03:33
  • 1
    Does your library have a package definition? Perhaps this? https://stackoverflow.com/questions/2320092/how-to-use-jar-files-without-package-information – Morrison Chang Jun 12 '17 at 03:35
  • @MorrisonChang Yes, it ended up being a package structure problem. Thank you. – M.S. Jun 12 '17 at 05:58

1 Answers1

0

File->Project Structure..->app->Dependencies->+->jar Dependency->chose your jar file

Melrose
  • 81
  • 4
  • 2
    This was already done. I believe the issue is with the structure of the jar file, since I am able to successfully import other jar files when I follow these steps. – M.S. Jun 12 '17 at 02:07