0

How can I deal with the Baseline Profile generation when I have different code running depending on the device?

For example, I have some kind of method like this:

public static String runCode() {
    if (Utils.isTablet()) {
        doSomethingTablet();
    } else {
        doSomethingPhone();
    }
}

If I run the BaselineProfileGenerator and use a phone to generate the BP file, the doSomethingTablet() wouldn't be recorded unless I run the generator on a Tablet. If I run it separately I'll have two different baselines files. How Can I organize them or join the content of those files?

Carlos Lopez
  • 133
  • 4

1 Answers1

0

There are several options here.

If you don't want to be dependent on a device type you run the generators on, you can create multiple build flavors and "inject" some state to override the default behavior (e.g. with BuildConfig). This way you can run the same generator for each build flavor resulting in different exercised code paths.

Assuming you would run multiple generators and had several profiles With AGP 8.0+ you can have multiple baseline profile files in src/[variant|main]/baselineProfile/*.txt directory which are all merged during build. You don't have to have the profile in src/main/baseline-prof.txt anymore (it's kept for backwards compatibility).

If you need to have a different interactions in the generators, you can write a generator in custom variant as well.

Btw, I recommend checking the newly released Baseline Profiles Gradle Plugin that automates copying the generated rules and have the options to define when and how the generated rules are copied, merged or even filtered.

mlykotom
  • 4,850
  • 1
  • 22
  • 27