Dagger + ButterKnife = Could not initialize class dagger.internal.codegen.ModuleAdapterProcessor - android

I have a project where I'm using ButterKnife for view injection, and I just added dagger but I'm getting the following error:
Description Resource Path Location Type Internal compiler error:
java.lang.NoClassDefFoundError: Could not initialize class
dagger.internal.codegen.ModuleAdapterProcessor at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method) R.java /Suggest/gen/com/google/android/gms line 0 Java Problem
I'm using eclipse and I have the following in my Annotation config:
notice: I have written one #module with its #provides ... correctly, then removed it and still I'm having the same compilation error
I followed this comment to setup Annotation processing:
https://github.com/square/dagger/issues/126#issuecomment-11992320
I'm not sure if it's code-related or dependency and versions related, I just need someone to point me to the possibilities behind this error

For those looking for a solution, I just found out that using JavaWriter 2.1.1 Fixed the problem

Related

After merging two branch and then rebuilding I am getting these errors related to Dagger/missing binding

I am working on a client project via GitHub, there is two branches let's say branch 1 and branch 2, and both are working perfectly separately, but when I merge branch 1 into branch 2 and resolve all conflicts and then after resolving all conflicts, i clean the project, sync it and then try to rebuild it then it is throwing some dagger missing error, i have tried everything but unable to solve it, as its a multi-module project, these are the following errors :-
D:\3.4)clientmainworkgithub\04)github_holedo_dev9_1pm_15may2022\matrix-sdk-android\build\tmp\kapt3\stubs\debug\org\matrix\android\sdk\internal\session\SessionComponent.java:8: error: [Dagger/MissingBinding] error.NonExistentClass cannot be provided without an #Inject constructor or an #Provides-annotated method.
public abstract interface SessionComponent {
^
error.NonExistentClass is injected at
org.matrix.android.sdk.internal.crypto.crosssigning.DefaultCrossSigningService(…, outgoingKeyRequestManager, …)
org.matrix.android.sdk.internal.crypto.crosssigning.DefaultCrossSigningService is injected at
org.matrix.android.sdk.internal.crypto.crosssigning.UpdateTrustWorker.crossSigningService
org.matrix.android.sdk.internal.crypto.crosssigning.UpdateTrustWorker is injected at
org.matrix.android.sdk.internal.session.SessionComponent.inject(org.matrix.android.sdk.internal.crypto.crosssigning.UpdateTrustWorker)
The following other entry points also depend on it:
org.matrix.android.sdk.internal.session.SessionComponent.session()
org.matrix.android.sdk.internal.session.SessionComponent.syncTask()
org.matrix.android.sdk.internal.session.SessionComponent.inject(org.matrix.android.sdk.internal.session.room.send.SendEventWorker)
org.matrix.android.sdk.internal.session.SessionComponent.inject(org.matrix.android.sdk.internal.session.room.send.MultipleEventSendingDispatcherWorker)
org.matrix.android.sdk.internal.session.SessionComponent.inject(org.matrix.android.sdk.internal.session.content.UploadContentWorker)
org.matrix.android.sdk.internal.session.SessionComponent.inject(org.matrix.android.sdk.internal.session.sync.job.SyncWorker)
org.matrix.android.sdk.internal.session.SessionComponent.inject(org.matrix.android.sdk.internal.crypto.verification.SendVerificationMessageWorker)

ANTLR Tool version 4.7.1 used for code generation does not match the current runtime version 4.5.3

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()
}

Dagger 2.21+ unable to generate UnitTest Component in android

