Import the library as an existing Android code into workspace - android

I'm trying to import existing code (library) into Android Studio workspace according to this guide.
A have done everything step-by-step and Gradle refuses to synchronize project with error message:
Gradle 'MyApplication' project refresh failed. Error:Configuration with name 'default' not found.
Any ideas what went wrong?

You're following an outdated guide.
You should add a new module via File -> Project Structure then click the + button.
You then have various options to import libraries.
To include your library in another project add a compile project definition to your dependancies:
dependencies {
compile project(':mylibrary')
}

Related

Android Studio ! How to add Facebook-SDK in Libgdx Project?

I tried to add facebook-android-sdk by file -> import -> new -> module -> facebook-android-sdk-4.20 -> facebook. added successfully
but error occured "core 1.0 depends on one or more android libraries but is a jar."
Created New libgdx project.
Then I added facebook-android-sdk gradle module from https://github.com/facebook/facebook-android-sdk added successfully
but error occured "Error:Could not get unknown property 'ANDROID_BUILD_SDK_VERSION' for project ':facebook' of type org.gradle.api.Project."
So how to do this?
And do we need to add separate Facebook-SDKs and dependencies for all projects or Libgdx will do it automatically?
I'm using Android studio-2.3, build tools 25.0.2, compile sdk version API 25.
Add this to your build.gradle in the dependency section of the android sub project:
compile "com.facebook.android:facebook-android-sdk:4.20.0"
Alternatively you can have a look at or just use: https://github.com/TomGrill/gdx-facebook/ and see how it is done there.

How to manually import a gradle dependency in android studio

I'm trying to contribute to an open source project from Mapzen called "On the Road". (Github link)
I would like to edit and add some code to the project. At the moment I'm including the project using gradle with the following dependency:
compile 'com.mapzen:on-the-road:1.1.1'
Someone gave me a tutorial on how to do this here, but I'm getting a gradle error;
Error:Configuration with name 'default' not found.
What I did was clone the project from github, copied the entire master folder into my apps main and renamed it to "customLibrary".
I then added include':customLibrary' to my settings.gradle and compile project(':customLibrary') to my build.gradle(Module:app) file.
How do I import this project without the errors?
As you cloned the entire master folder, inside the customLibrary there is the build.gradle file which is the top-level file of the library.
You can't do it.
Since you are including the customLibrary folder, gradle is looking for a module build.gradle.
You have to clone the library folder instead of the entire master folder.
Otherwise you can use include':customLibrary:library' only to add the module library of the entire project.

Gradle project Sync failed , How to fix?

I imported a material Dialog library from Github.
https://github.com/drakeet/MaterialDialog
And I imported the library in Android Studio.
However, now The Android Studio says "Gradle project sync failed, basic functionality (editing, debugging) will not work properly.
I tried alternative answers to similar problems from other questions here,
Gradle project sync failed?
Android Studio Gradle project sync failed
But, none works for me .
The error I get in console is : Error:Dependency ZyiaAlarm:materialDialog:unspecified on project app resolves to an APK archive which is not supported as a compilation dependency. File: F:\ZyiaAlarm\materialDialog\build\outputs\apk\materialDialog-release-unsigned.apk
My doubt is: Any way to restore the things back, I mean to get the gradle as it was as I am a beginner, there's much to learn about gradle.
OR
anyway to fix this library I imported ?
Any help will be appreciated!
Too long for a comment.
It is not clear how do you import it.
If you would like to build locally this library, you should have this type of structure:
root
MaterialLib
build.gradle
app
build.gradle
build.gradle
settings.gradle
where MaterialLib is the folder MaterialDialog/library from github.
You haven't to import the other folders from github.
Also in
app/build.gradle you should have:
dependencies {
compile project(':MaterialLib')
}
and in the settings.gradle you should have:
include ':app',':MaterialLib'
However I suggest you avoiding the local library.
Remove the MaterialLib (don't import code from github).
Just add to your app/build.gradle these lines:
dependencies {
compile 'me.drakeet.materialdialog:library:1.2.2'
}
In this you should have this type of structure:
root
app
build.gradle
build.gradle
settings.gradle
and in the settings.gradle you should have:
include ':app'

Importing library gives error in Android studio

I am new to Android Studio. I am trying to work using the android-map-utils library. But it is giving me the following error.
`Error:(64) A problem occurred evaluating project ':library'.
> No such property: sonatypeUsername for class: org.gradle.api.internal.project.DefaultProject_Decorated`
Can anyone help me with this issue and also tell me a easy way to import libraries in android studio?
I had a similar problem while I was migrating from eclipse. I resolved my issue by using the gradle method of including the library (as opposed to importing it as a module and using it as a dependency).
Add the following dependency to your Gradle build file:
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.3+'
}
source: http://googlemaps.github.io/android-maps-utils/#start
I wasn't able to comment.
Applying gradle dependency as link doesn't allow us to view it's source properly.
So if you are interested in viewing source too, in Android Studio itself
You should try adding library as a module project, i.e.,
File -> New -> Import Module -> (Dir of Library)
after importing, you'll face an error, which can be resolved from - Adding Maps Utils Module

Android Studio - Importing libraries to a gradle project

I imported a gradle project from eclipse and I'd like to add some libraries to the project.
The usual approach would be to import a module in the Project Structure window.
The problem is that according to google I can't do that with a gradle project: Android Studio - Project structure is almost empty
If so, in what way that is compatible with gradle projects can I import a library?
In the project window, right click on your project name and new a directory named 'libs'. libs has the same level of build and src.
Copy your jar file to libs within file manager of OS.
Wait for seconds, the jar file will show under libs in android studio. Right click on it and click 'add as library'.
Add info to build.gradle, for example
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile files('libs/NameOfYourFile.jar')
}
Now, you can use the library and build. If you get some errors, Enter project directory and run ./gradlew clean and rebuild your project.

Categories

Resources