Android Studio - android-4.2.2/dx failed when importing Facebook Android SDK

Problem

Got this error in Android Studio while following Getting Started with the Facebook SDK for Android (Android Studio) tutorial on Facebook.

Gradle: Execution failed for task ':HelloWorldAndroid:dexDebug'.
> Running /Applications/Android Studio.app/sdk/build-tools/android-4.2.2/dx failed. See output





Solution

1. Use latest Android Gradle Plugin

First, in order to use the most recent version of the Android Gradle Plugin, change all occurences of Gradle classpath in build.gradle file.

buildscript {
  dependencies {
    classpath 'com.android.tools.build:gradle:0.4'
  }
}


to

buildscript {
  dependencies {
    classpath 'com.android.tools.build:gradle:0.4.+'
  }
}


2. Install Android Repositories

Make sure the following components of Android SDK are installed:

  1. Android Support Repository
  2. Google Repository



3. Change the reference for Android Support library

The correct way to reference to Android Support Library is shown below. (Instead of referencing android-support-v4.jar files in every library.

dependencies {
    compile files('libs/android-support-v4.jar')
}


to

dependencies {
    compile 'com.android.support:support-v4:13.0.0'
}



That's it! Your project should be able to compile and run without error!




References:
1. http://showlabor.blogspot.ca/2013/05/actionbarsherlock-in-android-studio-01.html

Comments

Popular posts from this blog

[Azure Websites PHP] Cross Domain request results in blank response page after Preflight HTTP OPTIONS

[Magento] Create Contact Form with Dynamic Recipient