Android Gradle构建问题

时间:2015-07-02 19:38:50

标签: android gradle

我试图将项目从旧的Android工作室导入到新版本中。项目包括Cordova lib。我对gradle有很大的问题 目前,我遇到了这个问题Error:Configuration with name 'default' not found.

这是来自gradle.build的代码

import java.util.regex.Pattern

apply plugin: 'com.android.application'

buildscript {
    repositories {
        mavenCentral()
    }

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

ext.multiarch=false

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    for (subproject in getProjectList()) {
        compile project(subproject)
    }
}

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

    defaultConfig {
        versionCode Integer.parseInt("" + getVersionCodeFromManifest() + "0")
    }

    compileSdkVersion 19
    buildToolsVersion "19.1"

    if (multiarch || System.env.BUILD_MULTIPLE_APKS) {
        productFlavors {
            armv7 {
                versionCode defaultConfig.versionCode + 2
                ndk {
                    abiFilters "armeabi-v7a", ""
                }
            }
            x86 {
                versionCode defaultConfig.versionCode + 4
                ndk {
                    abiFilters "x86", ""
                }
            }
            all {
                ndk {
                    abiFilters "all", ""
                }
            }
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

}

task wrapper(type: Wrapper) {
    gradleVersion = '2.2.1'
}

def getVersionCodeFromManifest() {
    def manifestFile = file(android.sourceSets.main.manifest.srcFile)
    def pattern = Pattern.compile("versionCode=\"(\\d+)\"")
    def matcher = pattern.matcher(manifestFile.getText())
    matcher.find()
    return Integer.parseInt(matcher.group(1))
}

def getProjectList() {
    def manifestFile = file("project.properties")
    def pattern = Pattern.compile("android.library.reference.(\\d+)\\s*=\\s*(.*)")
    def matcher = pattern.matcher(manifestFile.getText())
    def projects = []
    while (matcher.find()) {
      projects.add(":" + matcher.group(2).replace("/",":"))
    }
    return projects
}

代码的某些部分以dependencies cannot be applied to (groovy.lang.Closure)例外突出显示 这是gradle.properties

import java.util.regex.Pattern


    def getProjectList() {
    def manifestFile = file("project.properties")
    def pattern = Pattern.compile("android.library.reference.(\\d+)\\s*=\\s*(.*)")
    def matcher = pattern.matcher(manifestFile.getText())
    def projects = []
    while (matcher.find()) {
      projects.add(":" + matcher.group(2).replace("/",":"))
    }
    return projects
}

for (subproject in getProjectList()) {
    include subproject
}

include ':'

我不确切知道这个例外是什么,也不知道如何解决这个问题。

1 个答案:

答案 0 :(得分:1)

我浪费了很多时间试图解决同样的问题,发现在新版本的Android工作室中创建一个全新的项目,创建具有完全相同名称的活动/片段,然后复制/粘贴所有项目要容易得多的java,xml,图像等。