oppia-android: [BUG]: Fix all Android lint failures.

Describe the bug

We would like to fix all the remaining lint issues on Oppia Android. There are currently 195 errors and 1009 warnings. Also, 38 checks are currently disabled.

We’d like to get rid of all these errors and then enable all the lint checks fully on CI (see https://github.com/oppia/oppia-android/issues/1742).

Steps To Reproduce

Run the following command from a terminal in a checked-out Oppia Android repo:

./gradlew :app:lint

Expected Behavior

Running the command above should not show any errors.

Screenshots/Videos

This is the first part of the error report:

Screenshot from 2023-10-02 00-44-03

Project Organization

This project can be divided into multiple parts. Please specify which part you want to take up and show a screenshot of a lint report with no errors for the corresponding issues in order to claim a part (and make a PR for it). Also, explain your general approach to fixing the errors for the part you claimed (don’t just suppress the errors).

The relevant parts are listed below:

  • #5195
  • #5186
  • #5230
  • VectorRaster
  • #5273
  • #5204
  • ObsoleteLintCustomCheck
  • DefaultLocale + OldTargetApi + UnknownIdInLayout + GradleDependency
  • MissingTranslation + ExtraTranslation
  • #5231
  • #5272
  • UnusedResources
  • #5261
  • MergeRootFrame
  • #5194
  • #5171
  • #5182
  • Explicitly unsuppress the following disabled checks and fix any violations: AppLinksAutoVerifyError, AppLinksAutoVerifyWarning, BackButton, ConvertToWebp, DalvikOverride
  • Explicitly unsuppress the following disabled checks and fix any violations: DuplicateStrings, EasterEgg, FieldGetter, GoogleAppIndexingApiWarning, GoogleAppIndexingWarning
  • Explicitly unsuppress the following disabled checks and fix any violations: IconExpectedSize, ImplicitSamInstance, KotlinPropertyAccess, LambdaLast, LockedOrientationActivity
  • Explicitly unsuppress the following disabled checks and fix any violations: LogConditional, MangledCRLF, MinSdkTooLow, MissingRegistered, NegativeMargin
  • Explicitly unsuppress the following disabled checks and fix any violations: NewerVersionAvailable, NoHardKeywords, NonResizeableActivity, PermissionImpliesUnsupportedChromeOsHardware, Registered
  • Explicitly unsuppress the following disabled checks and fix any violations: RequiredSize, SelectableText, SourceLockedOrientationActivity, StopShip, SyntheticAccessor
  • Explicitly unsuppress the following disabled checks and fix any violations: TypographyQuotes, UnknownNullness, UnpackedNativeCode, UnsupportedChromeOsCameraSystemFeature
  • Explicitly unsuppress the following disabled checks and fix any violations: UnsupportedChromeOsHardware, UnusedIds, ValidActionsXml, WrongThreadInterprocedural

About this issue

  • Original URL
  • State: open
  • Created 9 months ago
  • Comments: 32 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Hi @adhiamboperes, i would like to work on UnusedAttribute Warning is happening due to min. sdk version specified in the gradel.build is 19. We can change it to 29 and avoid those warnings.

Hi @pingu-73, at the moment, we are unable to update the minSdk version. That removes support for older devices as well as will need a lot of work to verify compatibility with other libraries in the repo(we have a lot!). Could you please suggest another solution? For example, can you identify these unused attributes, and see if we can address each on a case by case basis?

Hi @adhiamboperes Another Approach: we can add checks using dataBindings for example: Screenshot 2023-12-14 at 3 58 00 PM

Screenshot 2023-12-14 at 4 04 31 PM Screenshot 2023-12-14 at 3 55 20 PM

Hi @aryanmishra29, an easy way to repro the issue is to navigate to Code -> Inspect Code.

image

Then check on Whole Project and click on Analyze.

image

Hi @adhiamboperes, I’ve found a solution of this issue: RestrictedApi

class AppCompatCheckBoxBindingAdapters has an error:

AppCompatCheckBox.setSupportButtonTintList can only be called from within the same library group prefix (referenced groupId=androidx.appcompat with prefix androidx from groupId=oppia-android)

The reason is using a private API. To resolve it, we can use:

CompoundButtonCompat.setButtonTintList(@NonNull CompoundButton button, @Nullable ColorStateList tint)

Here is a screen of lint report Before

restricted-api-before.png

After

restricted-api-after.png

Hi @adhiamboperes,

I would like to continue to work on - All warnings in "Usability:Typography", "Usability:Icons", and "Usability" categories task.

The issues can be categorized as:

  1. Borderless Buttons
  2. OK text capitalization
  3. Ellipsis/Hyphen unicode replacement
  4. Image in density drawable folder
  5. Text size too small
  6. To incorporate Autofill

Fix:

  1. Borderless Buttons: Added style="?android:attr/buttonBarButtonStyle" to implement borderless buttons as suggested.
  2. OK Text Capitalization: Capitalized the text in string resources, changing “ok” to "OK" for better consistency.
  3. Ellipsis/Hyphen Unicode Replacement: Used Unicode values to replace … and - instances in Arabic translations, and added tools:ignore="TypographyDashes" where Unicode couldn’t be applied.
  4. Image in Density Drawable Folder: Created and reallocated density images to appropriate folders such as
  • drawable-hdpi
  • drawable-mdpi
  • drawable-xhdpi
  • drawable-xxhdpi
  • drawable-xxxhdpi.
  1. Text Size Too Small: Increased text size to 12sp, as recommended, from the previous size of 10sp.
  2. Incorporating Autofill: Added autofill hint text to the Feedback Edit Text.

I have the code changes in my forked repository [Link1][Link 2] for your review and have attached before-and-after screenshots.

Screenshots Before After Usability Lint Issues If this solution aligns with the project’s requirements, I’d appreciate it if you could assign the task to me so I can proceed with making a pull request.

Thank you!

Best regards, RD [Rama Devi]

InvalidPackage + NewApi + FragmentLiveDataObserve + RestrictedApi

Hi @BenHenning, I would like to work in this part. There is a compile-time error on line 231 in class ControlButtonsViewModel.

Call requires API level 26 (current min is 19): java.util.Base64#getEncoder

I can solve this error by:

  1. using if-else operator. If API 26 and higher use java.util.Base64 class else use android.util.Base64 class

     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
         Base64.getEncoder().encodeToString(compressedMessage)
     } else {
         android.util.Base64.encodeToString(compressedMessage, 0)
     }
    
  2. android.util.Base64 has encodeToString as equivalent of getEncoder().encode(args) it both Passing DEFAULT results in output that adheres to RFC 2045. So I can try to return right away:
    return android.util.Base64.encodeToString(compressedMessage, 0)

