Simon Ang
Simon Ang

Reputation: 113

Changing the package name

I planned to change the package name through smali(reverse)

when I open up apktool.yml, I saw this

forced-package-id: '127'

I have tried to change it but it crash why should i do?

Upvotes: 9

Views: 43559

Answers (3)

I've tried different approaches but the most reliable for me has been the method described here:

https://forum.xda-developers.com/t/how-to-guide-mod-change-package-names-of-apks.2760965/

These are the steps:

  1. Decode APK (using apktool)
  2. Edit apktool.yml
  3. Edit AndroidManifest.xml
  4. Rename smali subfolders
  5. Search & Replace *.smali (using Notepad++)
  6. Build APK (using apktool)
  7. Sign APK (using apksigner)

Tools needed:

Download apktool and wrapper script to C:\apktool.

Let's assume you want to modify from/to as specified here:

From: XVipreSettings.apk (Package name: com.xvipre.settings)

To: ModdedApp.apk (Package name: com.modded.app)

1. Decode APK (using apktool)

apktool.bat d XVipreSettings.apk

2. Edit apktool.yml

apkFileName: XVipreSettings.apk
...
renameManifestPackage: null

is changed to:

apkFileName: ModdedApp.apk
...
renameManifestPackage: 'com.modded.app'

3. Edit AndroidManifest.xml

package="com.xvipre.settings"

is changed to:

package="com.modded.app"

4. Rename smali subfolders

move .\XVipreSettings\smali\com\xvipre\settings .\XVipreSettings\smali\com\xvipre\app
move .\XVipreSettings\smali\com\xvipre .\XVipreSettings\smali\com\modded

5. Search & Replace *.smali

  • Start Notepad++
  • Menu > Search > Find in Files... (Ctrl+Shift+F)
  • Find what : "Lcom/xvipre/settings"
  • Replace with : "Lcom/modded/app"
  • Filters : "*.smali"
  • Directory : "C:\apktool\XVipreSettings\smali\com"
  • Press Replace in Files (may take a few minutes)

6. Build APK

apktool.bat b XVipreSettings -o ModdedApp.apk

7. Sign APK

(I'm assuming 31.0.0 here yours may be different, also if you don't want to sign using debug certificate you need to modify this step accordingly)

%homedrive%%homepath%\AppData\Local\Android\Sdk\build-tools\31.0.0\apksigner.bat sign --ks %homedrive%%homepath%\.android\debug.keystore --ks-pass pass:android --key-pass pass:android C:\apktool\ModdedApp.apk

Upvotes: 0

JesusFreke
JesusFreke

Reputation: 20282

Assuming your goal is to rename the package name of the apk, the package names used for the classes are irrelevant. The package name of the apk is mostly unrelated to the package names of any classes in the apk. And there's no reason you need to touch the package id.

I would recommend unpacking the apk with apktool, and then edit the apktool.yml, setting renameManifestPackage to the new package name. Then when you rebuild the apk with apktool, it should use aapt's --rename-manifest-package functionality to change the package name.

After that, just resign the new apk and you should be good to go.

apktool d app.apk
// change "renameManifestPackage: null" in app/apktool.yml
// to "renameManifestPackage: my.new.package"
apktool b app -o new_app.apk
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ~/my.keystore new_app.apk mykeyname

And just to reiterate, you don't need to modify the package names of any classes.

Upvotes: 38

Luca D'Amico
Luca D'Amico

Reputation: 3222

To my knowledge there are no fast ways to change the package name. You have to change the package="com.mycompany.myapp" in Manifest.xml and then manually replace all the package name occurrences in smali files (and folders). Finally edit apktool.yml replacing the old package name, with your new package name.

A full detailed tutorial can be found here: http://forum.xda-developers.com/showthread.php?t=2760965

Upvotes: 5

Related Questions