-1

I'm having a terrible time adding an external JAR to my gradle project in Android Studio. I asked a similar question here but those answers haven't worked for me.

I created a libs folder and added my JAR in there:

~/android/MyProject/libs $ pwd
/Users/me/android/MyProject/libs
~/android/MyProject/libs $ ls
TestFlightLib.jar

And I added the following in my build.gradle

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

After doing all this I clicked Build -> Rebuild project but that still doesn't let me add import com.testflightapp.lib.TestFlight

I also tried the second solution of right clicking TestFlightLib.jar and adding it as a Module. This lets me add import com.testflightapp.lib.TestFlight successfully but when I Run the project I still get the error: Gradle: error: package com.testflightapp.lib does not exist

What am I doing wrong?

How can I simply add an external JAR to my gradle project?

Community
  • 1
  • 1
birdy
  • 9,286
  • 24
  • 107
  • 171
  • 3
    Don't ask a second, duplicate question just because you don't get a satisfactory answer to your question within 2 hours of asking it. – Scott Barta Jan 10 '14 at 17:48

2 Answers2

2

Try this:

  • right click on your project
  • choose "open module settings"
  • click on module, then "dependencies"
  • check that your file exists in the list
  • if not, press + and add it as a file
Alessandro Roaro
  • 4,665
  • 6
  • 29
  • 48
0

try this:compile files('libs/x.jar', 'libs/y.jar')

user1568967
  • 1,816
  • 2
  • 16
  • 18