Finding actual error out of data binding error - android

I am using data binding without any problems and it works good. But sometimes it frustrate me a lot by hiding the real problem by showing data binding error for no reason. Last time i made some changes in room database and mistakenly used wrong table name in ROOM DAO. At the time of building project android studio displayed multiple data binding error for no reason but not the real culprit ( wrong table name ). When i fixed that build worked. Now again i have made some changes and its giving me same data binding error, i am going through each file to find the real culprit but didn't see anything problematic. Any help to show all the error not just data binding error. This is very annoying Android Studio gradle build did not display all error at the bottom.

The Java compiler cuts off errors after 100 by default. With a standard Android-style project structure, add this to your root level build.gradle to raise the limit (to 500 in this case) - this raises the limit for all subprojects. You will still have to dig through all errors to find the real ones:
subprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xmaxerrs' << '500'
}
}
}

I fixed the issue by implementing Room in another module

Related

Kapt annotation processing - how to show full stacktrace

I am working on a android project using Kotlin, Databinding and Room.
Sometimes the build fails with a error message, containing no information about what exactly went wrong, except that it has something to do with the annotation processor (which can have many causes...).
shortened Example:
org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing org.jetbrains
[more stack trace lines]
Caused by: org.jetbrains.kotlin.kapt3.base.util.KaptBaseError: Error while annotation processing
[even more stack trace lines]
at org.jetbrains.kotlin.kapt3.base.Kapt.kapt(Kapt.kt:45)
... 32 more
Finding the cause, then means time consuming backtracking of my steps (and maybe using git stash) and guessing, when one the 32 hidden lines at the end seems likely to contain some useful information about what actually went wrong.
So the question is: how to show the full stack trace?
I tried setting the -Xmaxerrs 500 in my build.gradle as shown here https://kotlinlang.org/docs/reference/kapt.html#java-compiler-options as well as various variants of this, I found on SE (sorry, don't remember which exactly).
None made any difference. Maybe i put the block in the wrong part? (tried module level, android -> defaultConfig -> kapt)
Add kapt.verbose=true to your project's gradle.properties file.
In my case, the issue was apparently with the 'suspend' keyword added to my Dao function. I may be missing dependency or there may be some dependency issue.
For example I changed the following:
#Query("select * from election_table")
**suspend** fun getAllElections():LiveData<List<Election>>
to
#Query("select * from election_table")
fun getAllElections():LiveData<List<Election>>
Room version: = "2.2.5"
Update: Yep - the issue is ensure you have the following dependencies:
//Room
implementation "androidx.room:room-runtime:$version_room"
kapt "androidx.room:room-compiler:$version_room"
implementation "androidx.room:room-ktx:$version_room"
I was missing the last one. Added suspend keyword again, and now compiles like a charm!

java.lang.NullPointerException when dataBinding enabled = true

Whenever I enable this in my app gradle
dataBinding {
enabled = true
}
and then sync -> It completely succeed.
but when I "run" it, It builds fail and shows this error
java.lang.NullPointerException
at android.databinding.tool.store.LayoutFileParser.parseOriginalXml(LayoutFileParser.java:135)
at android.databinding.tool.store.LayoutFileParser.parseXml(LayoutFileParser.java:93)
...
my app has little amount of Kotlin code, and android version is 3.5, minSdkVersion 19, targetSdkVersion 28, and upgraded to androidX
How can I solve this? which part should I search for solve this problem???
except above code, every thing works perfect.
Edit
And when I rolled back my code before upgrading to androidX and compiled it, it also shows "Null point exception" and at this time, there are no extra message without just "Null point exception".
Finally I got answer. (cc. android databinding error:Execution failed for task ':app:dataBindingProcessLayoutsDebug')
I guessed it was because of BOM. Someone said it will happen when the code is used in two different circumstances(Window and Mac).
So in 'res' folder, I clicked 'remove BOM' button in android studio and that action changed some xml files.
<?xml version="1.0" encoding="utf-8"?>
But it wasn't worked in Mac. This solution worked only in Window.
I tried a little too much but I figured it out. I created the project on the Mac computer and it wasn't a problem when I switched to windows later. When I tried to create a new file, I got this error and just understood why. Every time I right-clicked on the file I just added, I saw an option called "remove BOM". Clicking this solved my problem. But I did not find the solution to the problem logically, I just found it random.
ex: https://prnt.sc/riw6ex

android data binding: how to get useful error messages

