如何在Android Studio中为ActionBarSherlock正确设置Gradle?

时间:2013-07-14 17:58:52

标签: gradle android-studio

所以我很难在Android Studio v0.2中使用Gradle v1.6设置一个非常简单的项目。 我想创建一个使用ActionBarSherlock的简单应用程序,因此我在Android Studio中创建了一个Project 在创建项目的同一根文件夹中,我已经下载了最新的ABS。

所以这是我的结构:

|ABSAppProject 
|..settings.gradle
|..build.gradle
|--ABSApp
|....build.gradle
|actionbarsherlock
|..build.gradle

在根settings.gradle中,我有:

include ':ABSApp'
include 'actionbarsherlock'
project(':actionbarsherlock').projectDir=new File('actionbarsherlock')

actionbarsherlock/build.gradle我有:

apply plugin: 'android-library'

buildscript {
    repositories {
        mavenCentral()
    }

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

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

android {
  compileSdkVersion 14
  buildToolsVersion '17'

  sourceSets {
    main {
      manifest.srcFile 'AndroidManifest.xml'
      java.srcDirs = ['src']
      res.srcDirs = ['res']
    }
  }
}

最后,ABSApp/build.gradle,我有:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.android.support:support-v4:r7'
    compile project (':actionbarsherlock')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 16
    }
}

root build.gradle为空。

构建时,(使用gradle build --info)我得到:

Starting Build
Settings evaluated using settings file '/Users/m/Documents/Projects/ABSAppProject/settings.gradle'.
Projects loaded. Root project using build file '/Users/ma/Documents/Projects/ABSAppProject/build.gradle'.
Included projects: [root project 'ABSAppProject', project ':ABSApp', project ':actionbarsherlock']
Evaluating root project 'ABSAppProject' using build file '/Users/m/Documents/Projects/ABSAppProject/build.gradle'.
Evaluating project ':ABSApp' using build file '/Users/m/Documents/Projects/ABSAppProject/ABSApp/build.gradle'.
Evaluating project ':actionbarsherlock' using empty build file.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':ABSApp'.
> Failed to notify project evaluation listener.
   > Configuration with name 'default' not found.

使用Gradle单独构建ABS库似乎工作正常,因此gradle.build文件可能没问题。

我做错了什么?

2 个答案:

答案 0 :(得分:2)

无需单独下载ABS。 Gradle支持Android的新.aar format,这使得使用库项目更加容易。只需将此(或当前的任何版本)添加到项目的dependencies中的build.gradle部分:

compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'

让Gradle处理剩下的事情。

答案 1 :(得分:0)

settings.gradle中actionbarsherlock的条目应为

  

包括'..:actionbarsherlock'

您不应该需要project(':actionbarsherlock').projectDir=new File('actionbarsherlock')