Renaming Android build .apk from CordovaApp to your App name

There seems to be a small quirk with Cordova 3.6.4. The .apk generated using the CLI is always named CordovaApp as opposed to the name of you project.

This tutorial helps fix that issue by integrating the renaming into your workflow.

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/CordovaApp.java

NOTE: From the above (file 3), com/yourpackagename/appfolder will correspond to the reverse domain name you used when when set up your application.

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="CordovaApp" android:screenorientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowsoftinputmode="adjustResize">

Change CordovaApp in android:name=“CordovaApp” to whatever the name of your project is
(android:name=“AwesomeKickAssApp”).

STEP 2:
In the build.xml file locate the following line:

<project name="CordovaApp" default="help">

Change CordovaApp to the name of your project and should match the one in put in step 1 (i.e
name=“AwesomeKickAssApp”).

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 Cordova.java and rename it to project name (Same as
    step 1 and 2…i.e AwesomeKickAssApp.java).

  • Open the renamed file and locate the line :
    public class CordovaApp extends CordovaActivity change it to the project name like:
    public class AwesomeKickAssApp extends CordovaActivity

Sorry to disappoint you but…That’s it!!!

Run the command : ionic build android --release

This should result in:

BUILD SUCCESSFUL
Total time: 8 seconds
Built the following apk(s):
    /Path-to-your-project/platforms/android/ant-build/AwesomeKickAssApp-release-unsigned.apk

I hope this saves someone else’s hair, as i pulled out a lot of mine trying to figure this one out. :slight_smile:

Refrences:

Stack Overflow Issue
JetBrains confluence page
Saints at play

9 Likes

This works for me, Thanks.

Works great! Thanks for publishing this fix

It works great :smile: :smile:

I’m new to Ionic and having the same problem. The files you mentioned, aren’t they created automatically during the build process? So they will be overwritten everytime I build the application.

I had this problem and this fixed worked perfect. I can run the build command multiple times and it doesn’t overwrite these files. I think the files are generated only when you “ionic platform add android”

platforms is generated, there should be a way to do it on config.xml…

2 Likes

It looks like an attribute was added to allow this, but I can’t get it to work:

You should be able to add an attribute to the root in config.xml like so:

<widget ... android-activityName="MyName" ... >

Doesn’t seem to work for me …

@zeronil nice, was it released in which cordova version?

tried here with 4.3.0 and also didn’t work

didn’t work for me either. tried with cordova 4.2.0 and 4.3.0. the only difference is the tag android:name=“MainActivity”, in cordova 4.2.0 this was android:name=“CordovaApp”

@puzste Additionally change in the following files as well.

  1. YourProjectName\platforms\android\res\values\strings.xml
  2. YourProjectName\platforms\android\xml\config.xml

That solved it for me

1 Like

@ZimNerd I don’t want to change files in platforms folder because they are generated and not checked in in our version control. is there any other way?

@puzste Use a hook “after_build” and instead of renaming it, make a copy. Make sure in your hook you handle iOS, Android with and without crosswalk.

@puzste were u able to solve this without changing from platforms? also i cant find build.xml in my platforms directory.

@boyfunky: No I wasn’t …did you found a solution?

Hi,

Does this works for latest version of Cordova 5.* ?

Halo @sreedharbukya,

I had this problem before, i change package name from config.xml and i got error when i build it.
But i fixed it with this:

  1. change package name inside config.xml
  2. open cmd and do this:
    cordova platform rm android
    cordova platform add android
    cordova build --release android

So yeah, i have to remove android platform first, so AndroidManifest.xml and all data inside platforms/android/src/… can be built based on config.xml. All this data generates from the first build, you can build it again but only with the same package name, so when you change the package name, you have to build it again from the beginning, i hope this can help.