Status Update
Comments
uc...@google.com <uc...@google.com>
to...@gmail.com <to...@gmail.com> #2
Small bump for Tor :) Still the case with AGP 4.1 and now that CL 2.0 is out it triggers a lot more false warnings as this is used a lot more.
Following example will trigger unused id view1 when it's actually used.
<Space
android:id="@+id/view1"
android:layout_width="0dp"
android:layout_height="0dp" />
<androidx.constraintlayout.helper.widget.Flow
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="view1"
app:flow_maxElementsWrap="3"
app:flow_wrapMode="aligned" />
tn...@google.com <tn...@google.com> #3
Fixed by Change-Id: Id116185535fc955bc7de091e318cdcd7bbd00343 for 4.2. Also considering cherry-pick into 4.1 RC. Thanks for the bump and sorry for the delay.
w....@futuremind.com <w....@futuremind.com> #4
When we use lint
gradle command (gradlew :app:lint
) then we receive exactly the same issue:
Error: This view is not constrained. It only has designtime positions,
so it will jump to (0,0) at runtime unless you add the constraints [MissingConstraints]
Tested with Android Gradle Plugin 4.1.2
and 4.2.0-beta04
tn...@google.com <tn...@google.com> #5
Is there any way you can create a reproducible scenario for this?
w....@futuremind.com <w....@futuremind.com> #6
The simplest reproductible scenario in Android Studio 4.1.2 (but probably also in 4.2.0-beta04) is:
- Create a new project with Empty Activity
- Modify
activity_main
layout to useFlow
withconstraint_referenced_ids
and remove unnecessary constraints fromTextView
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.constraintlayout.helper.widget.Flow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="someTextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/someTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</androidx.constraintlayout.widget.ConstraintLayout>
- In terminal run
gradlew :app:lint
tn...@google.com <tn...@google.com> #7
Thanks for the repro project! I can reproduce this in 4.2 but not in 7.0. Let me see if I can find the fix and evaluate whether it's safe enough to put into 4.2.
tn...@google.com <tn...@google.com> #8
Uhm no, that fix is way too risky this late in the 4.2 cycle; it basically switched us over from batch collection of id declarations to using the resource repository -- it's a 4000+ line plus CL (
I think what I'll do for 4.2 is to try to disable part or all of that check.
tn...@google.com <tn...@google.com> #9
Actually, I went to look into this and I realized that we're talking about different things.
This bug was about the unused resource detector not realizing that a view referenced from a constraint_referenced_ids attribute is actually used.
However, the bug I reproduced with your example is a separate one, the MissingConstraints one, which complains if you haven't both horizontally and vertically constrained your id.
I've filed a new bug to track this, here:
Marking this (unused resource handling for constraint_referenced_ids again).
Description
Lint unused id does not take in account constraint layout constraint_referenced_ids but should as it's an hard used reference and Support Libraries are quite common libraries. (And CL 2.0 will offer way more attributes to link to other ids)
tested with AGP 3.2.0-alpha15