How to rename the package name


How to successfully rename the package name of an App Inventor app

Note: Please see this solution by @Anke. Thank you Anke.

Note: According to Mr. Pratim, the process ddescribed below is outdated. The package name now can be changed by:

  1. Using apktool 2.1.1 decompile the apk, edit it and recompile it.
  2. Getting a pem certificate and pk8 key with OpenSSL.
  3. Signing the apk.

Mr. Pratim described this process in detail here. Thank you!

See also this guide by Avram. Thank you!

See also https://developer.android.com/studio/publish/app-signing.html#considerations:
If you plan to support upgrades for an app, ensure that your key has a validity period that exceeds the expected lifespan of that app. A validity period of 25 years or more is recommended. When your key's validity period expires, users will no longer be able to seamlessly upgrade to new versions of your app.

If you plan to publish your apps on Google Play, the key you use to sign those APKs must have a validity period ending after 22 October 2033. Google Play enforces this requirement to ensure that users can seamlessly upgrade apps when new versions are available

Thank you Boban!

Also, I had to zipalign the apk after signing it. Without zipalign the apk is rejected by the Play Store.
Thank you Martyn_HK!

I tried the steps of Mr. Patim in your page, and it did not work. That was because I had the latest java v.9 and it seems it is not compatible with my apktools v2.2.1. The solution was to install JDK v7 and execute these lines in the cmd.exe before beginning with the process:

        java -version
        set JAVA_HOME=C:\Program Files\jdk1.7.0_79
        set PATH=C:\Program Files\Java\jdk1.7.0_79\bin;%PATH%
        java -version
      

You should find that the first line will give you version 8 or 9, the last line should give you v7 Once you close cmd.exe the process should be repeated if you open cmd.exe again. This seems does not change the environment variables of Windows. It is only temporary for your cmd session (which is good, to not interfere with other programs that needs JDK9).
If you download the latest apktools (v2.3.1), then it will work with no problem with the latest JDK (v9). apktools can be downloaded from here..
Thank you Haider!


This tutorial is based on the work of Glassy. Thank you Glassy for the description and thank you DIYicious, for being the sponsor of this tutorial.

In the example I'm renaming the package name appinventor.ai_taifunbaer.manager to com.puravidaapps.manager. See also the package name conventions here. Which means, we also have to adjust the directory structure from appinventor/ai_taifunbaer/manager to com/puravidaapps/manager.

1. Preparation

  1. Download APK Studio Version 1.0.02.

    Unzip it and copy al files into a folder. I used the folder C:\Prog\apkstudio in the description below. Note: We have to use Version 1, because Version 2 doesn't have the functionality to decompile Java sources (for now).

  2. Download Notepad++ and install it. I used the current version, which is Version 6.6.9.
  3. Download 7zip and install it.
  4. Build your APK file in App Inventor, for the example I used the manager screen example, which has the package name appinventor.ai_taifunbaer.manager after building.

2. Decompile using APK Studio

  1. Create a new subfolder inside of C:\Prog\apkstudio, I used the subfolder name "myApk" and copy the App Inventor apk file in there.
  2. Start APK Studio, click onto "File/Open APK" and select the APK you want to decompile.

    Wait until the file is decompiled, this takes a while! The apk file is decompiled in a new subfolder ending with "-apkstudio" (in the example the subfolder name is manager-apkstudio). This process is ready, when you get the text "Decompiling com/google/youngandroid/runtime..." in the status bar.
  3. Close APK Studio.

3. Modify the jar file to get the new directory structure using 7zip

We have to adjust the directory structure from appinventor/ai_taifunbaer/manager to com/puravidaapps/manager.

  1. In the File Manager go to the "-androidstudio" subfolder (C:\Prog\apkstudio\myApk\manager-apkstudio). Copy the .jar file from the "-apkstudio" folder and paste it into a new folder, I used folder "temp".
  2. In the temp folder right click onto the copied jar file and select 7zip - unzip here. Some folders appear inside the temp folder.
  3. Open the appinventor folder and rename the folder inside. For the example I have to rename the folder ai_taifunbaer to puravidaapps
  4. Now use a second file manager, go to the temp folder, right click onto the jar file and select 7zip - Open. Inside 7zip open the com folder and move the previously renamed folder puravidaapps inside (Drag and drop).
  5. In 7zip go back to the main folder and delete the appinventor folder
  6. Close 7zip and replace the original jar file in the "-apkstudio" folder by the modified jar file which now has new directory structure.

