Publishing an App Inventor app in Android Market

I found two good resources to help with getting Agile's apps (Volume*, etc) into the Market, but somehow neither one seemed perfect or complete, probably because of my own dim-wittedness and my idiosyncratic system. So here's the workflow I use on my Mac, all in the Terminal:

1 Download the application APK from App Inventor
Make sure the APK file has the name you will use for ever more. You will have to use this name for all future versions of the app. Keep it simple.

Then open the terminal and navigate to the directory you have the APK file in, for example: cd AppInv/Yourapp

2 Decompile the APK
Use apktool. You may need to install it first from Google. Then: apktool d -s yourapp.apk

3 Edit what you want
Usually you need to at least add the following lines to the AndroidManifest.xml file, right after xmlns:android="http://schemas.android.com/apk/res/android" ; make sure the lines are inside the angle brackets.

android:versionCode = "1" android:versionName = "1.0"

VersionCode must increase by one for each release. VersionName can be anything you like. For more on editing the manifest, see this page.

4 Compile the package again
I move the original file first because I'm not sure when the file is allowed to have a different name and when it's not. For some reason, I have to run this command as SU, so I need to enter my root password when prompted.

mv yourapp.apk yourapp.apk.initial sudo apktool b yourapp yourapp.apk

5 Sign the APK using your own keystore
The utility jarsigner comes with the JDK. jarsigner -verbose -keystore mykey.keystore yourapp.apk alias

6 Verify if the APK is correctly signed
jarsigner -verify -verbose -certs yourapp.apk

7 Align the APK
Use zipalign, which is in the Android SDK Tools folder. zipalign -v 4 yourapp.apk yourapp.apk.za mv yourapp.apk yourapp.apk.unaligned mv yourapp.apk.za yourapp.apk

8 Publish to the Android Market
You're done! Upload this new APK file to Android Market.