将 volley 导入 Android Studio 1.3.0 项目

Import volley into Android Studio 1.3.0 project

我在 android studio 1.3.0 项目中导入和使用 volley 库时遇到问题。我已经按照在线教程将 volley 从 git 导入到项目目录中。

现在,我在让它与项目一起工作时遇到了问题。我无法使用在线说明构建它。

它生成的错误是:

错误:(23, 0) Gradle 未找到 DSL 方法:'compile()' 可能的原因:

  • 项目 'Hrup' 可能正在使用不包含该方法的 Gradle 版本。 Gradle 设置
  • 构建文件可能缺少 Gradle 插件。 应用 Gradle 插件
  • 我为所有文件夹添加了 build.gradle 和 settings.gradle

    等文件

    Build.gradle(截击)

    // NOTE: The only changes that belong in this file are the definitions
    // of tool versions (gradle plugin, compile SDK, build tools), so that
    // Volley can be built via gradle as a standalone project.
    //
    // Any other changes to the build config belong in rules.gradle, which
    // is used by projects that depend on Volley but define their own
    // tools versions across all dependencies to ensure a consistent build.
    //
    // Most users should just add this line to settings.gradle:
    //     include(":volley")
    //
    // If you have a more complicated Gradle setup you can choose to use
    // this instead:
    //     include(":volley")
    //     project(':volley').buildFileName = 'rules.gradle'
    
    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.3.0'
            compile project (':volley')
        }
    }
    
    apply plugin: 'com.android.library'
    
    android {
        compileSdkVersion 22
        buildToolsVersion = '22.0.1'
    }
    
    apply from: 'rules.gradle'
    
    dependencies {
    
    }
    

    Build.gradle(应用程序)

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.1"
    
        defaultConfig {
            applicationId "com.bali.hrup"
            minSdkVersion 14
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:23.0.1'
    }
    

    Build.gradle(Hrup{我的项目名})

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.3.0'
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            jcenter()
        }
    }
    

    Settings.gradle

    include ':app'
    include ':volley'
    

    只是一个小改动,编辑文件 build.gradle(app),而不是 build.gradle(volley)

    只需添加一行

        compile project (':volley')
    

    最终文件 (build.gradle(app)) 将如下所示:

        apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.1"
    
        defaultConfig {
            applicationId "com.bali.hrup"
            minSdkVersion 14
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:23.0.1'
        compile project (':volley')
    }