4. Search and Replace the package name using Notepad++

We have to rename the package name from appinventor.ai_taifunbaer.manager to com.puravidaapps.manager in all files.

  1. In the File Manager go to the "-androidstudio" subfolder (C:\Prog\apkstudio\myApk\manager-apkstudio), right-click onto the file "Android Manifest.xml" and select "Edit with Notepad++". Highlight the part of the name you want change, in the example it is appinventor.ai_taifunbaer.manager, select the correct directory, in the example this is the folder C:\Prog\apkstudio\myApk\manager-apkstudio.

    Then go to - "Search/Find in Files" and click onto "Find All" and it will find all identical names. In the example I got 11 hits in 8 files.
  2. Go back to "Search/Find in Files" Click on "Replace with" and type in the new package name, in the example this is com.puravidaapps.manager,
    then click on "Replace in files" and after confirmation

    the old package name will be replaced by the new package name in all files.

5. Search and Replace the directory structure using Notepad++

We have to rename the directory structure from appinventor/ai_taifunbaer/manager to com/puravidaapps/manager in all files.

  1. Go back to "Search/Find in Files" and search for appinventor/ai_taifunbaer/manager
    Then go to "Search/Find in Files" and click onto "Find All" and it will find all identical names. In the example I got 2075 hits in 12 files.
  2. Go back to "Search/Find in Files" Click on "Replace with" and type in the new directory structure, in the example this is com/puravidaapps/manager, then click on "Replace in files" and after confirmation the old directory structure will be replaced by the new directory structure in all files.
  3. Close Notepad++

6. Repackage the apk file using APK Studio

  1. Open up APK Studio again and click - "File - Open Directory", select the folder that you have been working on which ends in "-apkstudio" (C:\Prog\apkstudio\myApk\manager-apkstudio) and click "OK", then click "Build - Repackage" .

    This process is ready, when you get the text "Successfully rebuilt..." in the status bar.
  2. You will find the rebuilt file in the dist folder
  3. Ready!

For questions about App Inventor,
please ask in the App Inventor community.Thank you.

Questions and Answers

Q1: I need help with a package app to rename... I cannot do! I've tried many times and I just can install the app. When I launch the app, it crashes! Can you help me?
A: You have to follow the tutorial EXACTLY step by step, else it will not work.

Q2: When I try to upload the modified apk to Play Store it gives me the following error "Upload failed You uploaded an APK that is signed with a restricted certificate. You need to upload an APK signed with your own certificate."
A: After reading this probably the easiest way is to use AppToMarket to sign your app or sign the app using this tutorial.

Q3: Your tutorial in changing the package name is awesome and working most of the time. But when I try to add a "Texting" element from the Social Component in my app, I can't decompile it using APK Studio.
A: Brown Bear found out, how to decompile an app, which uses the texting component. Thank you Brown Bear!

Q4: I wait 8 hours for decompile the APK with APKstudio... and he has not finished... why?
A: As vgn found out the hard way here, installing Apk Studio in C:\Programs did not work to decompile an apk file. It worked for him after installing to desktop. Or just follow my instructions above and install it in C:\Prog\apkstudio ;-)
Also probably one of the App Inventor components you are using in your project prevent Apk Studio to decompile the apk file. For example the texting component (see solution in Q3 above) or the fusiontable control component, as Sharooz found out here.

Generally to find out, which component prevents Apk Studio to decompile your apk file, first create a backup of your project and download it to your computer. Then as test remove one of the components from the project, build it, then try to decompile again. In case it still does not decompile, try to remove the next component etc. until you find out, which component it is. Let us know, what you find out.


Developing and maintaining snippets, tutorials and extensions for App Inventor takes a lot of time.
I hope it saved some of your time. If yes, then you might consider to donate a small amount!

Donation amount:

or donate some mBTC to Bitcoin Address:
1Jd8kXLHu2Vkuhi15TWHiQm4uE9AGPYxi8
Bitcoin

Thank you! Taifun
 

Back to top of page ...

Creative Commons License
This work by Pura Vida Apps is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
with attribution (name=Pura Vida Apps and link to the source site) required.


Home | Snippets | Tutorials | Extensions | Links | Search | Privacy Policy | Contact