Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-drawable prioritized over drawable leading to ResourceNotFoundException #73

Closed
benjaminRomano opened this issue May 7, 2019 · 2 comments

Comments

@benjaminRomano
Copy link

Describe the bug
We recently ran into an issue where our LDPI and MDPI split apks, woud have a drawable resourceId with no entries like so

id name ldpi mdpi hdpi
0x7f08014b camera_flip_icon

The root cause was that an attribute (which has no defined density) was prioritized over a drawable with density. Specifically, the first resource defined in the tableEntry below was chosen:

entry_id {
  id: 331
}
name: "camera_flip_icon"
visibility {
  source {
  }
}
config_value {
  config {
  }
  value {
    source {
      path_idx: 39
      position {
        line_number: 4211
      }
    }
    item {
      str {
      }
    }
  }
}
config_value {
  config {
    density: 160
  }
  value {
    source {
      path_idx: 994
    }
    item {
      file {
        path: "res/drawable-mdpi-v4/camera_flip_icon.webp"
      }
    }
  }
}
config_value {
  config {
    density: 240
  }
  value {
    source {
      path_idx: 995
    }
    item {
      file {
        path: "res/drawable-hdpi-v4/camera_flip_icon.webp"
      }
    }
  }
}
config_value {
  config {
    density: 320
  }
  value {
    source {
      path_idx: 996
    }
    item {
      file {
        path: "res/drawable-xhdpi-v4/camera_flip_icon.webp"
      }
    }
  }
}
config_value {
  config {
    density: 480
  }
  value {
    source {
      path_idx: 997
    }
    item {
      file {
        path: "res/drawable-xxhdpi-v4/camera_flip_icon.webp"
      }
    }
  }
}
config_value {
  config {
    density: 640
  }
  value {
    source {
      path_idx: 998
    }
    item {
      file {
        path: "res/drawable-xxxhdpi-v4/camera_flip_icon.webp"
      }
    }
  }
}

The reason this strange resource exists within our tableEntry for camera_flip_icon is because one of our modules referenced a drawable within another module without depending on that module. This would work since the correct entry would be defined in resources table when the apk is assembled. Specifically, we had the following code:

<resources>
    <item name="camera_flip_icon" type="drawable"/>
</resources>

Bundletool version(s) affected
Version: 0.9.0

Stacktrace
Copy all of the output of the command, including the stacktrace if visible.

To Reproduce
Create modules A,B,C where both B and C are dependencies of A. Create xxxhdpi drawable in module C and reference from within module B using manually defined item. LDPI split should have no entries for the given drawable.

   A
 /   \
B    C

Expected behavior
I would expect either of the following behaviors:

  1. Crash when this situation occurs
  2. Always prefer config value with a specified density over one with non-density (this would be more consistent behavior with assemble task)
@plecesne
Copy link
Contributor

plecesne commented May 9, 2019

That's a reasonable request.

Although what bundletool is doing is technically correct since the default density is the same as the mdpi density so specifying both resources can lead to indeterminism, it seems that a few developers are getting confused by this, so we should address this.

@benjaminRomano
Copy link
Author

benjaminRomano commented May 9, 2019

Yep, I'd expect indeterministic behavior in this scenario. When I found this code, I was surprised it even worked 🙂

Ideally it would fail sooner since this type of issue can be a bit tricky to debug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants