Getting error while adding Facebook SDK in build.gradle - android

I am working on a project where I need to implement facebook login. For that purpose I followed the steps from the developer website as mentioned. But unfortunately getting build error after adding'com.facebook.android:facebook-android-sdk:4.1.0' in build.gradleas follows
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.facebook"
minSdkVersion 11
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
}
Error log which I am getting:
Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not resolve com.facebook.android:facebook-android-sdk:4.1.0.
Required by: ExampleApp:app:unspecified
> No cached version of com.facebook.android:facebook-android-sdk:4.1.0 available for offline mode.
> No cached version of com.facebook.android:facebook-android-sdk:4.1.0 available for offline mode.
Please help me to resolve this issue which I am facing right for a couple of days. I am really helpless and stuck up with the solutions. Any kind of suggestions would be much useful to fix my issue.

Your log gives the answer:
No cached version of com.facebook.android:facebook-android-sdk:4.1.0 available for offline mode.
Gradle is in offline mode, so it cannot download a new version of your library.
Go to Preferences > Build, Execution, Deployment > Build Tools > Gradle
and disable "Offline work".
Preferences can be accessed from here:

You do not need repositories in this gradle file as you should have one "global" build.gradle so remove this entry from module's grade file. And you should also check what repository is set there as it should be jcenter() not mavenCentral() as the latter is replaced with jcenter() for some time now.
allprojects {
repositories {
jcenter()
}
}

Related

Android Studio Error:(3, 0) Plugin with id 'com.android.application' not found

I'm new to android studio and had somebody write an app I made which was originally used in app inventor. I followed his template and added new things. The app has a problem with the Gradle and gives me the following.
"Error:(3, 0) Plugin with id 'com.android.application' not found."
It also says that my extras Android Support Repository isn't installed however it is. and everything is up to date. I saw many things about updating the Gradle, How do I do that if the SDK manager didn't.
code is:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.0.2"
defaultConfig {
applicationId "contactorganizer.introcode.or.myapplication"
minSdkVersion 8
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.0'
}
Sorry about not having much knowledge.
If you would like the project I can email it to you because I have absolutely no clue and would love to just build this.
Thanks for your help!
When I updated my Android Studio to the latest, I got the same problem. Here is how I solved it.
First:
Add the following code to the top of your build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
Second: Find the gradle-wrapper.properties.
Change the last sentence to this:
distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip
Hope this works for you.
I have faced the problem too. The android plugin is 1.2.3. It appears when running one module task in the module directory like this way, ../graldew :module:xxx.
I eventually notice plugin 1.2.3 cannot get right context and android plugin 1.5 works well. So It will work to give it right gradle file.
../gradlew -b ../build.gradle -c ../settings.gradle :module:xxx
This is the situation for me. You can just regard it as a reference.

Gradle failed to refresh Android Studio

Ive been installing and re-installing AndroidStudio since i keep getting the error
> Gradle 'android' project refresh failed:
> Open quote is expected for attribute "{1}" associated with an element type "language".
All of my group members can open up the project without receiving this error except me.I am in dire need of help,i just want to finish my group project for the semester.Thank you for your help.
settings.gradle
include ':app'
build.gradle in the app folder
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.3.23'
compile 'com.android.support:support-v4:18.0.0'
files('libs/json-simple-1.1.1.jar')
compile files('libs/json-simple-1.1.1.jar')
}
build.gradle in the gradle folder
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
Update:did another re-intstall of Android Studio and now its giving me this error.
Failed to refresh Gradle project 'android'
Out of memory: Java heap space. Configure Gradle memory settings using '-Xmx' JVM option (e.g. '-Xmx2048m'.)
Please fix the project's Gradle settings.
Gradle settings
You might have typed closed quote (“) instead of open quote("). Change the quotes at start and end of attribute.

Android Studio: cannot resolve some symbol and method

I install the Android Studio and build a new project, but the automatic generated code show lots of "cannot resolve" errors like "cannot resolve symbol app" in the code "import android.support.v7.app.ActionBarActivity;"
The onCreate and setContentView Method cannot be resolved too
My Android Studio version is 0.4.2 , gradle version is 1.9
my build gradle is:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
You can do "File" -> "Invalidate Caches...", and select "Invalidate and Restart" option to fix this.
Well that worked for me.
Open your SDK Manager (you can find it in toolbar), and download
Android Support Repository and Android Support Library (you can find them in extras).
Google Repository and Google Play Service
Then sync your project with your gradle files (there is a button in toolbar).

Network is unreachable: connect

After Upgrading to version 0.4.0 of Android Studio, I have started getting the following error when compiling my project:
A problem occurred configuring project ':muve'.
> Could not resolve all dependencies for configuration ':muve:classpath'.
> Could not resolve com.android.tools.build:gradle:0.7.+.
Required by:
MUVE:muve:unspecified
> Failed to list versions for com.android.tools.build:gradle:0.7.+.
> Could not list versions using M2 pattern 'http://repo1.maven.org/maven2/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]'.
> Could not GET 'http://repo1.maven.org/maven2/com/android/tools/build/gradle/'.
> Network is unreachable: connect
My build.gradle file is:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 11
targetSdkVersion 18
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
I am at a loss on how to resolve the issue. Any help would be highly appreciated.
Thanks
It's a networking problem, somewhere between you and Maven Central. Try again after a while, perhaps with --refresh-dependencies. I've you've successfully built with the same dependencies before, you can also try an offline build (-o).
Try this and check whether your studio can make connection successful with mention maven repository in error.
Go to File > Settings > HTTP proxy , select auto detect proxy settings just for test.
In my case, I was using an HTTP proxy, and this was my .gradle/gradle.properties :
systemProp.http.proxyHost=10.23.201.11
systemProp.http.proxyPort=3128
I changed it to HTTPS, even though I was using HTTP
systemProp.https.proxyPort=3128
systemProp.https.proxyHost=10.23.201.11
When I hit Sync, Android Studio Popped this:
Android Studio Pop up
Uncheck the HTTPS proxy and then OK.

Cannot build app when using gradle (Android Studio) and local maven repo

I am trying to include the library Slik and Cards-UI in my app, I'm using android studio and gradle to build. The app builds fine without this but adding the dependency make the build fail. Looking at the debug log of the build it doesn't seem to be looking in the local repo for the arr file. I can see the files are there and I have followed the tutorial on the github wiki page for the install and that works fine. The error is:
A problem occurred configuring project ':climbtrack'.
> Could not resolve all dependencies for configuration ':climbtrack:_debugCompile'.
> Could not find com.afollestad.cardsui:library:1.0-SNAPSHOT.
Required by:
ClimbTrack:climbtrack:unspecified
> Could not find com.afollestad.silk:library:1.0-SNAPSHOT.
Required by:
ClimbTrack:climbtrack:unspecified
Here is my build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
repositories {
mavenLocal()
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
compile 'com.afollestad.cardsui:library:1.0-SNAPSHOT'
compile 'com.afollestad.silk:library:1.0-SNAPSHOT'
}
The google play services dependency works fine and is found from the maven central repo as expected.
Any ideas anyone?
Thanks
This is bug https://code.google.com/p/android/issues/detail?id=63908
If you look at comment #3 in that bug, there's a workaround. Try it and see if it helps:
This appears to be a bug in Gradle 1.9 with local Maven repositories.
See https://plus.google.com/109385828142935151413/posts/hF7W59uZ7rX
The workaround for now is to use
maven { url "${System.env.HOME}/.m2/repository" }
instead of mavenLocal()
In Android Studio 0.4.6 using mavenLocal works fine:
repositories {
mavenCentral()
mavenLocal()
}
Check and configure your Maven installation on Preferences >> Maven to ensure it points to your local repository.
I hope this update helps newcomers.

Categories

Resources