How to rename and sign APKs, and upload them as Managed Google Play private apps in Intune

Gabriel Gunnarsson,intuneapkgoogle playandroid enterprise

We recently experienced an issue with a third-party vendor that published a faulty version of a business-critical application in Google Play. The application crashed immediately on launch. The vendor quickly provided us with the APK of the previous version, but could not say when a fixed version would be released to Google Play.

Since we are using Android Enterprise to manage our Android devices, the only way to deploy an application is via Managed Google Play. Google Play requires the package names of all applications to be globally unique. To upload the APK we received from the third-party vendor, we must change its package name.

flowchart LR id1[Decompile APK] id2[Modify package name] id3[Recompile APK] id4[Sign & Zip align APK] id1-->id2 id2-->id3 id3-->id4

Table of Contents

  1. Rename Package
    1. Decompile APK
    2. Modify package name
    3. Recompile APK
    4. Sign & Zip algin APK
  2. Upload Package

Prerequisites

Rename package

1 Decompile APK

The APK is decompiled using Apktool.

apktool decode path-to-apk.apk -o output/path

Make sure the output path does not already exist, or add --force to the command.

2 Modify package name

Open the output folder, it should look something like this.

Output folder
|───assets
|───build
|───original
|───res
|───smali
|───unknown
|   AndroidManifest.xml
|   apktool.yml

Open apktool.yml and set the new package name by changing the renameManifestPackage value.

!!brut.androlib.meta.MetaInfo
apkFileName: filename.apk
...
packageInfo:
  forcedPackageId: '127'
  renameManifestPackage: com.originalcompany.originalpackage
...

3 Recompile APK

Run apktool again to recompile the APK with the new, updated package name. The first path here should point to the output folder from above.

apktool build path/to/folder -o output/new-apk-name.apk

4 Sign & Zip align APK

java -jar uber-apk-signer.jar --apks /path/to/new-apk-name.apk --ks /path/to/keystore `
    --ksAlias [alias of the upload key] --out /path/to/output/folder

You will be prompted to enter the passwords as required.

Upload Package

To upload the package to Intune, follow the instructions on docs.microsoft.com

⚠️

According to the upload form, the title can contain max 50 characters. However, I have found that using above around 30 characters will result in an error message and the app will be stuck in a perpetual "Not available yet" status. If this happens to you, you must repackage the app with a new package name and then upload it again with a shorter title.

© Gabriel Gunnarsson.RSS