使用Gradle将AndroidSlidingUpPanel添加到IntelliJ IDEA项目

时间:2014-02-27 22:25:46

标签: android gradle android-gradle

我使用Gradle在IntelliJ IDEA上创建了一个项目,我正在尝试向其添加AndroidSlidingUpPanel(https://github.com/umano/AndroidSlidingUpPanel)。

我到底需要做什么来配置它?

我有以下文件夹结构:

RootFolder
|_libraries
    |_ AndroidSlidingUpPanel
         |_ library
               |_ build.gradle
         |_ settings.gradle
         |_ build.gradle
|_app
    |_ build.gradle
|_ settings.gradle
|_ build.gradle

文件是这样的:

RootFolder / settings.gradle

include ':app'
include ':libraries:AndroidSlidingUpPanel:library'

RootFolder /的build.gradle

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

allprojects {
    repositories {
        mavenCentral()
    }
}

RootFolder /库/ AndroidSlidingUpPanel / settings.gradle

include ':library'
include ':demo'

RootFolder /库/ AndroidSlidingUpPanel /的build.gradle

allprojects {

  group 'com.sothree.slidinguppanel'
  version '1.0.0-SNAPSHOT'

  buildscript {
    repositories {
      mavenCentral()
    }
  }

  dependencies {
    repositories {
      mavenCentral()
    }
  }
}

RootFolder /库/ AndroidSlidingUpPanel /库/的build.gradle

apply plugin: 'android-library'

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

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

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

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

RootFolder /应用/的build.gradle

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.2"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:gridlayout-v7:19.0.1'
    compile 'com.android.support:support-v4:19.0.1'
    compile 'com.android.support:appcompat-v7:19.0.1'
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

1 个答案:

答案 0 :(得分:0)

您不清楚可能遇到的构建错误或确切问题是什么,但由于您在 app / build.gradle 中没有依赖SlidingUpPanel,问题是如何包含它?

如果是这样,首先要记住的是项目不能有多个 settings.gradle 。更确切地说,它只在它的根文件夹中查找并使用它,如果它在那里。因此, RootFolder / libraries / AndroidSlidingUpPanel / 中的 settings.gradle 将被忽略。看起来您已经在 RootFolder / settings.gradle 中正确设置了include到SlidingUpPanel库,所以这很好:

include ':libraries:AndroidSlidingUpPanel:library'

要在您的应用中包含对它的依赖,您使用compile project语句并为其指定相同的路径:

dependencies {
    compile 'com.android.support:gridlayout-v7:19.0.1'
    compile 'com.android.support:support-v4:19.0.1'
    compile 'com.android.support:appcompat-v7:19.0.1'
    compile project(':libraries:AndroidSlidingUpPanel:library')
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

如果您正在使用Android Studio(它也应该与IntelliJ Community Edition中基于Gradle的项目一起使用),您可以通过模块>在项目结构对话框中设置模块的依赖关系。 您的模块 > 依赖关系> + > 模块依赖

Project Structure dialog showing how to add a module dependency

如果您已将模块添加到 settings.gradle 文件中,并已将项目同步到Gradle文件,则SlidingUpPanel模块应显示在项目视图中IDE,应该在该依赖项列表中作为模块选择出现。