Reputation: 51658
I have an old Android Cordova app whose manifest has <activity android:name=".MyActivity"
. This has already been published to the Play store, so I can no longer change the name.
I'm trying to migrate to the Cordova CLI workflow, but the Android app it generates has android:name="MainActivity"
. How can I customize this in config.xml, so it generates the right name?
I found an undocumented preference "android-activityName". I tried setting this to ".MyActivity", and removing/adding the android platform. But with this setting, it no longer created the activity class at all, and I got an error "Error: No Java files found which extend CordovaActivity".
Upvotes: 1
Views: 4946
Reputation: 51658
I've dealt with this using the cordova-custom-config plugin, adding this to my config.xml:
<custom-preference name="android-manifest/application/activity/@android:name" value=".MyActivity" />
Upvotes: 1
Reputation: 572
I had a similar problem and this was my solution in bash. I had the wrong Activity name and the wrong java file name, so I needed to change both.
I created the following bash
function:
First I replace all MainActivity
references with NewActivityName
.
Then I look for the java file and rename it.
function rename_the_activity {
platformDir="/path/to/platformdir"
grep -rl 'MainActivity' $platformDir | sort | uniq | xargs perl -e "s/MainActivity/NewActivityName/" -pi
activity=$(find $platformDir -name 'MainActivity.java')
newactivity="${activity/MainActivity/NewActivityName}"
mv $activity $newactivity
print_blue "Renamed activity class MainActivity to NewActivityName"
}
Upvotes: 0
Reputation: 2060
Recently I also faced a similar situation.What I did was I changed the id of the widget tag inside config.xml to reflect the package name where I put my MyActivity class which extends CordovaActivity.Make sure you have deleted the unwanted MainActivity class that cordova generates(if you are putting your MyActivity class in the same package as MainActivity class).And also your MyActivity class should be extending CordovaActivity (important).Then open config.xml and change the widget tag as given below.
//Change the id value to the package name where you put your MyActivity class
<widget id="com.yourCompanyName.yourPackageName" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
After doing this clean the project using cordova clean command and then rebuild the project.Additionally you can use android-packageName property to widget tag to give android specific package name and ios-CFBundleIdentifier for ios specific name.
Upvotes: 0