alextk
alextk

Reputation: 6239

Cordova hook to change the app name for iOS and Android

I could not manage to have a space in the app name when generating the iOS target. Overriding the app name in the manifest (android) and in resources (ios) was fine, but changes are lost as soon as I rebuild the app (as it copies again the app name from config.xml).

I was thinking of creating a hook for that. Such hook would put the proper app name value for ios and android. Are there any sample hook that does such thing and is "before_compile" the proper timing for that?

Upvotes: 4

Views: 4278

Answers (3)

blakgeek
blakgeek

Reputation: 419

I created a hook to do exactly this. You can take a look at the github repo.

The plugin takes the display name as a variable when you add it and then updates the iOS plist on install and adds an after_prepare hook that sets app_name for Android so you don't run into the issue of your change being overwritten.

cordova plugin add cordova-plugin-app-name --variable APP_NAME="My Super Cool App" --save

Upvotes: 7

alextk
alextk

Reputation: 6239

To answer my own question I was able for Android to create a script (that I created in dart as I am more comfortable with) using the after_prepare hook that simply modify the string "app_name" in platforms/android/res/values/strings.xml. Calling cordova prepare android properly fix the app name.

For iOS i changed the name in XCode (in xxxx-Info.plist, Bundle Display Name) and it seems that calling again cordova prepare ios does not override it

Upvotes: 0

njtman
njtman

Reputation: 2170

I've noticed Cordova project names usually don't play nice when there are any spaces or special characters in the names. I usually just have a simple project name, then override the app's display names inside the native projects.

I build my apps from the command line, as my build process is wired through jenkins.

I'm not so sure about native Cordova hooks, but on iOS, you just need to modify the "App Name". You can do this by going to this file here

CORDOVA_PROJECT_DIRECTORY/platforms/ios/cordova/build.xcconfig

and adding the following line to the end of the file.

PRODUCT_NAME = My Crazy App Name With Spaces And Character !?

Now when you run the

cordova compile ios --release

the app will display the PRODUCT_NAME specified above, instead of the cordova project's name.

Android is a bit more complicated which requires modification of a couple of xml files.

I will update this answer in a little bit with the android solution.

Upvotes: 0

Related Questions