构建脚本错误,升级到0.5.1后发现不支持Gradle DSL方法:'release()'!

3
无法解决此错误,我已更新Android Studio。查看了其他解决方案,但对我无效,请帮忙解决。
构建脚本错误,找到不支持的Gradle DSL方法:'release()'!可能的原因是:
-您正在使用不支持该方法的Gradle版本 -您没有应用提供该方法的Gradle插件 -或者在构建脚本中存在错误 Gradle设置
Gradle版本-0.9
主Gradle。
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }

}
apply plugin: 'android'

android {
    compileSdkVersion 19

    buildToolsVersion "19.0.0"

}

项目 Gradle 文件
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 17
    buildToolsVersion '18.0.1'

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 17
    }

    signingConfigs {
        release {
            storeFile file('dsc.jks')
            storePassword 'dscneo'
            keyAlias 'dsc'
            keyPassword 'dscneo'
        }
    }

    buildTypes {
        debug {
            versionNameSuffix '-DEBUG'
        }
        beta {
            versionNameSuffix '-BETA'
        }
        release {
            signingConfig signingConfigs.release
        }
    }


}

dependencies {
    compile 'com.google.android.gms:play-services:3.1.36'
    compile 'com.android.support:appcompat-v7:18.0.+'
    compile 'com.android.support:support-v4:+'
    compile files('libs/libGoogleAnalyticsServices.jar')
    compile files('libs/signpost-commonshttp4-1.2.1.1.jar')
    compile files('libs/signpost-core-1.2.1.1.jar')
    compile files('libs/gson-2.1.jar')
    compile project(':facebook')
    compile project(':TabIndicatorLibrary')
    compile files('libs/YouTubeAndroidPlayerApi.jar')
    compile project(':VerticalViewPager')
    compile files('libs/universal-image-loader-1.9.1.jar')
    compile files('libs/universal-image-loader-1.9.1-sources.jar')
    compile files('libs/twitter4j-core-3.0.5.jar')
    compile files('libs/HockeySDK-3.0.1.jar')
}

Facebook SDK Gradle文件

apply plugin: 'android-library'

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

android {
    compileSdkVersion 17
    buildToolsVersion "18.0.1"

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

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

其他库项目 gradle 文件

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

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

android {
    compileSdkVersion 16
    buildToolsVersion '18.0.1'

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

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

再添加一个库项目的Gradle文件。

apply plugin: 'android-library'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion "19.0.0"

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

dependencies {
    compile 'com.android.support:appcompat-v7:+'
}

请发布您的Gradle文件和Gradle包装器版本。 - Gabriele Mariotti
@GabrieleMariotti 已编辑,请检查。 - MohsinSyd
1个回答

7

在您的最后一个文件(库)中,您将release块放在android块内。

现在库项目的DSL与应用程序项目相同

特别是您需要将release块放在buildTypes内。

android {
    buildTypes {           
        release {
        }
    }

我建议您在所有gradle文件中使用buildToolsVersion '19.0.x'

您可以将其放置在根目录下的build.gradle中。

ext {
    compileSdkVersion = 19
    buildToolsVersion = "19.0.3"
}

然后在每个build.gradle文件中,您可以使用:

 compileSdkVersion rootProject.ext.compileSdkVersion
 buildToolsVersion rootProject.ext.buildToolsVersion

谢谢Gabriele,我会尝试的 :) - MohsinSyd
无法工作,先生,我遇到了这个错误 :( 错误:在任务':checkDebugManifest'的配置中发现问题。
为属性'manifest'指定的文件'/home/webwerks/AndroidStudioProjects/dsc/DubaiSportsCouncilProject/src/main/AndroidManifest.xml'不存在。
- MohsinSyd
它是否位于DubaiSportsCouncilProject/src/main/AndroidManifest.xm?您的错误消息显示文件..不存在。 - Gabriele Mariotti
@msn 您的目录结构应该是:app/src/main/AndroidManifest.xml - IgorGanapolsky
+1...我来自另一个问题,但这个答案帮助了我解决其他问题。 - uLYsseus

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接