Android Studio Build of App fails claiming Keystore was tampered with

10,660

Solution 1

I edited my build types under Project Structure and removed the signing config, to see if that was the problem. That worked so I could build the APK again. Now I have a new problem, where I can't seem to get the apk to install on my phone. But that sounds like a separate problem. I'll post a new question.

BTW, thanks to Kashan Danish for the suggestion.

Solution 2

I have had this problem in Android Studio 3.3 and Gradle Build Tools 28.0.3

I did not forget the password and the keystore was not tampered with. What had happened was that i had changed to a very old branch in my Git repo. And the project had a different structure. Though there was no difference in the keystore, the project was very different.

This caused me build errors due to the build files being cached. After i invalidated and restarted and rebuilt the project this is when the problem started. I had no idea at first that it was that, since the error is quite explicit.

But what pointed me in the right direction was that i changed back to the more advanced branch and then had the same build problems as before, solved them as above, then still had the password issue with the key. I then created a new key in the same keystore with a different name. After i went back to the older branch and repeated the clean up process , i got a new error stating that the key that i had created in the latest branch, could not be found. So that made me realise that Gradle could be the culprit.

I deleted the gradle folder and the build folder and also invalidated cache and restarted Android Studio. Then it just worked.

Hope it helps someone

Share:
10,660
Rben
Author by

Rben

I like to program, write science fiction stories, and play on computers. I also enjoy sailing, cycling, reading, and theatre.

Updated on July 29, 2022

