The above mentioned solution does not work if you want to install the new application side by side with the old.
Suppose you have an oldapk.apk and you want to rename its package from com.oldcompany.oldname to com.mycompany.myname and install the newapk.apk side by side with the oldapk.apk, follow these steps:
Install apktoolgui: https://github.com/AndnixSH/APKToolGUI
Install ruplacer: https://github.com/dmerejkowsky/ruplacer
Decompile apk using apktoolgui
Edit oldapk/apktool.yml:
- renameManifestPackage: null
+ renameManifestPackage: com.mycompany.myname
Replace old names to new:
ruplacer "Lcom/oldcompany/oldname" "Lcom/mycompany/myname"
ruplacer "com\.oldcompany\.oldname" "com.mycompany.myname"
Run ruplacer afterwards again with option --go (first run was only reporting)
Rename folders smali(...)/com/oldcompany/oldname to smali/com/mycompany/myname
Compile newapk.apk (including align/sign) using apktoolgui