(#) Right-to-left text compatibility issues !!! ERROR: Right-to-left text compatibility issues This is an error. Id : `RtlCompat` Summary : Right-to-left text compatibility issues Severity : Error Category : Internationalization: Bidirectional Text Platform : Android Vendor : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 Since : Initial Affects : Kotlin and Java files, manifest files and resource files Editing : This check runs on the fly in the IDE editor Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/RtlDetector.java) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/RtlDetectorTest.java) Copyright Year : 2017 API 17 adds a `textAlignment` attribute to specify text alignment. However, if you are supporting older versions than API 17, you must **also** specify a gravity or layout_gravity attribute, since older platforms will ignore the `textAlignment` attribute. !!! Tip This lint check has an associated quickfix available in the IDE. (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text res/layout/relative.xml:10:Error: To support older versions than API 17 (project specifies 5) you should also add android:layout_alignParentLeft="true" [RtlCompat] android:layout_alignParentStart="true" ------------------------------- res/layout/relative.xml:13:Error: To support older versions than API 17 (project specifies 5) you should also add android:layout_marginLeft="40dip" [RtlCompat] android:layout_marginStart="40dip" -------------------------- res/layout/relative.xml:24:Error: To support older versions than API 17 (project specifies 5) you should also add android:layout_marginLeft="40dip" [RtlCompat] android:layout_marginStart="40dip" -------------------------- res/layout/relative.xml:26:Error: To support older versions than API 17 (project specifies 5) you should also add android:layout_toRightOf="@id/loading_progress" [RtlCompat] android:layout_toEndOf="@id/loading_progress" ---------------------- res/layout/relative.xml:29:Error: To support older versions than API 17 (project specifies 5) you should also add android:paddingRight="120dip" [RtlCompat] android:paddingEnd="120dip" ------------------ res/layout/relative.xml:37:Error: To support older versions than API 17 (project specifies 5) you should also add android:layout_alignParentLeft="true" [RtlCompat] android:layout_alignParentStart="true" ------------------------------- res/layout/relative.xml:38:Error: To support older versions than API 17 (project specifies 5) you should also add android:layout_alignRight="@id/text" [RtlCompat] android:layout_alignEnd="@id/text" ----------------------- res/layout/relative.xml:47:Error: To support older versions than API 17 (project specifies 5) you should also add android:layout_alignLeft="@id/cancel" [RtlCompat] android:layout_alignStart="@id/cancel" ------------------------- res/layout/relative.xml:48:Error: To support older versions than API 17 (project specifies 5) you should also add android:layout_alignRight="@id/cancel" [RtlCompat] android:layout_alignEnd="@id/cancel" ----------------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: `res/layout/relative.xml`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ProgressBar android:id="@+id/loading_progress" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:layout_marginBottom="60dip" android:layout_marginStart="40dip" android:layout_marginTop="40dip" android:max="10000" /> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignWithParentIfMissing="true" android:layout_marginBottom="60dip" android:layout_marginStart="40dip" android:layout_marginTop="40dip" android:layout_toEndOf="@id/loading_progress" android:ellipsize="end" android:maxLines="3" android:paddingEnd="120dip" android:text="@string/creating_instant_mix" android:textAppearance="?android:attr/textAppearanceMedium" /> <Button android:id="@+id/cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_alignEnd="@id/text" android:layout_below="@id/text" android:background="@null" android:text="@string/cancel" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/cancel" android:layout_alignStart="@id/cancel" android:layout_alignEnd="@id/cancel" android:scaleType="fitXY" android:src="@drawable/menu_list_divider" /> </RelativeLayout> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/RtlDetectorTest.java) for the unit tests for this check to see additional scenarios. The above example was automatically extracted from the first unit test found for this lint check, `RtlDetector.testRelativeLayoutCompat`. To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=192708. (##) Suppressing You can suppress false positives using one of the following mechanisms: * Adding the suppression attribute `tools:ignore="RtlCompat"` on the problematic XML element (or one of its enclosing elements). You may also need to add the following namespace declaration on the root element in the XML file if it's not already there: `xmlns:tools="http://schemas.android.com/tools"`. * Using a suppression annotation like this on the enclosing element: ```kt // Kotlin @Suppress("RtlCompat") fun method() { problematicStatement() } ``` or ```java // Java @SuppressWarnings("RtlCompat") void method() { problematicStatement(); } ``` * Using a suppression comment like this on the line above: ```kt //noinspection RtlCompat problematicStatement() ``` * Using a special `lint.xml` file in the source tree which turns off the check in that folder and any sub folder. A simple file might look like this: ```xml <?xml version="1.0" encoding="UTF-8"?> <lint> <issue id="RtlCompat" severity="ignore" /> </lint> ``` Instead of `ignore` you can also change the severity here, for example from `error` to `warning`. You can find additional documentation on how to filter issues by path, regular expression and so on [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). * In Gradle projects, using the DSL syntax to configure lint. For example, you can use something like ```gradle lintOptions { disable 'RtlCompat' } ``` In Android projects this should be nested inside an `android { }` block. * For manual invocations of `lint`, using the `--ignore` flag: ``` $ lint --ignore RtlCompat ...` ``` * Last, but not least, using baselines, as discussed [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).