Status Update
Comments
yb...@google.com <yb...@google.com> #2
actually this seems to be failing because we are getting pre-compiled java classes where parameter names are replaced with argXXX.
if this is not fixable, we can make room incremental compilation kotlin only?
da...@google.com <da...@google.com> #3
This sounds like JDK bug we are suppose to identify and turn off incremental AP if the JDK is not the correct one.
Can you check you are seeing this in command-line builds (not in Android Studio)?
Which JDK are you on?
Can you reproduce if you pass to javac the -parameters
flag? Something like:
tasks.withType(JavaCompile) {
options.compilerArgs << "-parameters"
}
yb...@google.com <yb...@google.com> #4
it is command line build:
➜ support git:(room-pixelc-crash) ✗ java -version
openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Debian-3deb10u1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Debian-3deb10u1, mixed mode, sharing)
i'll try the parameters flag.
da...@google.com <da...@google.com> #5
Has you been able to observe this issue again Yigit? We will be turning ICAP by default in Room soon, so hopefully this is not an recurring issue.
yb...@google.com <yb...@google.com> #6
no i've not seen it again. we should turn on and add RELNOTE on how to disable it.
da...@google.com <da...@google.com> #7
Yup, it will be on the release notes.
jo...@gmail.com <jo...@gmail.com> #8
> Task :app:kaptDebugKotlin
error: Each bind variable in the query must have a matching method parameter. Cannot find method parameters for :referenceId. - queryLineItemsOfOrderLV(java.lang.String) in aaa.cubeup.cube.room.daos.LineItemDaoerror: Unused parameter: arg0 - queryLineItemsOfOrderLV(java.lang.String) in aaa.cubeup.cube.room.daos.LineItemDaoerror: Each bind variable in the query must have a matching method parameter. Cannot find method parameters for :referenceId. - queryOrder(java.lang.String) in aaa.cubeup.cube.room.daos.OrderDaoerror: Unused parameter: arg0 - queryOrder(java.lang.String) in aaa.cubeup.cube.room.daos.OrderDaoerror: Each bind variable in the query must have a matching method parameter. Cannot find method parameters for :referenceId. - queryOrderLV(java.lang.String) in aaa.cubeup.cube.room.daos.OrderDaoerror: Unused parameter: arg0 - queryOrderLV(java.lang.String) in aaa.cubeup.cube.room.daos.OrderDao
> Task :app:kaptDebugKotlin FAILED
Each bind variable in the query must have a matching method parameter. Cannot find method parameters for :referenceId. - queryLineItemsOfOrderLV(java.lang.String) in aaa.cubeup.cube.room.daos.LineItemDaoerror: Unused parameter: arg0 - queryLineItemsOfOrderLV(java.lang.String) in aaa.cubeup.cube.room.daos.LineItemDaoerror: Each bind variable in the query must have a matching method parameter. Cannot find method parameters for :referenceId. - queryOrder(java.lang.String) in aaa.cubeup.cube.room.daos.OrderDaoerror: Unused parameter: arg0 - queryOrder(java.lang.String) in aaa.cubeup.cube.room.daos.OrderDaoerror: Each bind variable in the query must have a matching method parameter. Cannot find method parameters for :referenceId. - queryOrderLV(java.lang.String) in aaa.cubeup.cube.room.daos.OrderDaoerror: Unused parameter: arg0 - queryOrderLV(java.lang.String) in aaa.cubeup.cube.room.daos.OrderDao
Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
> java.lang.reflect.InvocationTargetException (no error message)
The dao method for the last unmatched set is this:
@Transaction
@Query("SELECT * FROM order_object WHERE reference_id = :referenceId")
public abstract LiveData<OrderCube> queryOrderLV(String referenceId);
It consistently fails the first time I build after changing any of those files, but not with
"tasks.withType(JavaCompile) {
options.compilerArgs << "-parameters"
}"
I'm using AS4.2C4 and Room 2.3.0-alpha01
yb...@google.com <yb...@google.com> #9
#8, did you enable incremental compilation for room?
jo...@gmail.com <jo...@gmail.com> #10
da...@google.com <da...@google.com> #11
Switching to Kotlin is definitely a workaround since parameter names can be retrieved from the Kotlin metadata. But based on your description it does seem to be related to incremental. Were you seeing this when compiling both from Android Studio and the command line? Can you also share which JDK were you on when this happens?
hungnv@ would it also make sense for AGP to always add the '-parameters' flag to AGP? The only consequence is that the class files produced my be slightly bigger (due to the extra information).
jo...@gmail.com <jo...@gmail.com> #12
1. Change the text of a println in my abstract database class.
2. Use debug button (fails the first time)
3. Use debug button again (builds successfully)
I don't normally use command line so I'm sure this is right, but I the commands I tried with those steps were 'gradlew installDebug' and 'gradlew assembleDebug'.
Also, in studio it only fails the first time when i use the debug button. If I just rebuild it's always successful.
jo...@gmail.com <jo...@gmail.com> #13
This is the output from the two 'gradlew installDebug' runs.
JAVA_HOME:C:\Program Files\Java\jdk-11.0.7
WARNING: API 'BaseVariant.getApplicationIdTextResource' is obsolete and has been replaced with 'VariantProperties.applicationId'.
It will be removed in version 5.0 of the Android Gradle plugin.
For more information, see TBD.
To determine what is calling BaseVariant.getApplicationIdTextResource, use -Pandroid.debug.obsoleteApi=true on the command line to display more information.
> Task :app:kaptDebugKotlin
error: Each bind variable in the query must have a matching method parameter. Cannot find method parameters for :referenceId. - queryOrder(java.lang.String) in aaa.cubeup.cube.room.daos.OrderDaoerror: Unused parameter: arg0 - queryOrder(java.lang.String) in aaa.cubeup.cube.room.daos.OrderDaoerror: Each bin
d variable in the query must have a matching method parameter. Cannot find method parameters for :referenceId. - queryOrderLV(java.lang.String) in aaa.cubeup.cube.room.daos.OrderDaoerror: Unused parameter: arg0 - queryOrderLV(java.lang.String) in aaa.cubeup.cube.room.daos.OrderDao
> Task :app:kaptDebugKotlin FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
> java.lang.reflect.InvocationTargetException (no error message)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 9s
26 actionable tasks: 3 executed, 23 up-to-date
C:\Square\cube>gradlew installDebug
> Configure project :app
JAVA_HOME:C:\Program Files\Java\jdk-11.0.7
WARNING: API 'BaseVariant.getApplicationIdTextResource' is obsolete and has been replaced with 'VariantProperties.applicationId'.
It will be removed in version 5.0 of the Android Gradle plugin.
For more information, see TBD.
To determine what is calling BaseVariant.getApplicationIdTextResource, use -Pandroid.debug.obsoleteApi=true on the command line to display more information.
> Task :app:installDebug
Installing APK 'app-debug.apk' on 'SM-T510 - 10' for app:debug
Installed on 1 device.
BUILD SUCCESSFUL in 16s
33 actionable tasks: 7 executed, 26 up-to-date
C:\Square\cube>
hu...@google.com <hu...@google.com> #14
It's possible to add -parameters
to AGP (and Kapt) if we don't have a better solution.
However, it would be good to find out why we still see this bug with jdk-11.0.7, even though it has been fixed in JDK 11:
(Side note: The build succeeds after failing because after a failure the build is non-incremental and Gradle passes .java files where Room can access parameter names, whereas in an incremental build, Gradle passes .class files that could hide parameter names because of the above JDK bug.)
If possible, could you send us a sample project to investigate?
jo...@gmail.com <jo...@gmail.com> #15
Sure. Sorry it's not smaller. I didn't want to change daos or entities because I think the error is only caused by some and I'm not sure which.
github.com/jonolds/BindVariableIssue
Steps to reproduce:
- Build/run it.
- Stop the process.
- Change the println text in CatalogRoomDatabase
- Build/run again with the debug button (it should fail with bind error)
- Build again with the debug button and it builds
hu...@google.com <hu...@google.com> #16
Thanks a lot for the sample project, it really helps!
Here is the source file where it fails:
@Dao
public abstract class OrderDao {
@Transaction
@Query("SELECT * FROM order_object WHERE reference_id = :referenceId")
public abstract OrderZZZZ queryOrder(String referenceId);
...
}
Without passing -parameters
, the parameter name referenceId
will appear in OrderDao.class
as arg0
, therefore breaking incremental Room.
=====
For context, when we were designing incremental Room, we experimented with the following source file (see internal incremental Room design doc):
@Entity(tableName = "word_table")
public class Word {
private String mWord;
public Word(@NonNull String word) {
this.mWord = word;
}
}
In our experiment, JDK 11 (or a custom JDK version with the cherry-picked fix for .class
files, thereby allowing Room to be incremental. This bug is also covered by Room integration test: Incremental Room will fail on the not-cherry-picked JDK version and pass on the cherry-picked JDK version (
But your sample project shows that JDK 11 is not enough to have incremental Room.
hu...@google.com <hu...@google.com> #17
I think the next steps are:
- Add
-parameters
toJavaCompile
arguments. - Update Room integration test to cover the missing case (the first code snippet in
).comment #16 - Check if JDK 11 is still a requirement once
-parameters
is added, and remove it if it is no longer required.
Regarding (1), this can be done by AGP, by Room users, or by a small Room Gradle plugin:
1a. Done by AGP: My concern for adding -parameters
in AGP is that there are a couple of good reasons why parameter names are not added by default to the class files, e.g. as discussed here:
(Btw, it's easy to add it in AGP, but will be difficult to remove if something comes up later that requires us to remove it, because it would break those who rely on the new behavior, including Room.)
Once done in AGP, Room then needs to check the AGP version to see if it is high enough for Room to be incremental. This requires AGP to pass its version to Room (pending
1b. Done by Room users: When enabling incremental Room, Room users need to also add -parameters
to JavaCompile
via their build script (the code snippet in -parameters
.
1c. Done by Room Gradle plugin: The only drawback is that this requires more work on Room side compared to the previous approaches.
hu...@google.com <hu...@google.com> #18
We have added -parameters
to javac
starting with AGP 4.2.0-alpha11:
@Daniel: Could you help take care of the remaining work on the Room side?
I'm thinking we could proceed as follows:
- Route 1 [Safer]: Disable incremental Room by default. Tell users (via a console warning or a doc page) to enable incremental Room only when they apply one of the suggested fixes (see below).
- Route 2 [Unsafe]: Enable incremental Room by default. Accept that it might be broken but make sure we can detect the error (e.g., detect if the parameter name is
arg0
) and provide a fix (see below). - If incremental Room is enabled (whether manually or by default), and the users run into this error, make sure the error message from Room shows (or points to a doc page that shows) the suggested fixes.
- Suggested fixes:
- Upgrade to AGP 4.2.0-alpha11+
- Convert the relevant files to Kotlin
- Add
-parameters
manually via this script:
tasks.withType(JavaCompile) { options.compilerArgs << "-parameters" }
- Disable incremental Room if all else fails.
da...@google.com <da...@google.com> #19
Thank you so much Hung, I'll tackle the Room side of things!
hu...@google.com <hu...@google.com> #20
Update: We just discovered -parameters
requires that the project is not targeting Java 1.7 or lower. (AGP 4.2+ targets Java 8 by default if it is not set---
So the updated suggested fixes are:
- Convert the relevant files to Kotlin
- Upgrade to AGP 4.2.0-alpha11+ and set
android.compileOptions.targetCompatibility
toJavaVersion.VERSION_1_8
or higher (or just don't set it). - Add
-parameters
manually via this script:
and settasks.withType(JavaCompile) { options.compilerArgs << "-parameters" }
android.compileOptions.targetCompatibility
toJavaVersion.VERSION_1_8
or higher (or just don't set it if you're using AGP 4.2+) - Disable incremental Room if all else fails.
That's it! :)
el...@google.com <el...@google.com>
hu...@google.com <hu...@google.com> #21
According to
Description
we've just turned on incremental compilation and i'm getting a local error that is a bit indeterminate but happens very frequently.
to reproduce:
checkout androidx cd frameworks/support run ./gradlew :room:integration-tests:room-testapp:assembleAndroidTest :room:integration-tests:room-testapp:assemble
make some changes. I was changing RoomTrackingLiveData class and renaming some internal methods.
run ./gradlew :room:integration-tests:room-testapp:assembleAndroidTest :room:integration-tests:room-testapp:assemble
sometimes fails with: