【发布时间】:2019-05-04 02:45:22
【问题描述】:
有没有办法让 MSAL 与 Instant Run 和 AndroidX 一起工作?
Microsoft Authentication Library 0.2.1 开箱即用地与 Android Studio 配合使用,但在启用 Instant Run 后迁移到 androidx 后会出现构建错误。
编译时Java编译器报如下错误:
java.lang.SecurityException:com/microsoft/identity/client/AuthenticationCallback.class 的 SHA-256 摘要错误
复制:
- 创建一个新的 Android Studio 项目
- 确保已启用即时运行(文件 > 设置 > 构建、执行、部署 > 即时运行)
- 按照此处的说明进行操作:https://github.com/AzureAD/microsoft-authentication-library-for-android
- 调试。一切都会好起来的。
- 将以下内容添加到 gradle.properties:
- android.useAndroidX=true
- android.enableJetifier=true
- 重构 > 迁移到 AndroidX(无关:如果需要修复布局等)
- 尝试开始调试
- 现在编译器会报告上述错误
- 禁用即时运行
- 调试
- 现在一切正常。
我的 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
【问题讨论】:
-
如 Github 上所述,这是一个已知问题,但产品团队尚未对其进行分类。
标签: android msal androidx android-instant-run