Skip to main content

Enable debugging mode & Start Debugging with Android Studio

· 4 min read
Vo Luu Tuong Anh
VLTA of @TheFlightSims

Android Studio showcase

Prepare environment

It is recommended to install development packages

  • SDKs: 25 (Android 7.1.1), 27 (Android 8.1), 29 (Android 10.0), 31 (Android 12.0), 32 (Android 12L), 33 (Android 13), 34 (Android 14), 35 (Android 15), and 36 (Android 16). Note that you may need the emulator base image, and may not install Android SDK packages that not included within the APK supprted range.
  • Toolchains: Android SDK Build-Tools, Android SDK Command-line Tools (latest), Android Emulator (all), Google Play libraries and services (all, except the Instant Development SDK)
  • Plugins: Database Nagivator (to open sqlite)

Start adding the $PATH with the debugging packages

The following paths must be added to the path in order to use the application packages:

  • Java Development Kit 21 (/bin folder), to use keytool (recommend to add into the system $PATH variable)
  • Android platform tools (usually in Android/Sdk/platform-tools) to use adb
  • Android Build Tools (take your pick, usually in Android/Sdk/build-tools), to use apksigner

Installing device driver for ADB

Visit this page to install ADB device driver

Repack the Android Application package with the debuggable flag

  1. Using apktool.jar to unpack the Android application package

    apktool.jar d -o <output-directory> <path-to-your-apk-file>
  2. Once the unpacking is done, try adding the debuggable flag, and data retaining into the AndroidManifest.xml, under the <output-directory> path

    <application android:debuggable="true" android:hasFragileUserData="true" android:allowBackup="true" ...>
    <!-- other application elements -->
    </application>
  3. Recompile the APK

    apktool.jar b -o <path-to-your-new-apk-file> <output-directory> 

Resign the Android Application Package (with custom signing key, easy mode)

  1. First, create a custom signing key

    keytool -genkey -v -keystore <path-to-the-key-but-accessible> -alias alias_name -keyalg RSA -keysize <key-length> -validity <valid-days>
  2. Use the just-created signing key to sign the Apk

    apksigner sign -ks <path-to-the-key-but-accessible> --ks-pass pass:<password-you-set-on-the-key> <path-to-your-new-apk-file>

Try installing a new Android Application Package

Using the adb, try to install the new application package.

adb install <path-to-your-new-apk-file>

Common errors

INSTALL_PARSE_FAILED_NO_CERTIFICATES

Try signing the APK and resigning it in Resign the Android Application Package

INSTALL_FAILED_MISSING_SPLIT

It usually occurs when the application package is packed with multiple applications (e.g., it is packed in an XAPK) for multiple ABIs, where the base package does not provide the proper way for Android to handle the application.

If you are the developer/tester, try installing the APK with install-multiple flags.

If you are not, you may need to download the APK from an application store, such as ApkCombo. Once you've downloaded it, try unpacking the XAPK and start enabling debugging from the beginning.

Note:

  • You may need to resign both base and split packages, see the signing Android application package above
  • It is recommended to check for the device ABI before proceeding any further step. See INSTALL_FAILED_NO_MATCHING_ABIS below for details.

INSTALL_FAILED_NO_MATCHING_ABIS

It appears when your application is not compatible with the device architecture.

Try to find a package that is compatible with your device.

Note:

  • If this is a splited application package, just keep the base application package and find the matching ABI for library, it is not needed to redo all things

INSTALL_FAILED_UPDATE_INCOMPATIBLE

It occurs when your application package is already installed, and it has a different key compared to the modified application package.

Try to uninstall it with pm of adb shell, or using your own application manager inside your device.

(base) sh@DESKTOP-O9NIMTA:~$ adb shell
android:/ $ pm list packages | grep "<application-name-parts>"
android:/ $ pm uninstall <the-application-package-you-just-found>