适用于Android的MSAL:在使用androidx进行即时运行期间的SHA-256摘要错误(AuthenticationCallback.class)

问题描述 投票:2回答:2

有没有办法让MSAL与Instant Run和AndroidX一起工作?

Microsoft身份验证库0.2.1与Android Studio完全兼容,但在启用Instant Run后迁移到androidx后会出现构建错误。

Java编译器在构建期间报告以下错误:

java.lang.SecurityException:com / microsoft / identity / client / AuthenticationCallback.class的SHA-256摘要错误

演讲嘉宾:

  1. 创建一个新的Android Studio项目
  2. 确保启用了即时运行(文件>设置>构建,执行,部署>即时运行)
  3. 按照这里的说明:https://github.com/AzureAD/microsoft-authentication-library-for-android
  4. 调试。事情应该很好。
  5. 将以下内容添加到gradle.properties: android.useAndroidX =真 android.enableJetifier =真
  6. 重构>迁移到AndroidX(不相关:如果需要修复布局等)
  7. 尝试开始调试
  8. 现在编译器报告上面提到的错误
  9. 禁用即时运行
  10. 调试
  11. 现在情况很好。

我的MainActivity看起来如下:

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)
}
}

编辑:GitHub问题https://github.com/AzureAD/microsoft-authentication-library-for-android/issues/354

android msal androidx android-instant-run
2个回答
2
投票

我正在我的Android应用程序中集成AD登录,当我启用Instant Run时,我开始遇到此问题。所以我再次禁用了Instant Run,现在一切正常。


0
投票

似乎现在工作(不知道它何时修复或如何但MSAL 0.2.2和0.3.1-alpha似乎与2019年4月10日构建的Android Studio一起工作)。

© www.soinside.com 2019 - 2024. All rights reserved.