Comments

  • Rben
    Rben almost 2 years

    I have recently ported an Android app from Eclipse to Android Studio. I was able to debug the application and I've even been able to build a release version for the client to test with. Unfortunately, I can not debug anymore. When I try to run the app from Android Studio it fails. (See logcat and monitor output below.)

    As far as I know, I haven't changed the keystore. I only just created it 5 days ago. So I'm wondering where to go from here. This app has already been down for several weeks while I've been porting to Android Studio and I've got more work to do to get it functional again. (Client updated to Android 7 all at once. Ack!)

    I humbly ask for any help you can give me. Thank you, Ray.

    P.S.: Could antivirus or autobackup have anything to do with this?

    Logcat Output:

    Gradle tasks [:app:assembleDebug]
    Error:java.io.IOException: Keystore was tampered with, or password was incorrect
    Error:java.security.UnrecoverableKeyException: Password verification failed
    Error:Execution failed for task ':app:transformDexWithInstantRunDependenciesApkForDebug'.
    > com.android.build.api.transform.TransformException: com.android.ide.common.signing.KeytoolException: Failed to read key MyAndroidKey from store "I:\Users\Ray\keystores\android.jks": Keystore was tampered with, or password was incorrect
    

    And in the monitor I get:

    Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
    :app:buildInfoDebugLoader
    :app:preBuild UP-TO-DATE
    :app:preDebugBuild UP-TO-DATE
    :app:compileDebugAidl UP-TO-DATE
    :app:compileDebugRenderscript UP-TO-DATE
    :app:checkDebugManifest UP-TO-DATE
    :app:generateDebugBuildConfig UP-TO-DATE
    :app:prepareLintJar UP-TO-DATE
    :app:generateDebugResValues UP-TO-DATE
    :app:generateDebugResources UP-TO-DATE
    :app:mergeDebugResources UP-TO-DATE
    :app:createDebugCompatibleScreenManifests UP-TO-DATE
    :app:processDebugManifest
    :app:splitsDiscoveryTaskDebug UP-TO-DATE
    :app:processDebugResources
    :app:generateDebugSources
    :app:javaPreCompileDebug UP-TO-DATE
    :app:compileDebugJavaWithJavac UP-TO-DATE
    :app:mergeDebugShaders UP-TO-DATE
    :app:compileDebugShaders UP-TO-DATE
    :app:generateDebugAssets UP-TO-DATE
    :app:mergeDebugAssets UP-TO-DATE
    :app:packageInstantRunResourcesDebug UP-TO-DATE
    :app:checkManifestChangesDebug
    :app:transformClassesWithExtractJarsForDebug UP-TO-DATE
    :app:transformClassesWithInstantRunVerifierForDebug UP-TO-DATE
    :app:transformClassesWithDependencyCheckerForDebug UP-TO-DATE
    :app:compileDebugNdk NO-SOURCE
    :app:mergeDebugJniLibFolders UP-TO-DATE
    :app:transformNativeLibsWithMergeJniLibsForDebug UP-TO-DATE
    :app:processDebugJavaRes NO-SOURCE
    :app:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
    :app:transformNativeLibsAndResourcesWithJavaResourcesVerifierForDebug UP-TO-DATE
    :app:transformClassesWithInstantRunForDebug UP-TO-DATE
    :app:transformClassesEnhancedWithInstantReloadDexForDebug UP-TO-DATE
    :app:incrementalDebugTasks UP-TO-DATE
    :app:preColdswapDebug
    :app:fastDeployDebugExtractor UP-TO-DATE
    :app:generateDebugInstantRunAppInfo UP-TO-DATE
    :app:transformClassesWithInstantRunSlicerForDebug UP-TO-DATE
    :app:transformClassesWithDexBuilderForDebug
    :app:transformDexArchiveWithExternalLibsDexMergerForDebug
    :app:transformDexArchiveWithDexMergerForDebug
    :app:validateSigningDebug
    :app:transformDexWithInstantRunDependenciesApkForDebug
    Error while generating dependencies split APK
    com.android.ide.common.signing.KeytoolException: Failed to read key MyAndroidKey from store "I:\Users\Ray\keystores\android.jks": Keystore was tampered with, or password was incorrect
        at com.android.ide.common.signing.KeystoreHelper.getCertificateInfo(KeystoreHelper.java:212)
        at com.android.builder.core.AndroidBuilder.packageCodeSplitApk(AndroidBuilder.java:1393)
        at com.android.build.gradle.internal.transforms.InstantRunSplitApkBuilder.generateSplitApk(InstantRunSplitApkBuilder.java:174)
        at com.android.build.gradle.internal.transforms.InstantRunDependenciesApkBuilder.transform(InstantRunDependenciesApkBuilder.java:139)
        at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:222)
        at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:218)
        at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
        at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:213)
        at sun.reflect.GeneratedMethodAccessor180.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:173)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
        at java.lang.Thread.run(Thread.java:745)
    Caused by: java.io.IOException: Keystore was tampered with, or password was incorrect
        at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:780)
        at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:56)
        at sun.security.provider.KeyStoreDelegator.engineLoad(KeyStoreDelegator.java:224)
        at sun.security.provider.JavaKeyStore$DualFormatJKS.engineLoad(JavaKeyStore.java:70)
        at java.security.KeyStore.load(KeyStore.java:1445)
        at com.android.ide.common.signing.KeystoreHelper.getCertificateInfo(KeystoreHelper.java:190)
        ... 51 more
    Caused by: java.security.UnrecoverableKeyException: Password verification failed
        at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:778)
        ... 56 more
    
     FAILED
    :app:buildInfoGeneratorDebug
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':app:transformDexWithInstantRunDependenciesApkForDebug'.
    > com.android.build.api.transform.TransformException: com.android.ide.common.signing.KeytoolException: Failed to read key MyAndroidKey from store "I:\Users\Ray\keystores\android.jks": Keystore was tampered with, or password was incorrect
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    
    * Get more help at https://help.gradle.org
    
    BUILD FAILED in 11s
    
    39 actionable tasks: 11 executed, 28 up-to-date
    
  • h.martin
    h.martin over 5 years
    thanks for pointing this out ... was going mad, thought i had lost my password ... il also had to delete ~/.gradle/caches/*
  • Florian
    Florian over 5 years
    Thanks so much! I updated my app to target the latest Android version and due to that I had to also update a lot of libraries and make changes to my code. After all that I was also unable to create a signed apk through Android Studio until I deleted my gradle and build folders.
  • d4c0d312
    d4c0d312 over 5 years
    @Florian No problem, glad to help
  • Sterling
    Sterling about 5 years
    Thanks for the lead! Not wanting to lose quite so much of my project's metadata, I tried just closing Android studio and deleting the .gradle directory (which is where I think it caches a lot of stuff) - and that worked.
  • Sahdeep Singh
    Sahdeep Singh about 5 years
    @String you are right, deleting only .gradle works, but does anyone knows why i have to delete it every time while generating the the signed apk?
  • arkascha
    arkascha about 3 years
    That is not really the idea behind a release key, is it?
  • CoolMind
    CoolMind about 3 years
    @arkascha, agree with you.