Signing Android App in Xamarin

Achindra Bhatnagar
Achindra
Published in
2 min readJul 12, 2018

Just got my code signing cert from Digicert and I thought of signing my Android app to publish on Playstore, but there was this weird error

jarsigner error: java.security.SignatureException: private key algorithm is not compatible with signature algorithm

I tried command line and Xamarin Archive Manager but it continued to throw this error (and similar). Finally, I was able to make it. Here’s what I did -

First, switch to release mode, right click on Android project in Xamarin and select Archive…

This brings you to Archive Manager, which is also accessible from Tools menu. It takes a little while to generate an app archive. This will create an APK for you, ready to sign and distribute.

Create a KeyStore from P12

Android app signing uses Java Key Store. KeyStore is a repository of certs and keys. JDK has a tool — KeyTool where you can create a KeyStore and import your Cert

KeyStore

keytool -genkey -alias Gigabits -keystore GigabitsKeyStore.jks -keysize 1024 -validity 14000

Be sure to provide a keySize of 1024.

This Java Bug explains how this value reverts behavior of ‘keytool’ and ‘jarsigner’ to use SHA1withDSA.

Import

keytool -v -importkeystore -srckeystore MyCert.p12 -srcstoretype PKCS12 -destkeystore MyCertKeyStore.jks -deststoretype JKS

Migrate to industry standard PKCS12

keytool -importkeystore -srckeystore MyCertKeyStore.jks -destkeystore MyCertKeyStore.jks -deststoretype pkcs12

ZipAlign

ZipAlign does some optimizations on the APK, kind of repackaging. It is a mandatory process.

zipalign.exe -f -v 4 com.My.App.apk com.My.App_aligned.apk

Sign in Archive Manager

I ditched jarsigner since it continued to complaint. Select Distribute > AdHoc in Archive Manager and add this keystore. “Save As” should now sign the app for you.

ActivityManager

--

--