In android studio 2.1, the compile time error messages from xml mistakes are entirely non-helpful:
Error:(11, 41) error: package mypackage.databinding does not exist
Error:(15, 13) error: cannot find symbol class MyActivityBinding
The real error would usually be something like "there's no such attribute android:adapter", or "variable foo doesn't contain property bar" or something like that. But instead of actually showing such errors, it shows the above unhelpful ones, which only tell you that the bindings weren't generated because of some unknown error.
The way I use in Android Studio 4.0:
Select the top level Build: failed item on the Build Output panel
On the right part click Run with --stacktrace. When build is finished select the top Build: failed item again on the left panel. You'll get a databinding error description on the right panel:
In my case it's:
[databinding] {"msg":"Cannot find a getter for \u003ccom.google.android.material.slider.Slider app:value\u003e that accepts parameter type \u0027java.lang.Float\u0027\n\nIf a binding adapter provides the getter, check that the adapter is annotated correctly and that the parameter type matches.","file":"SliderDatabinding\src\main\res\layout\activity_main.xml","pos":[{"line0":14,"col0":8,"line1":21,"col1":41}]}
Clink on Toogle View, under the 'Build' icon will give you details logs
There's no easy way for now. In general, if you face such compilation error and error messages point at missing databinding classes it is usually either bad reference from layout (i.e. you try to access members classes you assigned do not expose - usually happens when you c&p layouts).
Even worse, when you use other code generating libraries (Icepick, Butterknife, etc) then the real culprit can be often in code completely unrelated to binding. So when something like this occur in my code, I usually check Gradle Console view and read it from the end up, ignoring all error messages related to databinding like "missing class" or "package does not exists"
One way of getting the proper error is to run gradle in a terminal with '--info', like:
gradle :app:build --info
That's not exactly integrated into AS, so I can't really accept that answer.

Issue with projectfolder called (AndroidProjects)?

I have a wired issue. If i set up a folder called AndroidProjects and put my project in there... Android-Studio fails with gradle.
one error is:
IllegalStateException:
PsiFile not parsed for file D:/AndroidProjects/MyApplication/settings.gradle.
Wait until onPsiFileAvailable() is called.
sometimes it says that gradle has a fatal error....
if i set up my projectlocation to e.g. andropro everyting is working fine.
My thoughts:
may problems with 2 big letters in projectfoldername
may foldername is to long
may android or project are registered words in android-studio
Is there a knowen issue using foldernames like i did above?
couldn't find anything on the net.

Android Studio with AndroidAnnotations -> these types will not undergo annotation processing

I am not sure if it is Android Studio ( 0.1.9 ) or AndroidAnnotation problem, however, lately I cannot make and compile my AndroidAnnotations projects.
Ok, so I try to make project and this is what I got in "Messages" window:
Information:Round 1:
Information: input files: {com.antyzero.sidereelo.ui.activity.SplashActivity}
Information: annotations: [com.googlecode.androidannotations.annotations.EActivity, java.lang.Override]
Information: last round: false
Information:Processor com.googlecode.androidannotations.AndroidAnnotationProcessor matches [com.googlecode.androidannotations.annotations.EActivity] and returns true.
Information:Note: Starting AndroidAnnotations annotation processing
Information:Round 2:
Information: input files: {com.antyzero.sidereelo.ui.activity.SplashActivity_}
Information: annotations: [java.lang.Override]
Information:Processor com.googlecode.androidannotations.AndroidAnnotationProcessor matches [] and returns true.
Information:Round 3:
Information: input files: {}
Information: annotations: []
Information: last round: true
Information:Compilation completed successfully with 1 warning in 17 sec
Information:0 errors
Information:1 warning
Warning:: Unclosed files for the types '[dummy1372862415557]'; these types will not undergo annotation processing
Nothing less, nothing more. In result I don't have my SplashActivity_ created. This message is from brand new project but my old projects are also affected.
Answer from Android Studio: Use AndroidAnnotations is not helpful.
I was working with AA and IntelliJ weeks before Android Studio without problem. IMO it might happen after latest Android Studio update, but maybe there is some kind of solution for this right now, if not I will report this to Android Studio team. Thanks for help.
One more thing. My projects are using Maven and building them from CLI works fine, all classes are generated as they should be.
I was facing the same problem when trying to inject a view with #ViewById, and the problem was that I was declaring the field private. Declaring it at least protected fixed the issue!
Before:
#ViewById
private NoListResultsView noResultsView;
After
#ViewById
protected NoListResultsView noResultsView;

Categories

Resources