Let's start with an issue:
> Task :app:kaptAppDebugUnitTestKotlin FAILED
/app/build/tmp/kapt3/stubs/appDebugUnitTest/com/pckg/TestAppComponent.java:77: error: [ComponentProcessor:MiscError] dagger.internal.codegen.ComponentProcessor was unable to process this class because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
public abstract class TestAppComponent extends com.pckg.AppComponent {
^warning: The following options were not recognized by any processor: '[room.schemaLocation, kapt.kotlin.generated, room.incremental]'[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: android.databinding.annotationprocessor.ProcessDataBinding (DYNAMIC).
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:kaptAppDebugUnitTestKotlin'.
> 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
I'm trying to update our huge project to run with incremental kapt. One of the essentials was to update dagger. I tried a lot version, but the last one working is 2.20, everything above gives the mentioned 'error'.
To be honest, I don't see any error. The build works fine, when I assemble only app, but when I try to run the UnitTest task, it shows me that error. But I'm unable to find any issue, nor the AS code inspections in AppComponent. The TestAppComponent is not even generated.
I believe, we use completely regular setup of local unit tests for android.
Setup:
/core/src/main/com/pckg/core/Provisions.kt
interface Provisions {
....
}
/app/src/main/com/pckg/AppComponent.kt
#Component(modules=[....])
#Singleton
interface AppComponent : Provisions {
....
}
/app/src/test/com/pckg/TestAppComponent.kt
#Component(modules=[....])
#Singleton
interface TestAppComponent : AppComponent {
....
}
I also tried to make the Components to be abstract classes instead of interface (because the error says that class extends the interface, but without luck - same issue, just with abstract classes).
Of course I did try to run with --stacktrace, but it's just longer pointless exception.
Questions:
Do you know what needs to be changed when updating to dagger 2.21 and
above?
Do you know how to force dagger/kapt/gradle to say more than
(no error message)?
PS: Whatever library version you might think of is the latest. AGP 3.5.0, Gradle 5.5.1, Kotlin 1.2.50,...
I remember seeing something like this when I was trying to add the test component to the android tests. After adding the following to build.gradle the component was generated (originally I only had dagger in the kapt directive):
kaptAndroidTest "com.google.dagger:dagger-android-processor:$dagger_version"
kaptAndroidTest "com.google.dagger:dagger-compiler:$dagger_version"
If you're doing that for unit tests, adjust accordingly.
Note: If you're only seeing it when using incremental processing, then maybe it's some other configuration option you need to enable specifically for the unit test?
Turns out, the problem was in missing dependencies in tests.
In our case it was due to conflict with FindBugs.
We have defined FB as:
compileOnly "com.google.code.findbugs:annotations:3.0.1"
compileOnly "com.google.code.findbugs:jsr305:3.0.2"
So if we have a class with suppress:
public class JavaClass {
#Inject
#SuppressFBWarnings(value = "THIS_CRASHES_DAGGER",
justification = "Since this annotation is not available in test classpath, dagger will fail.")
Context mInjectedContext;
}
The #SuppressFBWarnings is not available in tests. This was ok up to dagger 2.20. But every version after is failing on that, because the annotation cannot be resolved. And dagger is trying to read other annotations to report you badly used annotations, etc.
The fix is easy:
testCompileOnly "com.google.code.findbugs:annotations:3.0.1"
testCompileOnly "com.google.code.findbugs:jsr305:3.0.2"
or making it implementation might ensure propagation to the tests also.
You can find more about this here: https://github.com/google/dagger/issues/1599

Dokka failure: com.intellij.psi.impl.source.PsiClassImpl cannot be cast to com.intellij.psi.PsiJavaFile

I have a build that generates Android artefacts (mainly an .aar) and bundles in dokka-generated docs (codebase is Kotlin+Java).
With some recent changes dokka started failing with this cryptic error:
> Task :mylib:dokka FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':mylib:dokka'.
> com.intellij.psi.impl.source.PsiClassImpl cannot be cast to com.intellij.psi.PsiJavaFile
Any help would be appreciated. I currently cannot seem to trace the source of this.
I can't pin-point the root of the problem but I can say for sure that Dokka has some issues with annotation classes.
In my changes, I had initially introduced a new annotation class based on Android's #IntDef inside an abstract class (alongside associated helper methods), written in Java.
These 2 steps seemed to have helped:
Switching to Kotlin for the annotation class' implementation, then defining the annotation class at a file's root scope (rather than as an inner item of a class).
Suppressing the annotation's package in Dokka's config, i.e. -
dokka {
...
packageOptions {
prefix = "com.mylib.myannotation"
suppress = true
}
}
The end result is that the documentation cannot reference the annotated class (that's no surprise, as it was suppressed), but the javadoc generation fully succeeded.

#hide class not found

The ContentResolver class has a hidden method called getSyncStatus(...).
To make it public visible I try to add a wrapper method in ContentResolverCompat from support v4 lib.
This works so far in Eclipse but when I call make it fails with the following errors:
ERROR: /development/android/frameworks/support/v4/java/android/support/v4/content/SyncStatusInfo.java:91: android.content.SyncStatusInfo cannot be resolved to a type
ERROR: /development/android/frameworks/support/v4/java/android/support/v4/content/ContentResolverCompat.java:19: The import android.accounts cannot be resolved
ERROR: /development/android/frameworks/support/v4/java/android/support/v4/content/ContentResolverCompat.java:137: Account cannot be resolved to a type
ERROR: /development/android/frameworks/support/v4/java/android/support/v4/content/ContentResolverCompat.java:138: android.content.SyncStatusInfo cannot be resolved to a type
ERROR: /development/android/frameworks/support/v4/java/android/support/v4/content/ContentResolverCompat.java:146: Account cannot be resolved to a type
ERROR: /development/android/frameworks/support/v4/java/android/support/v4/content/ContentResolverCompat.java:148: android.content.SyncStatusInfo cannot be resolved to a type
My thought was that #hide is a documentation thing only and I can access it from within AOSP classes. But why I can't build my changes when I want to access hidden classes / methods?
Note: I don't want to build an Android app, I want to change / build the Android source code itself.
Edit: This isn't a duplicate of #hide class not found because #hide means that it is removed from JavaDoc but it is still accessible from Android source code itself.

Categories

Resources