React Native: "Failed to read key from keystore" when trying to generate apk file
Asked Answered
S

1

6

When I try to follow the docs in https://facebook.github.io/react-native/docs/signed-apk-android.html to generate the apk file for a react-native app,I got the error described in the title above. I have already checked to make sure that the alias and password of my keystore are correct, so I'm not sure what the problem is. I have also made sure that I entered all the information required when generating the keystore.

Below is the stacktrace of the output I get from running the command gradlew assembleRelease inside the android directory.

:app:packageRelease (Thread[main,5,main]) started.
:app:packageRelease
Executing task ':app:packageRelease' (up-to-date check took 0.092 secs) due to:
  No history is available.
All input files are considered out-of-date for incremental task ':app:packageRel
ease'.
:app:packageRelease FAILED
:app:packageRelease (Thread[main,5,main]) completed. Took 0.151 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:packageRelease'.
> Failed to read key from keystore

* Try:
Run with --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:pac
kageRelease'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteActions(ExecuteActionsTaskExecuter.java:69)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecute(ExecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExec
uter.execute(PostExecutionAnalysisTaskExecuter.java:35)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.exec
ute(SkipUpToDateTaskExecuter.java:64)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execut
e(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecu
ter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter
.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execut
e(SkipOnlyIfTaskExecuter.java:53)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter
.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailur
e(AbstractTask.java:310)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorW
orker.executeTask(AbstractTaskPlanExecutor.java:79)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorW
orker.processTask(AbstractTaskPlanExecutor.java:63)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorW
orker.run(AbstractTaskPlanExecutor.java:51)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(Defaul
tTaskPlanExecutor.java:23)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(Defau
ltTaskGraphExecuter.java:88)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTask
ExecutionAction.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
r.java:62)
        at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExec
uter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecu
ter.java:68)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildEx
ecutionAction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
r.java:62)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
r.java:55)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(Default
GradleLauncher.java:149)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradle
Launcher.java:106)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLaun
cher.java:86)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildCon
troller.run(InProcessBuildActionExecuter.java:90)
        at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(Exe
cuteBuildActionRunner.java:28)
        at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildA
ctionRunner.java:35)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce
ssBuildActionExecuter.java:41)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce
ssBuildActionExecuter.java:28)
        at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.exe
cute(DaemonUsageSuggestingBuildActionExecuter.java:50)
        at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.exe
cute(DaemonUsageSuggestingBuildActionExecuter.java:27)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:40)
        at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.jav
a:169)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
execute(CommandLineActionFactory.java:237)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
execute(CommandLineActionFactory.java:210)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRunti
meValidationAction.java:35)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRunti
meValidationAction.java:24)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
CommandLineActionFactory.java:206)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
CommandLineActionFactory.java:169)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
ortingAction.java:33)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
ortingAction.java:22)
        at org.gradle.launcher.Main.doAction(Main.java:33)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBoots
trap.java:54)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.j
ava:35)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
        at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.ja
va:30)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:127)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
Caused by: org.gradle.tooling.BuildException: Failed to read key from keystore
        at com.android.build.gradle.tasks.PackageApplication.doFullTaskAction(Pa
ckageApplication.java:226)
        at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(In
crementalTask.java:79)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF
actory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:243)

        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF
actory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:219)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF
actory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:230)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF
actory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:208)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteAction(ExecuteActionsTaskExecuter.java:80)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteActions(ExecuteActionsTaskExecuter.java:61)
        ... 49 more
Caused by: com.android.builder.packaging.SigningException: Failed to read key fr
om keystore
        at com.android.builder.core.AndroidBuilder.packageApk(AndroidBuilder.jav
a:1775)
        at com.android.build.gradle.tasks.PackageApplication.doFullTaskAction(Pa
ckageApplication.java:206)
        ... 57 more


BUILD FAILED

I can't make sense of the stacktrace.

Part of my build.gradle file in my android/app folder is shown below:

signingConfigs {
            release {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }

while the gradle.properties file in my android folder is shown below:

android.useDeprecatedNdk=true
MYAPP_RELEASE_STORE_FILE=my-key.keystore
MYAPP_RELEASE_KEY_ALIAS=lew                 
MYAPP_RELEASE_STORE_PASSWORD= ****
MYAPP_RELEASE_KEY_PASSWORD= ****
Saleswoman answered 31/7, 2016 at 10:1 Comment(3)
Where did you put your .keystore file?Steadfast
My keystore file is in the android/app directory of my project folderSaleswoman
Have you found a solution to thisLinlithgow
M
0

Run:

keytool -list -keystore my-key.keystore

and check if ALIAS is lew.

Melendez answered 3/2, 2017 at 15:32 Comment(1)
Keystore file does not exist: my-key.keystore , and when i run this keytool -genkey -v -keystore mykeystore.keystore -alias mykeyalias -keyalg RSA -keysize 2048 -validity 10000 after your command i got Key pair not generated, alias <mykeyalias> already existsWhitfield

© 2022 - 2024 — McMap. All rights reserved.