bugsnag / bugsnag-android-gradle-plugin

Gradle plugin for BugSnag which uploads ProGuard, DexGuard and NDK mapping files, and sends build notifications
https://docs.bugsnag.com/build-integrations/gradle/
MIT License
70 stars 38 forks source link

API Key stored in resources no longer works #442

Closed deecewan closed 3 years ago

deecewan commented 3 years ago

Describe the bug

We currently have @string/BUGSNAG_API_KEY in our AndroidManifest.xml, and this string resource value is generated at build time based on what variant we're using. This failure happens when the string is static in strings.xml, too, tho.

In v5.7.8, this worked as expected. In v5.8.0, this results in

{"errors":["API key not recognised: @string/BUGSNAG_API_KEY"],"status":"error"}

being generated when running the bugsnagRelease<variant>Task.

I imagine that this plugin is parsing the AndroidManifest.xml before it's been fully merged? Unsure.

Steps to reproduce

  1. Add bugsnag-android-gradle-plugin v5.8.0 to a project
  2. Use a string resource for the key
  3. Run a ./gradlew assembleRelease
  4. Hit errors.

Environment

Example Repo

dentuzhik commented 3 years ago

I can confirm that downgrading and fixing the version to 5.7.8 makes our CI pass again.

luke-belton commented 3 years ago

Hi @deecewan - we're taking a look at this, but as you suggest fixing the version at 5.7.8 for now should resolve the issue!

deecewan commented 3 years ago

yep - we've downgraded for now.

johnkiely1 commented 3 years ago

Hi @deecewan

We have now released v5.8.1 which should reverse a fix that we added which had the effect of breaking it when using the API key with a resource value e.g. @string/BUGSNAG_API_KEY.

For now you could upgrade to v5.8.1 which should restore previous behaviour.

More generally, while it works in certain circumstances, inserting the API key via a resource file is not a technique that we recommend as it’s a runtime mechanism that is resolved by a running app, but there is no reliable API available to do this at build time. Instead we document and recommend that the API key – and other configuration values – are controlled via manifest placeholders and build variants. See our online documentation for details.

However it is probable that in the next major release of the Bugsnag Android Gradle Plugin, we will no longer allow it. Therefore you might wish to consider changing approaches for inserting the API key configuration option in the future.

deecewan commented 3 years ago

@johnkiely1 yep - i ended up changing to manifest placeholders as the docs suggest. mostly opened the issue because it was a breaking change where i didn't expect a breaking change.