Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio missing external dependencies

I have a library project. I want to use Android's new build system. Currently I'm encountering a quite annoying scenario.

I have my dependencies defined on gradle.build but they never appear under External Libraries in Android Studio. Hence all the references to those libraries are marked as errors.

When I run gradle dependencies on the command line it shows the full dependencies tree and compiles successfully. The problem clearly is with Android Studio.

I tried to restart the IDE/OS but nothing.

This is my gradle.build

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4.1'
    }
}

apply plugin: 'android-library'

apply plugin: 'idea'

repositories {
    mavenCentral()
}

dependencies {
    compile 'junit:junit:4.11'
    compile 'org.robolectric:robolectric:2.1:jar-with-dependencies'

    compile 'com.google.android:android:4.1.1.4'
    compile 'com.google.android:support-v4:r7'

    compile 'info.cukes:cucumber-java:1.1.3'
    compile 'info.cukes:cucumber-junit:1.1.3'
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        versionCode 1
        versionName "0.3-SNAPSHOT"
        minSdkVersion 15
        targetSdkVersion 17
    }
}

UPDATE

This issue seems to be fixed on latest Android Studio version (0.2.5)

like image 371
Axxiss Avatar asked Jun 02 '13 10:06

Axxiss


2 Answers

You can use 'Tools->Android->Sync project with Gradle files'. It will resolve the dependencies, download, and add them to external libraries.

like image 132
Aleksandar Apostolov Avatar answered Oct 05 '22 05:10

Aleksandar Apostolov


Unfortunately, in the current version of Android Studio, the IDE is not completely integrated with the build system (gradle). You have to add the library once in gradle.build for compilation, and once via the GUI for code completion.

Right click on your project, select "Open Module Settings". Acknowledge the warning. Select "Libraries", "+", and add the library you are using. You can search for libraries on Maven in the dialog that appears. You should select your libs dir for the jar. Finally, add the library to your code's module. If your app is MyApp, you probably have MyApp and MyAppProject. You need to add it to MyApp. (You can probably also directly add it from the "Modules" page.)

To additionally get gradle to add the jar to your apk, make the following changes to your grade file. Replace:

compile 'org.jsoup:jsoup:1.6.1'

and similar with

compile files('libs/jsoup-1.6.1.jar')

Now it should all work.

like image 43
jdm Avatar answered Oct 05 '22 05:10

jdm