Renaming Android build .apk from CordovaApp to your App name


#1

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


Android build keeps using CordovaApp as app name
Android build keeps using CordovaApp as app name
Android build keeps using CordovaApp as app name
#2

This works for me, Thanks.


#3

Works great! Thanks for publishing this fix


#4

It works great :smile: :smile:


#5

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.


#6

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”


#7

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


#8

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 …


#9

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


#10

tried here with 4.3.0 and also didn’t work


#11

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”


#12

@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


#13

@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?


#14

@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.


#15

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


#16

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


#17

Hi,

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


#18

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.