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

How to configure ACRA Dialog in Android Gradle Plugin v5 compatible way? #810

Closed
mikehardy opened this issue Oct 13, 2020 · 3 comments · Fixed by #813
Closed

How to configure ACRA Dialog in Android Gradle Plugin v5 compatible way? #810

mikehardy opened this issue Oct 13, 2020 · 3 comments · Fixed by #813

Comments

@mikehardy
Copy link
Contributor

Required reading
https://github.com/ACRA/acra/wiki/How-to-debug-ACRA

Describe the bug
The annotation style of configuring ACRA recommends using annotations set to 'R' values, but Android Gradle Plugin v5 will apparently have non-constant 'R' values, meaning a different style is needed

For instance, this will throw a new deprecation warning:


@AcraDialog(
        reportDialogClass = AnkiDroidCrashReportDialog.class,
        resCommentPrompt =  R.string.empty_string,
        resTitle =  R.string.feedback_title,
        resText =  R.string.feedback_default_text,
        resPositiveButtonText = R.string.feedback_report,
        resIcon = R.drawable.logo_star_144dp
)
@AcraHttpSender(
        httpMethod = HttpSender.Method.PUT,
        uri = BuildConfig.ACRA_URL
)
@AcraToast(
        resText = R.string.feedback_auto_toast_text
)

It is a new deprecation in Android Gradle Plugin 4.1

Avoid the usage of resource IDs where constant expressions are required.

A future version of the Android Gradle Plugin will generate R classes with
non-constant IDs in order to improve the performance of incremental compilation.

It may be suppressed temporarily like so:

@SuppressLint("NonConstantResourceId")

In a similar context in Java, the recommendation is to alter code from switch with cases using the 'R' values (which I suppose must be constant to work in case statements?) to chained if: https://issuetracker.google.com/issues/159878591#comment13

But I'm not sure what transformation to use for annotations. In the connected issue where Butterknife (which also takes config as annotations that use R values) they simply say "don't use Butterknife", so that's not helpful.

Perhaps a switch to specifying the name of the resource, then ACRA does the id lookup and uses it? https://developer.android.com/reference/android/content/res/Resources.html#getIdentifier(java.lang.String,%20java.lang.String,%20java.lang.String)

Expected behavior
No deprecation warnings with recommended initialization style

Version

  • Android Gradle Plugin 4.1.0
  • ACRA 5.7.0
mikehardy added a commit to mikehardy/Anki-Android that referenced this issue Oct 13, 2020
The future Android Gradle Plugin v5 will apparently generate non-final
resource references, which makes them unsuitable for use in switch statements

The recommended transformation is to chained-if statements:
https://issuetracker.google.com/issues/159878591#comment13

Usage of resource references in annotations is a similar problem but does
not have a recommended transformation yet. I logged upstream issue:
ACRA/acra#810
mikehardy added a commit to mikehardy/Anki-Android that referenced this issue Oct 13, 2020
The future Android Gradle Plugin v5 will apparently generate non-final
resource references, which makes them unsuitable for use in switch statements

The recommended transformation is to chained-if statements:
https://issuetracker.google.com/issues/159878591#comment13

Usage of resource references in annotations is a similar problem but does
not have a recommended transformation yet. I logged upstream issue:
ACRA/acra#810
@F43nd1r
Copy link
Member

F43nd1r commented Oct 13, 2020

ugh.

I'll probably just opt for deprecating the annotation configuration in favor of an improved kotlin dsl/java builder.

@mikehardy
Copy link
Contributor Author

As a library consumer the configuration by annotation is interesting but I don't mind having to configure an object with a builder

On the plus side, it's deprecation for a future version and the deprecation warning was added just days ago. I'm just suppressing lint right now (we normally abort on deprecation so we're forced to proactively suppress and then track them honestly in our issue tracker)

mikehardy added a commit to ankidroid/Anki-Android that referenced this issue Oct 14, 2020
The future Android Gradle Plugin v5 will apparently generate non-final
resource references, which makes them unsuitable for use in switch statements

The recommended transformation is to chained-if statements:
https://issuetracker.google.com/issues/159878591#comment13

Usage of resource references in annotations is a similar problem but does
not have a recommended transformation yet. I logged upstream issue:
ACRA/acra#810
@benardelia
Copy link

This is much impacted as i have large old kotlin project which half of its classes uses butterknife, its in a point where i couldn't change the style of stop using R value where the constant values required

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

Successfully merging a pull request may close this issue.

3 participants