2

I have downloaded the library which is a folder containing several files from: https://github.com/EasyPost/easypost-java/archive/master.zip

I have added my own folder named myLibs and added the unzipped project folder to it (folder named easypost-java-master).

My settings.gradle looks as follows:

include ':app'
include ':myLibs:easypost-java-master' 

My build.gradle looks as follows:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile files('libs/gson-2.2.4.jar', 'libs/gson-2.2.4-javadoc.jar', 'libs/gson-2.2.4-javadoc.jar')

    compile fileTree(dir: 'myLibs', include: ['easypost-java-master'])
}

I am getting no errors and able to sync. But when I try to import for example import com.easypost.EasyPost;at my MainActivity, I get the error

Cannot resolve easypost

Am I missing a step?

KFunk
  • 2,956
  • 22
  • 33
JasSy
  • 583
  • 5
  • 17

1 Answers1

1

Am I missing a step?

Yes, the BIG one. On EasyPost library GitHub profile, there are installation instructions. Did you notice that:

Installation

mvn package or build the jar from src!

To do it, just follow these steps:

In the latest build of Android Studio 1.2, the creation of JAR library has been made as simple as point and click.

Steps to follow :

  • Goto File -> New -> New Module enter image description here
  • Select "Java Library" at the end of the options list enter image description here
  • Enter the name of the jar lib and name of class in it and hit finish button enter image description here
  • Thats it !

The next step is adding your Jar Library as dependency in your app. Simple as that just

  • Goto File -> Project Structure -> Select 'app' -> Select 'Dependency'
  • Select the '+' at the bottom -> Select 'Module Dependency' enter image description here
  • Select your jar lib module you just created above enter image description here enter image description here
  • Select Ok and thats it!

....Or you could just add the below line to your App gradle file

dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar']) // Default Gradle Task, should be already present
      compile 'com.android.support:appcompat-v7:21.0.3' // Default Gradle Task, should be already present

      compile project(':nameOfYourJarLibraryModule') // This is your jar library module
 }

Google is promoting the Android Archive(AAR), even though JAR supported is brought back to android studio.To find out the difference between AAR and JAR refer this link

From: Create an Android Jar library for distribution

Hope it help

Community
  • 1
  • 1
piotrek1543
  • 19,130
  • 7
  • 81
  • 94
  • Thanks for reply. I don't get it. I have created the dependency and added the jar file as you shown. Where does the project easypost-java-master come into place in this picture? I thought maybe the newly created class should contain the code snipper shown on the Github page but I am not able to import com.easypost.EasyPost still. – JasSy Dec 30 '15 at 00:23
  • well, I haven't done it yest. You must create a .JAR file, then add it to `libs` folder in your project directory. Then you need to add to `build.gradle` file.... Here's a link how to do the next step: http://stackoverflow.com/questions/16608135/android-studio-add-jar-as-library – piotrek1543 Dec 30 '15 at 00:26
  • Only two steps: generate JAR from source and add JAR to Android project – piotrek1543 Dec 30 '15 at 00:27
  • Probably sounding silly but I want to clarify. How do I generate this Jar from source? At the end all I will have is one single jar file? Regarding the link I belive you mean to follow the selected answer? – JasSy Dec 30 '15 at 00:30
  • well I thought that this link would help you :-/ ask an author on Github project profile by new issue ;-0 – piotrek1543 Dec 30 '15 at 08:48