Gradle没有正确构建 - “找不到方法v2SigningEnabled for arguments [false]”

时间:2017-04-16 04:30:34

标签: android gradle android-gradle

我最近更新了android studio,现在我无法生成签名的APK。
这是我的build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.me.myapp"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    signingConfigs {
        release {
            storeFile file("keystore.jks")
            storePassword "mypassword"
            keyAlias "My app"
            keyPassword "mypassword"
        }
    }
    buildTypes {
        release {
            v2SigningEnabled false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}


这是我的错误:

INFO - e.project.sync.GradleSyncState - Sync with Gradle for project 'myApp' failed: Could not find method v2SigningEnabled() for arguments [false] on BuildType_Decorated{name=release, debuggable=false, testCoverageEnabled=false, jniDebuggable=false, pseudoLocalesEnabled=false, renderscriptDebuggable=false, renderscriptOptimLevel=3, minifyEnabled=false, zipAlignEnabled=true, signingConfig=null, embedMicroApp=true, mBuildConfigFields={}, mResValues={}, mProguardFiles=[], mConsumerProguardFiles=[], mManifestPlaceholders={}} of type com.android.build.gradle.internal.dsl.BuildType.

Consult IDE log for more details (Help | Show Log) 
2017-04-16 00:25:43,319 [ 554494]

1 个答案:

答案 0 :(得分:2)

SigningConfig should not be set inside buildTypes - Release. It should be something like below.

` android {

defaultConfig {
    applicationId "com.app.test"

}

signingConfigs {
    release {
        v2SigningEnabled false
    }
}
buildTypes {

        release {
            .....

        }
        debug {
            .....
        }


}

}`