Asked  7 Months ago    Answers:  2   Viewed   34 times

I want to add external library to my Android application (I use Android Studio, the instructions provided by lib author for Eclipse didn't work for Android Studio).

I've tried to do it with maven, so in File->Project Structure->Dependencies I've added com.foursquare:foursquare-android-nativeoauth-lib:1.0.0 but Gradle Sync fails:

Error:Failed to find: com.foursquare:foursquare-android-nativeoauth-lib:1.0.0

When I try to build my app (without fixing above error becaus I don't know how) I get:

Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not resolve com.foursquare:foursquare-android-nativeoauth-lib:1.0.0.
 Required by:
   > Could not parse POM
     > Could not find any version that matches com.foursquare:parent:1.0.0.

Any other way to import this lib? I can simply copy-paste source code into my source or create JAR out of it?

BTW: if you run into problems see this question (I had this issue after importing): Manifest merger failed : uses-sdk:minSdkVersion 14



Try this:

File > Project Structure > Dependencies Tab > Add module dependency (scope = compile)

Where the module dependency is the project library Android folder.

Tuesday, June 1, 2021
answered 7 Months ago

Since the GSON library is available in MavenCentral, there's an easy way to add it that avoids having to download an archive file and save it in your project.

Go to Project Structure > Modules > Your module name > Dependencies and click on the + button to add a new dependency. Choose Maven dependency from the list:

Adding a Maven dependency

You'll get a dialog box where you can enter search terms or the fully-qualified Maven coordinate string. Since GSON is a common library for Android developers to use, it's actually given in this dialog as an example, with the fully-qualified name. You can type it in:

Adding GSON dependency

Hit OK on both dialogs and you should be good to go.

With these Maven dependencies, the build system will automatically download the library and cache it if hasn't done so already; it takes care of that for you.

If you had a library that wasn't available on MavenCentral, you could save the archive in a libs folder in your project, and from that module dependencies dialog, add a File dependency instead of a Maven dependency to take care of it.

If you edit your build.gradle file by hand, you need to click on the "Sync Project with Gradle Files" button in the toolbar to force Android Studio to pick up the changes and update your project. If you go through the Project Structure dialog, that's unnecessary.

There are lots of conflicting answers to this issue in Stack Overflow because the functionality for this is in flux as the necessary features are implemented; it has been really broken before. These instructions should work properly for 0.3.6, and things will get a little easier in 0.3.7 and later.

Sunday, August 1, 2021
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :