Android studio 1.0.2 - gradle project sync failed - android

I have started using Android Studio 1.0.2 and I am trying to add Library dependency. For example I am adding loopj library in my project.
Steps which I follow:
File > Project Structure > Module(app) > Dependencies tab > Click on + icon > select loopj library > Apply > OK
Now I am getting issue of Gradle project sync failed.
Message : Failed to find: com.loopj.android:android-async-http:1.4.6
Somebody else facing the same problem? Please provide me suggestion if any.
Other information
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.test.testapplication"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.loopj.android:android-async-http:1.4.6'
}
//
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
//
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-2.2.1-all.zip

I've faced the same problem. The solution was simple, all you need is upgrade your gradle version. To do this, open your build.gradle (root project) and edit the next line:
classpath 'com.android.tools.build:gradle:1.0.0'
to
classpath 'com.android.tools.build:gradle:1.1.0'
So if you are using Android Studio you will notice that you are using offline mode that's not available in the new gradle version. Confirm the change and now you can download the dependencies you want.

Related

Android Studio Gradle does not download maven depedencies

I am quite new to Android development and trying to write some test code. I have downloaded Android Studio 1.3 version and created testapp. I am trying to add com.facebook.android:facebook-android-sdk:4.1.0 depedency but somehow it's not getting downloaded.
Here is Project level build.gradle file.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}}
Here is Module level build.gradle file.
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.testapp"
minSdkVersion 19
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile 'com.android.support:appcompat-v7:22.2.1'
}
After reading other posts on similar topics I also confirmed that Gradle > Global Gradle settings > Offline work is not checked. Still somehow facebook depedency is not getting downloaded.
Any suggestions what could be the issue? Appreciate any pointers.
Thanks.
In your build.gradle you have to add
repositories {
jcenter()
}
It this way gradle knows where are the dependencies to download.
It is somenthing different from the repositories inside the buildscript block.
Otherwise you can add in the top-level build.gradle file:
allprojects {
repositories {
jcenter()
}
}
In this case, the repository block is valid for all modules in the project.
Could you post the error AndroidStudio is showing? (check on the Gradle Console, on the Run section and Android Monitor section)
One possible option that comes to my mind is that you don't have the lastest Android Support repository / Google repository installed: Check for updates on your Android SDK Manager.

Android Studio cannot resolve 3rd party dependencies

With the newer versions of Android Studio it has been advertised that you can add compile statements to the build.gradle file for 3rd party libraries that are available on Maven Central and Android Studio should be able to automatically download the appropriate dependencies. However I haven't been able to get the Gradle Sync to successfully complete when I try to add one of these libraries. Here is the build.gradle file for the project
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.appsbysynapps.helloname"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.larswerkman:HoloColorPicker:1.5'
}
Here is the build.gradle for the module
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
Here is the error given out by Gradle
Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not resolve com.larswerkman:HoloColorPicker:1.5.
Required by:
HelloName:app:unspecified
> org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
> org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
I've been having the same issue for any 3rd party library I've tried to add. This is also a brand new project created in Android Studio 1.1.0 and offline mode is disabled. Any ideas for what is going on?

Error:Artifact 'support-v4.jar (com.android.support:support-v4:21.0.3)' not found. Android studio 1.0.2

I did a new install of Android Studio 1.0.2. Getting the following error when opening my first existing android project:
Gradle 'MyApplication' project refresh failed
Error:Artifact 'support-v4.jar (com.android.support:support-v4:21.0.3)' not found.
Searched in the following locations: file:/C:/Users/Ntokozo/AppData/Local/Android/sdk/extras/android/m2repository/com/android/support/support-v4/21.0.3/support-v4-21.0.3.jar
And if I navigate to that searched location I found two jar files which are: support-v4-21.0.3-sources.jar and support-v4-21.0.3-javadoc.jar
Here is my build.gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Gradle file under App folder:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.ntokozo.myapplication"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
}
Thank you in advance, please bare in mind in responses that I'm a novice and I might not know advanced features.
After re-installing windows OS and a new Android Studio setup the problem disappeared. I don't know what was the problem at first.

Upgrading project to Android Studio 1.0 (Gradle problems)

Just to start I'm very new to android development/android studio/gradle so forgive me if I'm asking a stupid question.
My team has been working on a project with the beta version of android studio, I've just installed the new version (1.0) and i've imported our project from the github remote repo.
When trying to sync the project with gradle i get the error: Gradle version 2.1 is required. Current version is 2.2.1. It recommends that I change the distributionUrl in gradle-2.1 but when I do I get the error that the gradle plugin requires 2.2.1.
The question is why is my project requiring 2.1 and where can I change this?
Here is my gradle.build:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
applicationId "com.<teamName>.<projectName>"
minSdkVersion 14
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'])
}
buildscript{
dependencies{
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
in the gradle-wrapper.properties use the following
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
in build.gradle use
dependencies {
classpath 'com.android.tools.build:gradle:1.0.+'
also replace
runProguard false
with
minifyEnabled true
I hope this can help
I was having the same issue that you were and had made the exact same updates as described in the Google docs.
The error I was making was editing my app module's build.gradle, and not the project's build.gradle in the root of the project folder for the com.android.tools.build version.
Here's the updated PROJECT's build.gradle file that I'm using that works.
// Top-level build file where you can add configuration options common to all sub- projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
ext {
compileSdkVersion = 21
buildToolsVersion = "20.0.0"
minSdkVersion = 15
targetSdkVersion = 21
}
allprojects {
repositories {
jcenter()
}
}
To change the gradle distribution used go to this file: {Project folder}/gradle/wrapper/graddle-wrapper.properties.
Then change the distributionUrl to use 2.1:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip

Gradle doesn't find dependency - Android Studio

Gradle no longer finds dependencies declared in the build.gradle. Everything was working fine and today when I open Android Studio I get an error :
Error:Failed to find: com.readystatesoftware.systembartint:systembartint:1.0.3
The library referenced is SystemBarTint. I had the library work previously using the same build.gradle file but now it no longer works.
My app/build.gradle looks like this :
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.adnan.systembartintdemo"
minSdkVersion 19
targetSdkVersion 19
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.readystatesoftware.systembartint:systembartint:1.0.3'
}
My root/build.gradle looks like this :
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
Any ideas what I am doing wrong here? Thanks !
Edit : Tried importing a project which I work on daily at my work, it fails to find any dependencies in that project either. Tried re installing Android Studio, still the same error
Ok finally got this fixed.The problem was weird, for some reason it was trying to pick up a local offline copy of the dependency, I went to Settings -> Compiler -> Gradle -> Enabled offline Work and disabled it again. Save and Apply changes.
And now it works !

Categories

Resources