Status Update
Comments
vi...@google.com <vi...@google.com>
je...@google.com <je...@google.com>
im...@google.com <im...@google.com> #2
I reproduced this issue locally and it looks related to databinding:
app/build/generated/source/kapt/debug/com/example/dbigle/DataBinderMapperImpl.java:10: error: cannot find symbol
import com.example.dbigle.databinding.MainFragmentBindingImpl;
^
symbol: class MainFragmentBindingImpl
location: package com.example.dbigle.databinding
da...@google.com <da...@google.com> #3
Yigit, I suspect you know quicker than I do what to dupe this bug against. (This seems related to all the generic fixes made recently to data binding).
da...@google.com <da...@google.com> #4
Note, relevant code is (I believe) the state
value referenced in the view model:
class MainViewModel : ViewModel() {
private val _state = MutableLiveData<UiState<Boolean>>()
val state: LiveData<UiState<Boolean>>
get() = _state
an...@gmail.com <an...@gmail.com> #5
If I pass the state
value as a separate variable
(in XML layout) an adjust the references or use a non-generic type then it generates code that compiles (with AGP > 3.5.0).
Looking at what was generated in the failing case for executeBindings
(LoadingStateBindingImpl.java
)
// 3.5.0
com.example.dbigle.ui.main.UiState state = mState;
// 3.6.1
com.example.dbigle.ui.main.UiState<?> state = mState;
But perhaps more interesting is that the references to state
are missing in BR.java
and DataBinderMapperImpl.java
ro...@gmail.com <ro...@gmail.com> #6
I have reported a similar issue which feels ridiculous. Have you tried changing the name of the variable to something else? In my case when I have changed it from "birthday" to "birthday_" the code compiles.
an...@gmail.com <an...@gmail.com> #7
I don't think this is a duplicate of 152781831, I tried renaming according to your suggestion, it did not work. I think the error message is the same purely down to the non-specificity of data binding errors.
[Deleted User] <[Deleted User]> #8
I have a similar issue. It looks the change actually happened in 3.5.1 and the databinding compiler tries to generate code with generic wildcards instead of removing generics and the generated type doesn't match up with the Kotlin interop type.
In my case, 3.5.0, for example, generated a value Function2
but 3.5.1 tries to generate Function2<String, Result<? extends ?, ? extends Exception>, Data>
, which fails. If I use @JvmSupressWildcards
on the Result<@JvmSuppressWildcards T, Exception>
type, the generated code changes to Result<?, ? extends Exception>
which seems correct, but then it doesn't match up with the value accessed later in the Impl file.
The error then is at viewModelValue = viewModel.getValue()
and the Kotlin type from getValue()
resolves to Result<? extends capture of ?, ? extends Exception>
instead of Result<?, ? extends Exception>
.
So it looks like either generics should be erased, or the types resolved by Kotlin interop will need to be fixed.
yb...@google.com <yb...@google.com> #9
can you share the layout file? we had to make some backwards incompatible changes to ensure we keep types longer. you may just need to define the generic types in the XML
an...@gmail.com <an...@gmail.com> #10
Hi YB (state
as a separate variable
in the layout.
yb...@google.com <yb...@google.com> #11
sorry my bad. i'm looking into it.
yb...@google.com <yb...@google.com> #12
So what is happening here is that the imported layout does not declare a type for state so it gets resolved as UIState<T> (T is unresolved type variable).
Then when we try to check if viewModel.state
can be set to it, we call to java processing's isAssignable
API with:
Can UIState<Boolean>
be assigned to UIState<T>
which returns false
.
Previously we used to drop type args to be more flexible (we would drop Boolean ) which caused other issues.
It is unfortunate not to be able to reply on javax.model API for assignability but i think a possible "proper" fix is to manaully implement assignability where undefined type variables are ignored.
Another quick hack would be to accept erasure assignability albeit with a lower score of confidence such that we'll accept it if there is no better match, which won't break exact match cases but might cause some false positive cases.
yb...@google.com <yb...@google.com> #13
also TIL, java is completely happy with these :(
List l;
List<String> stringList = new ArrayList<String>();
l = stringList;
l.add(3);
System.out.println("all cool" + Arrays.toString(stringList.toArray()));
also fine with this:
List l = new ArrayList();
List<String> stringList = new ArrayList<String>();
stringList = l;
yb...@google.com <yb...@google.com> #14
i merged a fix where we'll accept assigning List<T> to List but not List to List<T>.
Even though it is inconsistent w/ java, accepting List for List<T> has too many complications.
It should be released in 4.2-canary-8
[Deleted User] <[Deleted User]> #15
Is there an ETA on the 4.2-canary-8?
an...@gmail.com <an...@gmail.com> #16
[Deleted User] <[Deleted User]> #17
Yup, thanks.
Description
AI-192.7142.36.36.6241897, JRE 1.8.0_212-release-1586-b04x64 JetBrains s.r.o, OS Windows 10(amd64) v10.0 , screens 1920x1200, 1920x1080
AS: 3.6.1; Kotlin plugin: 1.3.70-release-Studio3.6-1; Android Gradle Plugin: 3.6.1; Gradle: 5.6.4; NDK: from local.properties: (not specified), latest from SDK: 21.0.6113669; LLDB: LLDB 3.1 (revision: 3.1.4508709); CMake: from local.properties: (not specified), latest from SDK: 3.10.2, from PATH: (not found)
I have noticed that since AS 3.5.1 and it's concomitant AGP (3.5.1) projects that contain an included layout referencing a LiveData of a generic type would no longer compile.
I link here an example on GitHub:
The `master` branch uses AGP 3.5.0 and compiles and runs, the `failure` branch targets AGP 3.6.1 and fails to build.
I'm currently putting of upgrading AGP (in the affected projects) due to this issue, but I cannot do so indefinitely so if this is a permanent change then may I ask for recommended alternatives?