5

I have successfully imported ActionBarSherlock to my project, and need to import another two libraries: Sliding Layer and Crouton. I know that similar questions have already appeared here before, but I've tried almost everything, each time breaking something in the project in a way that I had to start over.

My project tree looks like:

MyProject/
+ app/
+ libraries/
   + actionbarsherlock/
   + crouton/
   + slidinglayer/

I imported those two libraries as modules (File->Import Module)

My setting.gradle file looks like it should:

include ":libraries:actionbarsherlock", ':Krypto', ':libraries:crouton', ':libraries:slidinglayer'

actionbarsherlock gradle:

buildscript {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android-library'

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

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 16
    }

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

app gradle:

buildscript {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

dependencies {
    compile project(":libraries:actionbarsherlock")
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 16
    }
}

slidinglayer gradle:

apply plugin: 'android-library'

dependencies {
    compile "com.android.support:support-v4:18.0.0"
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.0.1"

    defaultConfig {
        minSdkVersion 4
        targetSdkVersion 18
    }

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

In crouton folder there is no gradle.build file. How it should look like? Theres only java files (no resources).

How to set up correctly dependencies in crouton and slidinglayer libraries?

4

2 回答 2

5

烤面包片的 build.gradle

buildscript {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}

apply plugin: 'android-library'

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

android {
    compileSdkVersion 18
    buildToolsVersion "18.0.1"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 17
    }

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

并在您的应用程序 build.gradle 中,更改

dependencies {
    compile project(":libraries:actionbarsherlock")
}

dependencies {
    compile project(":libraries:actionbarsherlock")
    compile project(":libraries:crouton")
    compile project(":libraries:slidinglayer")
}

并在 Android Studio 中再次导入

于 2013-09-06T15:36:40.787 回答
1

我不知道如何解决您的问题,但是当我在 Gradle 构建中遇到第三方库使用问题时,我通过以下方式解决了。

以下是我的项目结构。

GsonDemoProject
   GsonDemo
      构建
      库
          android-support-v4.jar
          gson.jar
      src
          main
          build.gradle
      build.gradle
      settings.gradle

我编辑了build.gradle位于src目录中的文件。

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

我将第 3 方库的引用放在dependencies上面的标签中。在我的项目libs中是放置库的目录。

于 2013-08-08T13:54:13.317 回答