Search This Blog

Thursday 24 September 2015

create ionic app with appname and id

we create ionic app just by saying:
ionic start YourAppName blank

if you create app this way, problem will come after building ios/android app.
you need to edit config.xml . if you want to give app name and bundle id while creating project itself use the below command.

ionic start YourAppName blank --appname YourApp --id com.yourcomapny.yourapp

Wednesday 23 September 2015

Signing and Generating .apk for Ionic apps

ionic build android will give you an unsigned apk file. unsigned apk is not accepted in play store. so you need to sign and make .apk to release to play store.

Building Ionic Android app:
ionic build --release android
This will generate a release build based on the settings in your config.xml. Your Ionic app will have preset default values in this file, but if you need to customize how your app is built, you can edit this file to fit your preferences. Check out the config.xml file documentation for more information.
Now, we can find out unsigned apk in \platforms\android\ant-build\MainActivity-release-unsigned.apk
app name "MainActivity" looks ugly. to change the app name follow the steps below:
You will need to update the following files:
  1. YourProjectName/platforms/android/AndroidManifest.xml
  2. YourProjectName/platforms/android/build.xml
  3. YourProjectName/platforms/android/src/com/yourpackagename/appfolder/MainActivity.java
STEP 1
Got to the AndroidManifest.xml file and look for:
<activity android:configchanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchmode="singleTop" android:name="MainActivity" android:screenorientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowsoftinputmode="adjustResize">
change MainActivity to whatever name you want. ex:ItsMyCodeShare
STEP 2: In the build.xml file locate the following line:
<project name="MainActivity" default="help">
Change MainActivity to the name of your project and should match the one in put in step 1 (i.e  name="ItsMyCodeShare").
STEP 3 This stage is abit more tricky and extra caution should be taken when doing this, or else you  might mess things up big time...and that is not Awesome!!
  • Locate the file MainActivity.java and rename it to project name (Same as step 1 and 2...i.e ItsMyCodeShare.java).
  • Open the renamed file and locate the line : public class MainActivity extends CordovaActivity change it to the project name like: public class ItsMyCodeShare extends CordovaActivity
Sorry to disappoint you but.....That's it!!!
Run the command : ionic build android --release
more so, we are ready with our desired name.apk file.
Lets start signing it now.
1) Generate Private key
2) Sign the apk
3) zip the apk
For the above steps you will be using keytool, jarsigner and zipalign tools respectively.
1)keytool will be available in "C:\Program Files\Java\jre7\bin"
2)jarsigner will be available in "C:\Program Files\Java\jdk1.7.0_79\bin"
3)zipalign will be available in "C:\Users\e571224\AppData\Local\Android\sdk\build-tools\22.0.1"
Note:build-tools version(22.0.1) might vary depending on your installed version.
Step 1:
 we need to generate a private key using keytool of JDK.
open your command prompt and enter keytool. if it is not recognized add your jre/bin to Path environment variable.
Then, use the following command to generate the private key
keytool -genkey -v -keystore yourapp-release-key.keystore -alias app_alias_name -keyalg RSA -keysize 2048 -validity 10000
yourapp-release-key.keystore is now generated in that folder. copy and keep it safe.
It will ask for a password, followed by some security questions. remember the password.(take a screenshot to be on safer side)
Step 2:
we need to sign our unsigned apk with the above private key.
copy the private key (yourapp-release-key.keystore, generated in above step) into the folder in which your apk is present. Also, make sure to add the jdk/bin to Path environment variable.
now, run the below command to sign it.
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore yourapp-release-key.keystore yourapp-release-unsigned.apk app_alias_name
enter the password and your apk is signed now. 
Step 3:
we use the zipalign tool to generate the apk. zipalign is available in build-tools/yourversion. add that path to your environment variables.
Now, run the below command to generate the apk:
zipalign -v 4 yourapp-release-unsigned.apk ItsMyCodeShare.apk
this will generate the apk file which you can ship to play store.
References:
http://ionicframework.com/docs/guide/publishing.html
http://forum.ionicframework.com/t/renaming-android-build-apk-from-cordovaapp-to-your-app-name/15416