|
| 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.topic: how-to |
| 6 | +ms.service: entra-id |
| 7 | +ms.date: 02/20/2025 |
| 8 | +ms.custom: sap:Developing or Registering apps with Microsoft identity platform |
| 9 | +--- |
| 10 | +# Package Inspector for MSAL Android Native |
| 11 | + |
| 12 | +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 can be invaluable for troubleshooting and verifying the signature hash for applications installed on an Android device. This article covers installation, usage, and common issues of the Package Inspector. |
| 13 | + |
| 14 | +## Scenarios where you can use Package Inspector |
| 15 | + |
| 16 | +- 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. |
| 17 | + |
| 18 | + In this scenario, Package Inspector will be useful to discover the new signature hash used by Google to sign in to the app package. |
| 19 | + |
| 20 | +- You are implementing MSAL in your Android application, but encounter the following error: |
| 21 | + |
| 22 | + > 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. |
| 23 | +
|
| 24 | + In this scenario, you can use the Package Inspector to verify what the package signature hash is and configure both the Azure portal and application to use the correct signature hash. |
| 25 | + |
| 26 | +- You are implementing MSAL in your Android application, but encounter the following error: |
| 27 | + |
| 28 | + > Intent filter for: BrowserTabActivity is missing |
| 29 | + |
| 30 | + This error can occur because the signature hash specified in the *AndroidManifest.xml* file doesn't match the signature hash actually used to sign in to the APK file. In this scenario, the Package Inspector will be useful to verify what the signature hash actually is. |
| 31 | + |
| 32 | +> [!NOTE] |
| 33 | +> For more information about MSAL for Android Native, see [Microsoft Authentication Library (MSAL) for Android](https://github.com/AzureAD/microsoft-authentication-library-for-android). |
| 34 | +
|
| 35 | +## Prerequisites |
| 36 | + |
| 37 | +Before you start, ensure you have the following: |
| 38 | + |
| 39 | +- A recent version of Android Studio installed. |
| 40 | +- A virtual Android device with applications installed, which can be managed using Android Studio's AVD manager. For more information, see [AVD manager](https://developer.android.com/studio/run/managing-avds). |
| 41 | +- A physical device with developer options, USB debugging enabled, and a USB cable. For more information, see [Developer options](https://developer.android.com/studio/debug/dev-options). |
| 42 | +- An application installed to inspect. |
| 43 | + |
| 44 | +## Install Package Inspector |
| 45 | + |
| 46 | +There are two methods to install Package Inspector: |
| 47 | + |
| 48 | +### Option 1: Clone the repository directly into Android Studio |
| 49 | + |
| 50 | +1. Open Android Studio and close any open projects. |
| 51 | +2. Select **Get From Version Control**. |
| 52 | + |
| 53 | + :::image type="content" source="https://rubikcopilotchat.azurewebsites.net/blobimages/991342cf-513f-4844-8923-37065c451d32/7a705a68-d6b2-4df8-b632-fc828b142f6f.png" alt-text="Screenshot that shows the 'Get From Version Control' option in Android Studio" lightbox="https://rubikcopilotchat.azurewebsites.net/blobimages/991342cf-513f-4844-8923-37065c451d32/7a705a68-d6b2-4df8-b632-fc828b142f6f.png"::: |
| 54 | +3. Ensure **Git** is selected at the top of the window, paste the repository URL `https://github.com/AzureAD/microsoft-authentication-library-for-android.git`, and select **Clone**. |
| 55 | + |
| 56 | + :::image type="content" source="https://rubikcopilotchat.azurewebsites.net/blobimages/991342cf-513f-4844-8923-37065c451d32/63ea16d9-74d6-43fb-9965-76382e2442f6.png" alt-text="Screenshot that shows how to clone a Git repository in Android Studio" lightbox="https://rubikcopilotchat.azurewebsites.net/blobimages/991342cf-513f-4844-8923-37065c451d32/63ea16d9-74d6-43fb-9965-76382e2442f6.png"::: |
| 57 | + |
| 58 | +### Option 2: Download as a zip file and open in Android Studio |
| 59 | + |
| 60 | +1. [Download the repository](https://github.com/AzureAD/microsoft-authentication-library-for-android/archive/refs/heads/dev.zip). |
| 61 | +2. Extract the zip file to your selected directory. |
| 62 | +3. Open Android Studio and close any open projects. |
| 63 | +4. Select **Open an Existing Project**. |
| 64 | + |
| 65 | + :::image type="content" source="https://rubikcopilotchat.azurewebsites.net/blobimages/991342cf-513f-4844-8923-37065c451d32/c40bb5ff-38b6-45f4-ae7d-1eee54a441d0.png" alt-text="Screenshot that shows the 'Open an Existing Project' option in Android Studio" lightbox="https://rubikcopilotchat.azurewebsites.net/blobimages/991342cf-513f-4844-8923-37065c451d32/c40bb5ff-38b6-45f4-ae7d-1eee54a441d0.png"::: |
| 66 | +5. Select the root package **msal-android** for the Android MSAL repository. Then, select **OK**. |
| 67 | + |
| 68 | + :::image type="content" source="https://rubikcopilotchat.azurewebsites.net/blobimages/991342cf-513f-4844-8923-37065c451d32/8f4e6637-a29a-4605-9c96-e8674c9801d1.png" alt-text="Screenshot showing selecting the Root Package in Android Studio" lightbox="https://rubikcopilotchat.azurewebsites.net/blobimages/991342cf-513f-4844-8923-37065c451d32/8f4e6637-a29a-4605-9c96-e8674c9801d1.png"::: |
| 69 | + |
| 70 | + > [!NOTE] |
| 71 | + > - The default name of the root package is `microsoft-authentication-library-for-android-dev`, but you might have renamed it. |
| 72 | + > - Don't select the **package-inspector** directory. |
| 73 | +
|
| 74 | +## Use Package Inspector |
| 75 | + |
| 76 | +1. With the Android MSAL project open in Android Studio, connect the desired Android device. This can be a physical device connected to the computer's USB port 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. |
| 77 | +2. To the left of the device drop-down, there is another drop-down list. Select this and select **package-inspector**. |
| 78 | + |
| 79 | + :::image type="content" source="https://rubikcopilotchat.azurewebsites.net/blobimages/991342cf-513f-4844-8923-37065c451d32/b38c129a-9cfb-4901-85f6-da13cc592f36.png" alt-text="Screenshot that shows the selection of package-inspector in Android Studio" lightbox="https://rubikcopilotchat.azurewebsites.net/blobimages/991342cf-513f-4844-8923-37065c451d32/b38c129a-9cfb-4901-85f6-da13cc592f36.png"::: |
| 80 | +3. Select the green **play** button (indicated with a green circle on the right) to build, install, and run the package inspector on the selected device. |
| 81 | +4. Browse the list of packages in the package-inspector app and select a package to view its signature hash. All accessible packages will appear in this list. |
| 82 | + |
| 83 | + :::image type="content" source="https://rubikcopilotchat.azurewebsites.net/blobimages/991342cf-513f-4844-8923-37065c451d32/6adfe09a-5e98-4b7b-b2f3-2c83b60fff8f.png" alt-text="Screenshot that shows package selection in the Package Inspector app" lightbox="https://rubikcopilotchat.azurewebsites.net/blobimages/991342cf-513f-4844-8923-37065c451d32/6adfe09a-5e98-4b7b-b2f3-2c83b60fff8f.png"::: |
| 84 | + |
| 85 | +## Common issues |
| 86 | + |
| 87 | +### Issues when loading Package Inspector into Android Studio |
| 88 | + |
| 89 | +To resolve these issues, ensure you load the root package from the MSAL repository, not just the package inspector. The project you're loading should be named `microsoft-authentication-library-for-android-dev` or whatever you have renamed the root repository on your system instead of package-inspector. See step 5 under [Option 2](#option-2-download-as-a-zip-file-and-open-in-android-studio) in the [Install Package Inspector](#install-package-inspector) section. |
| 90 | + |
| 91 | +### Not all packages appear in Package Inspector |
| 92 | + |
| 93 | +You can install and open Package Inspector, and a list of packages appear in the app. However, you don't see packages for any of the apps you have installed on the device. It might be due to changes in Android 11 (API 30). For more information, see [here](https://developer.android.com/training/package-visibility). |
| 94 | + |
| 95 | +To resolve this issue, follow these steps: |
| 96 | + |
| 97 | +1. Open the AndroidManifest.xml file within the package-inspector directory on the left side of Android Studio. |
| 98 | +2. Add the following permission and query between the `<manifest></manifest>` tags: |
| 99 | + |
| 100 | + ```xml |
| 101 | + <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.microsoft.inspector"></manifest> |
| 102 | + ... |
| 103 | + |
| 104 | + <permission android:name="android.permission.QUERY_ALL_PACKAGES" /> |
| 105 | + |
| 106 | + <queries> |
| 107 | + <intent> |
| 108 | + <action android:name="android.intent.action.MAIN" /> |
| 109 | + </intent> |
| 110 | + </queries> |
| 111 | + ``` |
| 112 | + |
| 113 | +3. Rerun the application from Android Studio to apply the changes. Then, you should can see the packages you have installed. |
| 114 | + |
| 115 | +[!INCLUDE [Azure Help Support](../../../includes/azure-help-support.md)] |
0 commit comments