如果我使用 Crashlytics,我该如何使用 "Apply Changes"?

How can I use "Apply Changes" if I use Crashlytics?

我正在使用 Android Studio 3.5 Beta 1。我决定试用 "Apply Changes"。 Instant 运行 存在问题,因此我们已将其禁用多年。我希望这会更好。

如果我尝试 "Apply Code Changes" 按钮,我会在 运行 window:

中收到错误消息
Changes were not applied.
Modifying resources requires an activity restart.
Resource 'assets/crashlytics-build.properties' was modified.
Apply changes and restart activity

crashlytics-build.properties 有评论说

#This file is automatically generated by Crashlytics to uniquely
#identify individual builds of your Android application

事实上,它有一个 build_id 属性,可能会随着每个 Gradle 构建而改变。由于 Gradle 在我使用 "Apply Code Changes" 或 "Apply Changes and Restart Activity" 按钮时运行构建,Gradle 构建会更改文件,从而阻止 Apply 运行 完成。

我在网上找到的唯一与此相关的信息是 Reddit comment

I learned the hard way that crashlytics + proguard breaks instant run

看来我不是唯一遇到这个问题的人。删除 Crashlytics 不是一种选择。我也不希望每次我要进行一些调试时都禁用它,然后再次启用它。

"Apply Changes and Restart Activity" 按钮起作用。我正在使用的 Activity 重新启动并且可以看到更改。我尝试将此时间与使用常规 "Run" 按钮进行比较。 "Apply Changes and Restart Activity" 需要同样长的时间。唯一的好处似乎是,我不必每次都通过应用程序导航到那个屏幕,我可以留在那个屏幕上并重新加载更改。这是一个很好的好处,我只是期待更多。

我可以做些什么来让 "Apply Changes" 更有效地为我工作?

您可以在 Crashlytics 中为调试版本关闭此行为:https://docs.fabric.io/android/crashlytics/build-tools.html#optimize-builds-when-you-re-not-proguarding-or-using-beta-by-crashlytics

debug 块中 build.gradle 模块中将 ext.alwaysUpdateBuildId 设置为 false

android {
    buildTypes {
        debug {
          // Only use this flag on builds you don't proguard or upload to beta-by-crashlytics
          ext.alwaysUpdateBuildId = false