title: gradle assembleRelease uses wrong key/certificate
body: <p>I have a gradle-based android project and trying to generate a release apk. However, it seems that somehow gradle is picking up the wrong key/cert.</p>
  
  <p>This is what I have in build.gradle:</p>
  
  <pre><code>signingConfigs {
      release {
          storeFile file("mykey.jks")
          storePassword "mypass"
          keyAlias "mykey.key"
          keyPassword "mypass"
      }
  }
  
  buildTypes {
      release {
          debuggable false
          jniDebugBuild false
          runProguard true
          proguardFile getDefaultProguardFile('proguard-android.txt')
          signingConfig signingConfigs.release
      }
  }
  </code></pre>
  
  <p>And after running</p>
  
  <pre><code>gradlew assembleRelease
  </code></pre>
  
  <p>and taking out META-INF/CERT.RSA from inside the .apk I run the following:</p>
  
  <pre><code>keytool -list -keystore mykey.jks
  </code></pre>
  
  <p>and </p>
  
  <pre><code>keytool -printcert -v -file CERT.RSA
  </code></pre>
  
  <p>but they produce output with different certificate fingerprints. Trying with a certificate from another apk signed with the same key (but not with gradle) yields the correct certificate fingerprint.</p>
  
  <p>Gradle seems to be picking up the keystore fine (changing the password or location or alias makes it stop working).</p>
  
  <p>I'm puzzled since I don't want to release something to the store signed with an unknown key and then not be able to update it. I don't have a debug key explicitly defined in gradle.</p>
  
  <p><strong>UPDATE:</strong> This has something to do with the keystore. Trying the same gradle code with a fresh keystore and key works fine. This problematic keystore was imported from a pkcs#12 format (.p12 file). Using Intellij or jarsigner works fine with this keystore though, it's just the gradle code that has a different output - and it seems only the certificate generated from the key is different. </p>