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!
Related
While running lint a strange error occurred. This appears to happen after a androidx.lifecycle update from 2.2.0 to 2.3.0:
../../src/main/java/my/project/MyService.kt: Unexpected failure during lint analysis of MyService.kt
(this is a bug in lint or one of the libraries it depends on)
Message: org.jetbrains.uast.UastErrorType cannot be cast to com.intellij.psi.PsiClassType
The crash seems to involve the detector androidx.lifecycle.lint.NonNullableMutableLiveDataDetector.
You can try disabling it with something like this:
android {
lintOptions {
disable "NullSafeMutableLiveData"
}
}
Stack: ClassCastException:NonNullableMutableLiveDataDetector.visitMethodCall(NonNullableMutableLiveDataDetector.kt:103)
←UElementVisitor$DelegatingPsiVisitor.visitMethodCallExpression(UElementVisitor.kt:1079)
←UElementVisitor$DelegatingPsiVisitor.visitCallExpression(UElementVisitor.kt:1059)
←UCallExpression$DefaultImpls.accept(UCallExpression.kt:85)
←UCallExpressionEx$DefaultImpls.accept(UCallExpression.kt:-1)
←KotlinUSimpleReferenceExpression$KotlinAccessorCallExpression.accept(KotlinUSimpleReferenceExpression.kt:129)
←KotlinUSimpleReferenceExpression.visitAccessorCalls(KotlinUSimpleReferenceExpression.kt:116)
←KotlinUSimpleReferenceExpression.accept(KotlinUSimpleReferenceExpression.kt:83)
You can set environment variable LINT_PRINT_STACKTRACE=true to dump a full stacktrace to stdout.
This issue type represents a problem running lint itself. Examples include failure to find bytecode for source files (which means certain detectors could not be run), parsing errors in lint configuration files, etc.
These errors are not errors in your own code, but they are shown to make it clear that some checks were not completed.
To suppress this error, use the issue id "LintError" as explained in the Suppressing Warnings and Errors section.
When I disable NullSafeMutableLiveData - as suggested - the error doesn't occur anymore, great! But I wonder where this issue comes from and if there's a better solution than simply ignoring that specific check completely. Is it a bug in the androidx.lifecycle dependency I could report, or is it possible to somehow conflict with an error in my project I could fix? (if so, any advice finding out where?)
Note: this only happened when lint was run on Bitrise, I didn't encounter this when running lint in Android Studio. Not sure if this is somehow related though.
Im working on an Android App, currently using DSL and some libraries, suddenly the build gave me this error.
Task :app:kaptDebugKotlin FAILED
ANTLR Tool version 4.7.1 used for code generation does not match the current runtime version 4.5.3ANTLR Runtime version 4.7.1 used for parser compilation does not match the current runtime version 4.5.3
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)
i've been searching but with no success...
If you wanna see the issue you can clone the project. Project GITHUB
Im using Android Studio Canary 4.1.
So the solution was from the build.gradle
basically the import from ROOM was this
import(Room.compiler)
so i changed to this, and the issue was solved :)
kapt(Room.compiler)
Inside the build.gradle(Module:app) copypaste this code
configurations.all() {
resolutionStrategy.force "org.antlr:antlr4-runtime:4.5.3"
resolutionStrategy.force "org.antlr:antlr4-tool:4.5.3"
}
For anyone still experiencing this issue, just update your Room to the latest version:
androidx.room:room-runtime:2.3.0-alpha04
androidx.room:room-compiler:2.3.0-alpha04
It's due to this bug: https://issuetracker.google.com/issues/155215201
The problem was fixed for me by changing this.
from:
implementation "androidx.room:room-runtime:$depVersion"
implementation "androidx.room:room-compiler:$depVersion"
to:
implementation "androidx.room:room-runtime:$depVersion"
annotationProcessor "androidx.room:room-compiler:$depVersion"
Removing suspend keyword from queries in DAO interface, solved my problem
I got similar error. I have all files in Java and I changed few files to Kotlin. Then this issue showed up.
I have a function in a Java file accessing static function in a Kotlin file. That's the point where the app crashed.
Code in Kotlin file:
companion object{
#JvmStatic
fun myStaticFunction(){
// body of the static function
}
}
I added the annotation #JvmStatic(see the above code) to the function and the error got resolved.
This is a very specific scenario in which this crash occurs and may not be applicable to all.
At lease for me, the root cause of this problem/error is because of the data binding not being handled properly.
Currently, Android Studio does not have a mechanism to show error message for unreferenced variables in .xml file.
For example,
In MyViewModel.kt, If I have a property name as,
var email
and you are mapping this property in xml as,
#={model.errEmail}
instead of #={model.email}
You get to see this error.
If you see this error, just go to layout xml file and check the binding names/mappings and correct it.
Had a similar issue. I was trying to implement bindingAdapters to a TextView of a ViewHolder in my recyclerview
I failed to implement a bindingAdapter for a TextView after adding the adding a unique app attribute
app:tDate="#{transaction}
in the xml layout file for my recylerView item.
<TextView
android:id="#+id/trans_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/trans_category"
app:layout_constraintTop_toTopOf="parent"
app:tDate="#{transaction}"/>
Solved it by well.. implementing it.
#BindingAdapter("tDate")
fun TextView.setValue(item: Transactions){
text = item.date.toString()
}
I'm a complete beginner to coding and Android Studio. I've been trying to follow along with basic "hello world" guides and to my dismay, I am having zero luck.
I keep getting error messages even when the code seems to be correct. I've tried searching for the fix, but I'm honestly not sure what to search for as I'm not sure where I am going wrong.
I believe that it is a Kotlin issue. I've tried reinstalling android studio, resetting the settings and ensuring updates are current.
Code:
fun main(args:Array<String>) {
println("hello world!")
}
Error log:
build failed 9 s 875 ms
Run build 9 s 583 ms
null
C:/Users/guilder/AndroidStudioProjects/MyApplication3
app/src/androidTest/java
com/example/myapplication/ExampleInstrumentedTest.kt
Unresolved reference: ext
Unresolved reference: AndroidJUnit4
An annotation argument must be a compile-time constant
Okay, it's a bit late, but, if you are still struggling with this issue, just delete file which leads to crash. This is
C:/Users/guilder/AndroidStudioProjects/MyApplication3/app/src/androidTest/java
com/example/myapplication/ExampleInstrumentedTest.kt
file. Have a nice day!
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
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;