Hi @adhiamboperes,

I am a new contributor to oppia-android and would like to start my contributions with the project. I’ve signed the CLA, filled out the survey form, and set up the environment locally. After some initial exploration, I believe I can assist with some lint issues.

I’d like to begin with the task related to All warnings in "Internationalization" While working on it locally, I encountered two types of issues:

  • hardcoded text
  • padding/margins.

Fix:

  • I’ve resolved the hardcoded text issue by assigning string resource values and
  • Addressed the padding issues by setting padding end values.

I have the code changes in my forked repository [Link] for your review and have attached before-and-after screenshots.

Screenshots: Lint Issues Internationalization Before After

If this solution aligns with the project’s requirements, I’d appreciate it if you could assign the task to me so I can proceed with making a pull request.

Thank you!

Best regards, RD [Rama Devi]

  • MissingDefaultResource + AppCompatCustomView + FragmentTagUsage

Hi @adhiamboperes, I would like to work on this next.

  1. MissingDefaultResource mainly has a single issue with a string which has different names in english and other translations. It can be easily fixed, by matching the name of that string in english and other translations.
  2. For AppCompatCustomView, it can be fixed by replacing the Normal views with AppCompat views
  3. <fragment/> tags can be replaced with <androidx.fragment.app.FragmentContainerView/>.
  • All warnings in “Accessibility” category

Hi @adhiamboperes, I would like work on this part. Under this category, the warnings are mainly of 3 types.

  1. Warning: Image without contentDescription. Fix: Add a contentDescription to each of those ImageView.

  2. Warning: ‘onTouch’ lambda should call ‘View#performClick’ when a click is detected Fix: Call customView.performClick( ).

  3. Warning: ‘clickable’ attribute found, please also add ‘focusable’. Fix: Set android:focusable="false" as it is a button.