What does the hyphen and number that comes after an installed package name mean?


Question

For example, if I install Google Chrome on my phone (assume it's not prebuilt), whatever the original name of the apk is, it will usually be installed to /data/app/com.android.chrome-1.apk but sometimes /data/app/com.android.chrome-2.apk and even xxx-3.apk or xxx-4.apk

My question is what the number in that case mean and how is it generated? It's often varying and I haven't found any clue.


Answer

The number has no special meanings. It is used to distinguish old and new packages during installation. While installing an app, the Package Installer first finds an available 'packageid-number' pattern, with the number incrementing from 1, and creates the directory (APK file for Android 5.0 and under). Then it places the APK file in it and removes the old one. Therefore, most commonly the number only varies from 1 to 2 because only one instance of an installed app exists. Summing up the old app and the temporary name, there can only be 2 instances. If you have, by some other means like installing 2 of the same app using a parallel container, there can be up to 4 instances of the app, thus creating com.example-4.



Here's my experiment on Android 5.1.1, using Root Explorer to install the app and Terminal Emulator to monitor directory content change.

Preparation: Use XInstaller (an Xposed module) to allow downgrade installing app (so that I can repeatedly install the same version of an app).

1. Tap the prepared APK file in Root Explorer to install it. In my case, it's Termux.

2. Repeatedly run



root@android:/data/app # ls -d com.termux-*


Output:

First: com.termux-1

After some time: com.termux-1 com.termux-2

After more time and finally: com.termux-2

3. Tap the APK to install it again and repeat Step 2.

Output:

First: com.termux-2

After some time: com.termux-1 com.termux-2

After more time and finally: com.termux-1

4. Create placeholder directories named com.termux-2, com.termux-3, com.termux-4 and set correct permissions.

5. Repeat Step 3.

Output:

First:

com.termux-1  com.termux-2  com.termux-3  com.termux-4

After some time:
com.termux-1  com.termux-2  com.termux-3  com.termux-4  com.termux-5

After more time and finally:
com.termux-2  com.termux-3  com.termux-4  com.termux-5

Where com.termux-2, com.termux-3, com.termux-4 are all empty as they are created by me, not the Package Installer. To verify, run



root@android:/data/app # pm list packages -f | grep com.termux
package:/data/app/com.termux-5/base.apk=com.termux

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes