Is there a way to get MSAL working together with Instant Run and AndroidX?
Microsoft Authentication Library 0.2.1 works fine out-of-the-box with Android Studio but gives build errors after migrating to androidx when Instant Run is enabled.
The following error is reported by Java compiler during build:
java.lang.SecurityException: SHA-256 digest error for com/microsoft/identity/client/AuthenticationCallback.class
Repro:
My MainActivity looks as follows:
class MainActivity : AppCompatActivity() {
val CLIENT_ID = "<My Client Id>"
val SCOPES = arrayOf("https://graph.microsoft.com/User.Read")
private lateinit var sampleApp: PublicClientApplication
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
sampleApp = PublicClientApplication(
this.applicationContext,
CLIENT_ID
)
sampleApp.acquireToken(this, SCOPES, getAuthInteractiveCallback());
}
private fun getAuthInteractiveCallback(): AuthenticationCallback {
return object : AuthenticationCallback {
override fun onSuccess(authenticationResult: AuthenticationResult) {
val accessToken = authenticationResult.getAccessToken()
}
override fun onError(exception: MsalException) {
if (exception is MsalClientException) {
/* Exception inside MSAL, more info inside MsalError.java */
} else if (exception is MsalServiceException) {
/* Exception when communicating with the STS, likely config issue */
}
}
override fun onCancel() {
/* User canceled the authentication */
}
}
}
/* Handles the redirect from the System Browser */
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
sampleApp.handleInteractiveRequestRedirect(requestCode, resultCode, data)
}
}
Edit: GitHub issue https://github.com/AzureAD/microsoft-authentication-library-for-android/issues/354
Seems to work now (don't know when it was fixed or how but both MSAL 0.2.2 and 0.3.1-alpha seem to work with April 10, 2019 build of Android Studio).