Page 1 of 3

How to sign a release APK

Posted: Sun Nov 06, 2016 1:06 am
by e2robot
Not sure if anyone else has this strange issue.

Unless I include the debugger when creating APK, I get an APK corrupt error when installing to Nexus 5X running 7.0

Same happened with Beta 2.

regards,
Phil

Re: SB 2.00 Beta 4 - APK corrupt unless debugger enabled

Posted: Sun Nov 06, 2016 5:59 am
by Fred
It's because you need to sign the apk when compiling in release mode. Step to do it on Windows:

1) Open a command prompt

2) Ensures your JDK\bin directory is in the PATH (mine is here C:\Program Files\Java\jdk1.8.0_73\bin)

3) Create a new certificate with 'keytool' (which is in JDK\bin) (only required the first time)

Code: Select all

keytool -genkey -v -keystore my-release-key.keystore -keyalg RSA -keysize 2048 -validity 10000 -alias app
4) Sign your apk with 'jarsigner' (which is in JDK\bin)

Code: Select all

jarsigner -verbose -tsa http://timestamp.digicert.com -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore yourpackage.apk alias_name -storepass yourkeystorepassword
5) Align the resulting zip with 'zipalign' (can be found in SpiderBasic\Android\android\sdk\build-tools\23.0.2)

Code: Select all

zipalign 4 yourpackage.apk yourpackage_signed.apk
Now your APK is ready to be installed, and you can even submit it to the google appstore (tested it and it work :), french users can search for 'SpiderTest' app on GooglePlay it should appear)

Re: SB 2.00 Beta 4 - APK corrupt unless debugger enabled

Posted: Sun Nov 06, 2016 7:54 am
by e2robot
Thanks for the detailed instructions !

Working fine now.

Just in case anyone misses it. The alias_name in the jarsigner step is the alias you specified in keytool step. In this case it's app

Regards,
Phil

Re: How to sign a release APK

Posted: Sun Nov 06, 2016 7:59 am
by Fred
Great ! I changed the title and moved to trick and tips so everyone could find this info easily

Re: How to sign a release APK

Posted: Mon Nov 21, 2016 11:04 am
by Leonhardt
mark

Re: How to sign a release APK

Posted: Wed Dec 07, 2016 2:10 pm
by Rings
should such a tip not been included in the IDE an been automated ?

Re: How to sign a release APK

Posted: Sat Dec 10, 2016 11:25 pm
by falsam
Hello Fred.

Signing an APK is only to be able to publish on the store.

I would like to be able to transfer my apk to my terminal without going through the store.

The unknown source checkbox is checked on my terminal but the APK do not install.

If I install a signed APK, I can not upgrade with a new version.

Installing the application in debug mode (unsigned) would be very good but I would like the window debug not to be opened systematically.

Thanks.

Re: How to sign a release APK

Posted: Sun Dec 11, 2016 7:33 am
by Fred
You can use CloseDebugOutput() if you want to close it at start while being in debug mode. To reinstall a signed package, you need to uninstall it first, for all users (easier with adb)

Re: How to sign a release APK

Posted: Sun Dec 11, 2016 9:44 am
by Bradan
If you sign it with the same certificate every time it should work. Only if you switch between release and debug certificates it will ask you to uninstall it first. At least thats how it is when developing android apps with the sdk. Usually ALL apks are signed, even the debug builds. However the IDE usually creates a debug certificate which expires once every year or so.

Re: How to sign a release APK

Posted: Sun Dec 11, 2016 2:53 pm
by tj1010
Disable trusted source under settings>security on your test device.. I use Bluetooth sometimes with unsigned.. Enable it when done. It's trivial to make a PB program using RunProgram and directory scan for auto-find to do this if you want it signed, but yeah integrated should be there since SB already needs the JDK path anyway. Just store a key per-install?

I forget all the model for apk signing but I think Google has to sign with their private key on the back-end of the store for an apk to install on a device without debug. They check them with their public key stored on all phones. I may be wrong partly I learned this years ago and forgot some of it.