Unable to create SingleAccountPublicClientApplication for Azure AD on android

In short: this is likely a problem with your debug keystore. I was having this same problem recently, it ended up being a problem when I was creating the hash on the command line with their instructions. What solved it for me was re-doing the app registration process on the azure portal, and when you create the hash on the command line, make sure to use the password for your android keystore (default is 'android'). The first time I did it I used the default password for the jdk keystore and it still created a hash for me but it resulted in the error you described. I'm not entirely sure how the whole process works and would love for another person to clarify, but what I described above solved the issue for me.


I too faced the same issue. To get the Signature hash that works, follow the below steps.

STEP 1: Run the below method in the onCreate method of LAUNCHER activity.

Kotlin

@RequiresApi(Build.VERSION_CODES.P)
private fun getSignatureHash() {
   try {
      val info = packageManager.getPackageInfo(
         "<com.package.name>",
         PackageManager.GET_SIGNING_CERTIFICATES
      )
      for (signature in info.signingInfo.apkContentsSigners) {
         val md = MessageDigest.getInstance("SHA")
         md.update(signature.toByteArray())
         Log.d(
           "KeyHash", "KeyHash:" + Base64.encodeToString(
              md.digest(),
              Base64.DEFAULT
           )
         )
      }
   } catch (e: PackageManager.NameNotFoundException) {
   } catch (e: NoSuchAlgorithmException) {
   }
}

Java
https://github.com/AzureAD/microsoft-authentication-library-for-android/issues/914#issuecomment-582259223

try {
   PackageInfo info = getPackageManager().getPackageInfo(
      "<com.package.name>",
      PackageManager.GET_SIGNATURES
   );
   for (Signature signature : info.signatures) {
      MessageDigest md;
      md = MessageDigest.getInstance("SHA");
      md.update(signature.toByteArray());
      String something = new String(Base64.encode(md.digest(), 0));
      //String something = new String(Base64.encodeBytes(md.digest()));
      Log.e("KeyHash", something);
   }
} catch (PackageManager.NameNotFoundException e1) {
   Log.e("name not found", e1.toString());
} catch (NoSuchAlgorithmException e) {
   Log.e("no such an algorithm", e.toString());
} catch (Exception e) {
   Log.e("exception", e.toString());
}

STEP 2: You should get the HashKey in the Android Studio Logcat. Use this HasKey to register in Azure AD