Android Tutorial Tutorial - How to sign apk with non-B4A keystore

Discussion in 'Tutorials & Examples' started by JonPM, Jan 15, 2012.

  1. JonPM

    JonPM Well-Known Member Licensed User

    Here is my first tutorial for the community!

    This tutorial will show you how to sign a B4A generated apk with a non-B4A keystore. I needed a way to do this for myself since I had some apps out created using AppInventor that I remade using B4A. On to the tut:

    1. When you are ready to publish, You need to use B4ABuilder to compile an unsigned apk.
    "C:\Program Files (x86)\Anywhere Software\Basic4Android\B4ABuilder.exe" -Task=Build -NoSign=True -Obfuscate=true
    2. Go to \Main\Objects\bin and find the file called "temp.ap_". This is your app. Rename this file accordingly (i.e. "myapp.apk").
    3. Copy your keystore file to the same directory as myapp.apk.
    4. To make life easier, navigate to your android sdk folder and copy this file: \android-sdk\tools\zipalign.exe to the same folder as your apk and keystore.
    5. Open Windows Command Prompt. Navigate to the folder where myapp.apk, keystore, and zipalign are
    6. In Command Prompt type: jarsigner -verbose -keystore mykeystore.ks myapp.apk username
    Change "mykeystore.ks" to your keystore's file name. Change "myapp.apk" to your app's file name. Change "username" to the username used in your keystore.
    7. Enter your password when asked.
    8. When it's finished, type this: zipalign -v 4 myapp.apk myapp_aligned.apk
    9. You're done! myapp_aligned.apk is the file you'll need to upload to the market
     
    Last edited: Feb 22, 2016
    An Schi likes this.
  2. walterf25

    walterf25 Well-Known Member Licensed User

    Signing apps without b4A keystore

    Hi all, JonPM's tutorial is great, but there's an easier way to do it without having to go into a command prompt, just download the apptomarket located here
    M. Hossein Amerkashi's Blog | My Blog Site
    install this app on your desktop, once you've done this and you are ready to sign your app, in b4a under project menu, choose compile (without signing), this creates the temp.ap_ file under Object\bin folders, rename that file to the name of your app, (myapp.apk) copy that renamed file and paste it into the myapks folder inside the apptomarket folder, launch apptomarket app, and now you are ready to use your already created keystore, if you do't have one you can create one, this app is very easy to use, you can follow the tutorial video in the link provided above, good luck!

    :sign0089:
    Walter
     
  3. JonPM

    JonPM Well-Known Member Licensed User

    Hey walter, I used to use AppToMarket before when I used AI. However, I don't really like relying on a separate app to sign mine. If all else fails, the method I posted above will work 100% of the time.
     
  4. kingapps

    kingapps Member Licensed User

    nice tutorial

    ill try this once i finished working with sample program for b4a
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    You only need to use this technique if you have an existing app in the market not developed with Basic4android.
     
  6. airblaster

    airblaster Active Member Licensed User

    Just wondering, could this be automated using the new CustomBuildAction feature?
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    There is a simpler solution, however why do you need to sign your app with a key not created with Basic4android?
     
  8. airblaster

    airblaster Active Member Licensed User

    Because I want to upgrade a non-B4A App with many installations to an B4A App.
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Follow these steps:
    - Close the IDE
    - Go to: C:\Users\<user name>\AppData\Roaming\Anywhere Software\Basic4android
    - Open the INI file
    - Change the keystore alias (SignKeyAlias property)
     
    Foz and ArminKH like this.
  10. airblaster

    airblaster Active Member Licensed User

    Thank you for the tutorial!
    This helps a lot!
     
  11. airblaster

    airblaster Active Member Licensed User

  12. Erel

    Erel Administrator Staff Member Licensed User

    The key must be signed with SHA1withDSA algorithm. Otherwise you will need to use a batch file as described in the first post.
     
  13. airblaster

    airblaster Active Member Licensed User

    Seems like I have to go the batch way then.
    I'll try automating it a bit more with custombuildaction.
     
  14. cthomas4579

    cthomas4579 Member Licensed User

    App Did Not Install

    I used this method to pull together my .apk file but ran into a problem. Everything above seemed to work just fine. And prior to using this I was able to compile and run my app on my phone using the bridge. Worked great! When I attempt to side load my .apk file - (Send to my phone attached in email with developer mode on and attempt to install) It says "App did not install" Its a VERY basic app. I'm a beginner, simple app that creates an email subject, body and to, calls the email program up and fills in.

    I created my temp.ap_ file using Release (not debug)
    and again, through the bridge the app installs and runs perfectly.

    Just wanna get this together so I could send the .apk to another phone and install without hickup..

    Side note - I have checked the setting to allow install of apps from unknown sources

    One more side note - Does anybody know how to get rid of the B4A Example Name that appears on my app? I changed Application Label in Project attributes thinking that would solve it but hasn't. This is my first app in this software
     
    Last edited: Mar 28, 2013
  15. Erel

    Erel Administrator Staff Member Licensed User

    Why did you need to use a non B4A sign key?

    About B4A-Bridge. You need to first uninstall the current app from your device.

    Changing application label will change the name. Unless you checked Project - Do not overwrite manifest file.
     
  16. ondesic

    ondesic Active Member Licensed User

    I thought this was fixed with 2.52. I thought I read in the release notes that you could now input an alias.
     
    Last edited: May 10, 2013
  17. siddsg

    siddsg Member Licensed User

    Hi Jon,
    I followed the steps you mentioned, however at the command prompt, on giving the jarsignor command, am getting an error "'jarsigner' is not recognized as operable program or batch file."

    What else needs to be done?
     
  18. Erel

    Erel Administrator Staff Member Licensed User

    Have you tried the suggestion in post #9?
     
  19. ttsolution

    ttsolution Member Licensed User

    Dear all,

    I'm trying to build apk guided by the Tutorial (in the top). But I wonder about the username

    6. In Command Prompt type: jarsigner -verbose -keystore mykeystore.ks myapp.apk username
    Change "mykeystore.ks" to your keystore's file name. Change "myapp.apk" to your app's file name. Change "username" to the username used in your keystore.

    But when I Create keystore file with Private Sign Key there is no textbox to put username, just 04 textbox below

    1. First and last name
    2. Organization
    3. Country
    4. Password

    Where can i find the username

    Many thanks for your help

    Jonh,
     
  20. MaFu

    MaFu Well-Known Member Licensed User

    If you create a keystore with Basic4android, the username (= alias name) is always "b4a".
    You can change it in the ini file found at C:\Users\<username>\AppData\Roaming\Anywhere Software\Basic4android
     
    DavideV likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice