|
| 1 | +--- |
| 2 | +title: Package Inspector for MSAL Android Native |
| 3 | +description: Introduces how to install and use the Package Inspector tool. |
| 4 | +ms.reviewer: markbukovich, v-weizhu |
| 5 | +ms.service: entra-id |
| 6 | +ms.date: 03/25/2025 |
| 7 | +ms.custom: sap:Developing or Registering apps with Microsoft identity platform |
| 8 | +--- |
| 9 | +# Package Inspector for MSAL Android Native |
| 10 | + |
| 11 | +The Microsoft Authentication Library (MSAL) for Android Native includes a tool called Package Inspector. This tool lists the packages installed on an Android device and allows users to view, copy, and paste the signature hash used to sign an application's package. Package Inspector is invaluable for troubleshooting and verifying the signature hash of applications installed on an Android device. This article covers installation, usage, and common issues of the Package Inspector. |
| 12 | + |
| 13 | +## Scenarios for using Package Inspector |
| 14 | + |
| 15 | +- You have successfully developed an application to use MSAL, but after deploying the app to the Google Play Store, the app fails to perform authentication. |
| 16 | + |
| 17 | + In this scenario, Package Inspector is useful to discover the new signature hash used by Google to sign the app package. |
| 18 | + |
| 19 | +- You are implementing MSAL in your Android application, but encounter the following error: |
| 20 | + |
| 21 | + > The redirect URI in the configuration file doesn't match with the one generated with the package name and signature hash. Please verify the uri in the config file and your app registration in Azure portal. |
| 22 | +
|
| 23 | + In this scenario, you can use Package Inspector to verify what the package signature hash is and configure both the Azure portal and application to use the correct signature hash. |
| 24 | + |
| 25 | +- You are implementing MSAL in your Android application, but encounter the following error: |
| 26 | + |
| 27 | + > Intent filter for: BrowserTabActivity is missing |
| 28 | + |
| 29 | + This error occurs because the signature hash specified in the *AndroidManifest.xml* file doesn't match the signature hash used to sign the APK file. In this scenario, Package Inspector is useful to verify what the signature hash is. |
| 30 | + |
| 31 | +> [!NOTE] |
| 32 | +> For more information about MSAL for Android Native, see [Microsoft Authentication Library (MSAL) for Android](https://github.com/AzureAD/microsoft-authentication-library-for-android). |
| 33 | +
|
| 34 | +## Prerequisites |
| 35 | + |
| 36 | +Before you start, ensure you have the following: |
| 37 | + |
| 38 | +- A recent version of Android Studio installed. |
| 39 | + |
| 40 | + Android Studio comes with an AVD manager. For more information, see [Create and manage virtual devices](https://developer.android.com/studio/run/managing-avds). |
| 41 | +- A virtual Android device with applications installed. |
| 42 | +- A physical device with developer options, USB debugging enabled, and a USB cable. For more information, see [Configure on-device developer options](https://developer.android.com/studio/debug/dev-options). |
| 43 | +- An application installed to inspect. |
| 44 | + |
| 45 | +## Install Package Inspector |
| 46 | + |
| 47 | +There are two methods to install Package Inspector: |
| 48 | + |
| 49 | +### Option 1: Clone Android MSAL repository directly into Android Studio |
| 50 | + |
| 51 | +1. Open Android Studio and close any open projects. |
| 52 | +2. Select **Get From Version Control**. |
| 53 | + |
| 54 | + :::image type="content" source="media/package-inspector-msal-android-native/get-from-version-control.png" alt-text="Screenshot that shows the 'Get From Version Control' option in Android Studio"::: |
| 55 | +3. Ensure **Git** is selected at the top of the window, paste the Android MSAL repository URL `https://github.com/AzureAD/microsoft-authentication-library-for-android.git`, and then select **Clone**. |
| 56 | + |
| 57 | + :::image type="content" source="media/package-inspector-msal-android-native/clone-msal-repository.png" alt-text="Screenshot that shows how to clone a Git repository in Android Studio"::: |
| 58 | + |
| 59 | +### Option 2: Download Android MSAL repository and open it in Android Studio |
| 60 | + |
| 61 | +1. [Download the Android MSAL repository](https://github.com/AzureAD/microsoft-authentication-library-for-android/archive/refs/heads/dev.zip). |
| 62 | +2. Extract the zip file to your selected directory. |
| 63 | +3. Open Android Studio and close any open projects. |
| 64 | +4. Select **Open an Existing Project**. |
| 65 | + |
| 66 | + :::image type="content" source="media/package-inspector-msal-android-native/open-existing-project-android-studio.png" alt-text="Screenshot that shows the 'Open an Existing Project' option in Android Studio"::: |
| 67 | +5. Select the root package **msal-android** for the Android MSAL repository. Then, select **OK**. |
| 68 | + |
| 69 | + :::image type="content" source="media/package-inspector-msal-android-native/select-root-package.png" alt-text="Screenshot showing selecting the root package in Android Studio"::: |
| 70 | + |
| 71 | + > [!NOTE] |
| 72 | + > - The default name of the root package is `microsoft-authentication-library-for-android-dev`. In this example, it's renamed `msal-android`. |
| 73 | + > - Don't select the **package-inspector** directory. |
| 74 | +
|
| 75 | +## Use Package Inspector |
| 76 | + |
| 77 | +1. With the Android MSAL project open in Android Studio, connect the desired Android device. It can be a physical device connected to the computer's USB port or an emulator booted from Android Studio's AVD manager. Ensure your device appears in the drop-down list at the top of Android Studio and select it. |
| 78 | +2. On the left of the device drop-down list, there is another drop-down list. Select **package-inspector** from it. |
| 79 | + |
| 80 | + :::image type="content" source="media/package-inspector-msal-android-native/select-package-inspector.png" alt-text="Screenshot that shows the selection of package-inspector in Android Studio" lightbox="media/package-inspector-msal-android-native/select-package-inspector.png"::: |
| 81 | +3. Select the **play** button (indicated with a green circle on the right) to build, install, and run Package Inspector on the selected device. |
| 82 | + |
| 83 | + :::image type="content" source="media/package-inspector-msal-android-native/select-play-button.png" alt-text="Screenshot that shows the selection of the play button in Android Studio" lightbox="media/package-inspector-msal-android-native/select-play-button.png"::: |
| 84 | +4. Browse the list of packages in the Package Inspector app and select a package to view its signature hash. All accessible packages appear in this list. |
| 85 | + |
| 86 | + :::image type="content" source="media/package-inspector-msal-android-native/select-package-to-check-signature-hash.png" alt-text="Screenshot that shows package selection in the Package Inspector app"::: |
| 87 | + |
| 88 | +## Common issues |
| 89 | + |
| 90 | +### Issues when loading Package Inspector into Android Studio |
| 91 | + |
| 92 | +To resolve these issues, ensure you load the root package from the MSAL repository, not Package Inspector. Make sure that the Android MSAL project you load into Android Studio is named `microsoft-authentication-library-for-android-dev` or whatever you have renamed the root directory on your system instead of `package-inspector`. For more information, see step 5 under [Option 2](#option-2-download-android-msal-repository-and-open-it-in-android-studio) in the [Install Package Inspector](#install-package-inspector) section. |
| 93 | + |
| 94 | +### Not all packages appear in Package Inspector |
| 95 | + |
| 96 | +You have installed and opened Package Inspector, and a list of packages appear in the app. However, you don't see packages for any apps you have installed on the device. The issue might occur due to changes in Android 11 (API 30). For more information, see [Package visibility](https://developer.android.com/training/package-visibility). |
| 97 | + |
| 98 | +To resolve this issue, follow these steps: |
| 99 | + |
| 100 | +1. Open the *AndroidManifest.xml* file within the `package-inspector` directory on the left side of Android Studio. |
| 101 | +2. Add the following permission and query between the `<manifest></manifest>` tags: |
| 102 | + |
| 103 | + ```xml |
| 104 | + <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.microsoft.inspector"></manifest> |
| 105 | + ... |
| 106 | + |
| 107 | + <permission android:name="android.permission.QUERY_ALL_PACKAGES" /> |
| 108 | + |
| 109 | + <queries> |
| 110 | + <intent> |
| 111 | + <action android:name="android.intent.action.MAIN" /> |
| 112 | + </intent> |
| 113 | + </queries> |
| 114 | + ``` |
| 115 | + |
| 116 | +3. Rerun the application from Android Studio to apply the changes. Then, you can see the packages you have installed. |
| 117 | + |
| 118 | +[!INCLUDE [Azure Help Support](../../../includes/azure-help-support.md)] |
0 commit comments