Gradle无法正确构建 - “无法找到方法v2SigningEnabled参数[false]”

问题描述:

我最近更新了android studio,现在我无法生成已签名的APK。
这里是我的build.gradle
Gradle无法正确构建 - “无法找到方法v2SigningEnabled参数[false]”

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] 
+0

你为什么要加上'v2SigningEnabled FALSE'? –

+0

@JaredBurrows我想使用旧的签名方法 –

SigningConfig不应里面buildTypes设置 - 发行。它应该是下面的东西。

` 的Android {

defaultConfig { 
    applicationId "com.app.test" 

} 

signingConfigs { 
    release { 
     v2SigningEnabled false 
    } 
} 
buildTypes { 

     release { 
      ..... 

     } 
     debug { 
      ..... 
     } 


} 

}`