Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm using Android Studio 3.5 Beta 1. I decided to try out "Apply Changes". Instant Run was problematic, so we've had it disabled for years. I hoped that this would work better.

If I try the "Apply Code Changes" button, I get an error in the Run 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 has comments that say

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

And indeed, it has a build_id property that presumably changes for every Gradle build. And since Gradle runs a build whenever I use the "Apply Code Changes" or "Apply Changes and Restart Activity" buttons, the Gradle build changes the file, which prevents Apply Run from completing.

The only information I've found online related to this was one Reddit comment saying

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

So it would seem I'm not the only person with this problem. Removing Crashlytics isn't an option. Nor would I want to disable it every time I'm going to do some debugging, then re-enable it again.

The "Apply Changes and Restart Activity" button does function. The Activity I'm using restarts and changes are visible. I tried comparing the timing of this to using the regular "Run" button. "Apply Changes and Restart Activity" takes just as long. The only benefit seems to be that instead of having to navigate through the app to that screen each time, I can remain on that screen and reload the changes. That is a nice benefit, I just expected more.

Is there anything I can do to make "Apply Changes" work more effectively for me?

like image 348
Chad Schultz Avatar asked May 13 '19 18:05

Chad Schultz


People also ask

How to change build variant in Android Studio?

Change the build variant By default, Android Studio builds the debug version of your app, which is intended for use only during development, when you click Run. To change the build variant Android Studio uses, select Build > Select Build Variant in the menu bar.

Why does Android studio take so long?

If Android Studio has a proxy server setting and can't reach the server then it takes a long time to build, probably its trying to reach the proxy server and waiting for a timeout. When I removed the proxy server setting its working fine.


1 Answers

You can turn off this behavior for debug builds in Crashlytics: https://docs.fabric.io/android/crashlytics/build-tools.html#optimize-builds-when-you-re-not-proguarding-or-using-beta-by-crashlytics

Set ext.alwaysUpdateBuildId to false in your module build.gradle in debug block:

android {
    buildTypes {
        debug {
          // Only use this flag on builds you don't proguard or upload to beta-by-crashlytics
          ext.alwaysUpdateBuildId = false
like image 171
Jon T Avatar answered Oct 04 '22 05:10

Jon T