Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
729 views
in Technique[技术] by (71.8m points)

android - Issues with signing APK with keystore.jks, built with ionic cordova

I build my app with the following line

ionic cordova build android --prod --release

This creates an 'app-release-unsigned.apk' file. I have a 'keystore.jks' file available and although everywhere I find people talking about .keystore files, I assume this is the file I need to sign it.

Following things I tried:

1. Build with a build.json file

ionic cordova build android --prod --release --BuildConfig=build.json

Json content:

{
  "android":
  {
    "release":
    {
      "keystore": "keystore.jks",
      "storePassword": "************", // Filled in password
      "password" : "************", // Filled in password
      "alias" : "**" // Also tried removing this line, didn't make any difference
    }
  }
}

Problem: There build was still unsigned. (I tried also solving this with option 2)

2. Sign apk with jarsigner command

I tried executing the following command at the root of my app, where the keystore file is placed as well.

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore keystore.jks platforms/android/app/build/release/apk/app-release-unsigned.apk bp

Problem: after this command, it asks for Enter Passphrase for keystore. I tried filling in my password and storepassword, but then I get the error jarsigner error: java.lang.RuntimeException: keystore load: Keystore was tampered with, or password was incorrect

I also tried running the jarsigner command with keypass and storepass as flags, but that also didn't work. I'm pretty sure my password is correct.

Lastly I see you could use Android Studio to build a generated APK. Only this option is not available to me in the Android Studio build menu. I'm using SDK Api level 28.

TL;DR: Can't build signed app, have no clue why.

question from:https://stackoverflow.com/questions/65844235/issues-with-signing-apk-with-keystore-jks-built-with-ionic-cordova

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Could you try build using command line and apksigner :

Download latest platform-tools/build-tools from Android Studio

File --> Settings --> Android SDK --> SDK Tools --> Download platform-tools

It will contain apksigner (be sure you have recent JDK at least > 11 to use it, or you'll have errors)

Then open terminal : cd Project/android

gradlew assembleRelease

cd androidappuildoutputsapk elease

Add your keystore.jks file here.

In this repository, do :

call zipalign -v -p 4 app-release-unsigned.apk app-release-unsigned-aligned.apk

And then :

call apksigner sign --ks keystore.jks --ks-pass pass:YOURPASSWORD --key-pass pass:YOURPASSWORD --out app-release-signed.apk app-release-unsigned-aligned.apk

Then you have your signed apk. I'm using this way to deliver my APK to clients.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...