I am implementing Dagger2 and when I am using #ContributesAndroidInjector, I get compile time
error:#dagger.android.ContributesAndroidInjector was used,but dagger.android.processor.AndroidProcessor was not found on the processor path
I tried multiple solutions but this error never goes away. I tried using old library
version of dagger2 dependencies. I tried creating a java abstract #Module class. I
tried using Kotlin android processor declaring kapt dependency, But Nothing really Helped. Can somebody please help me to rid of this error. Following are the dependencies of Dagger2 that I am using in my project for reference:
implementation "com.google.dagger:dagger:2.35.1"
implementation "com.google.dagger:dagger-android:2.35.1"
implementation "com.google.dagger:dagger-android-support:2.35.1"
annotationProcessor "com.google.dagger:dagger-android-processor:2.35.1"
kapt 'com.google.dagger:dagger-compiler:2.28.3'
implementation 'javax.inject:javax.inject:1'
kapt "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.3.0"
implementation "androidx.compose.runtime:runtime:1.2.1"
Oh! You were not using the same Dagger compiler as your implementations. Your compiler was 2.28.3 and your implementations were 2.35.1. If the Dagger compiler has a different version than its implementation, it may generate non-working code that refers to missing implementations, or (as here) it may not generate code at all.
Make them match:
implementation "com.google.dagger:dagger:2.35.1"
implementation "com.google.dagger:dagger-android:2.35.1"
implementation "com.google.dagger:dagger-android-support:2.35.1"
kapt "com.google.dagger:dagger-android-processor:2.35.1"
kapt "com.google.dagger:dagger-compiler:2.35.1"
implementation 'javax.inject:javax.inject:1'
kapt "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.3.0"
implementation "androidx.compose.runtime:runtime:1.2.1"
I also switched your Android compiler to kapt per the Dagger README section on Gradle.
I managed to solve this by changing my dependencies to the following-
implementation 'com.google.dagger:dagger-android:2.16'
implementation 'com.google.dagger:dagger-android-support:2.16'
kapt "com.google.dagger:dagger-compiler:2.16"
kapt "com.google.dagger:dagger-android-processor:2.16"
This seems to be more like a a hack than a proper solution as when I update my libraries it starts giving me compile time error
For some reason my 4.0.2 based code doesn't produce rx-fied service versions with codegen.
Both VertxEBProxy and VertxProxyHandler classes are created as expected though.
Here is a demo project: https://github.com/ashertarno/playground
Please see the required dependencies below:
implementation "io.vertx:vertx-core:$vertxVersion"
implementation "io.vertx:vertx-rx-java2:$vertxVersion"
implementation "io.vertx:vertx-codegen:$vertxVersion"
implementation "io.vertx:vertx-service-proxy:$vertxVersion"
implementation "io.vertx:vertx-rx-java2-gen:$vertxVersion"
annotationProcessor "io.vertx:vertx-codegen:$vertxVersion:processor"
annotationProcessor "io.vertx:vertx-service-proxy:$vertxVersion"
What would be missing in this case?
You have to add io.vertx:vertx-rx-java2-gen:$vertxVersion as an annotationProcessor and testAnnotationProcessor. After I did that, I had the classes get generated:
./build/classes/java/main/me/tarno/playground/reactivex/BaseServiceProxy.class
./build/classes/java/test/me/tarno/playground/reactivex/TestProxy.class
After upgrading to gradle 4.7, my previously warning-free build now emits this warning:
The following annotation processors were detected on the compile classpath: 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor' and 'lombok.launch.AnnotationProcessorHider$ClaimingProcessor'. Detecting annotation processors on the compile classpath is deprecated and Gradle 5.0 will ignore them. Please add them to the annotation processor path instead. If you did not intend to use annotation processors, you can use the '-proc:none' compiler argument to ignore them.
It seems that annotation processors are deprecated and gradle version 5.0 will not support annotation processors.
My project uses lombok, which requries annotation processors, so using -proc:none is not an option. Neither is stopping using Gradle when verison 5.0 is released.
How do I:
stop the warnings, and
ensure my project will continue to build with future Gradle releases?
Change the lombok dependency type from compile to annotationProcessor, so your dependencies section in your build.gradle file should look like:
dependencies {
compileOnly('org.projectlombok:lombok:1.16.20')
annotationProcessor 'org.projectlombok:lombok:1.16.20'
// compile 'org.projectlombok:lombok:1.16.20' <-- this no longer works!
// other dependencies...
}
If your project contains tests then you'll need the following configuration to completely rid yourself of the gradle warning:
dependencies {
compileOnly "org.projectlombok:lombok:1.18.2"
testCompileOnly "org.projectlombok:lombok:1.18.2"
annotationProcessor "org.projectlombok:lombok:1.18.2"
testAnnotationProcessor "org.projectlombok:lombok:1.18.2"
}
Adjust the lombok version to suit.
Gradle added annotationProcessor in 4.6 and Lombok is an annotation processor even though their documentation is not really clear about this when using Gradle they are also aware of it as they recommend it when using Android Studio.
So short answer is to use:
dependencies {
compileOnly('org.projectlombok:lombok:1.18.0')
annotationProcessor('org.projectlombok:lombok:1.18.0')
}
I am trying to open existing android project in android studio and it gradle cannot build the app without the error
Error android studio keeps on throwing
Error:(74, 1) A problem occurred evaluating project ':app'.
> Could not find method implementation() for arguments
[com.android.support:appcompat-v7:26.0.0] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
My Code in build.gradle Which can help to understand my issue
My dependencies
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
// google & support
implementation "com.android.support:appcompat-v7:$supportVersion"
implementation "com.android.support:cardview-v7:$supportVersion"
implementation "com.android.support:recyclerview-v7:$supportVersion"
implementation "com.android.support:design:$supportVersion"
implementation "com.android.support:palette-v7:$supportVersion"
implementation "com.android.support:customtabs:$supportVersion"
implementation "com.android.support:support-v4:$supportVersion"
implementation 'com.google.android.exoplayer:exoplayer:r2.0.4'
// utils
implementation 'com.github.bumptech.glide:glide:4.0.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0'
implementation 'com.koushikdutta.ion:ion:2.1.7'
implementation 'com.github.Commit451:bypasses:1.0.4'
implementation 'com.jakewharton:butterknife:8.8.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.0'
implementation 'com.drewnoakes:metadata-extractor:2.9.1'
implementation "com.orhanobut:hawk:2.0.1"
}
Please help to solve the issue
Make sure you're adding these dependencies in android/app/build.gradle, not android/build.gradle.
Replace compile with implementation.
compile was recently deprecated and replaced by implementation or api
Make sure your Gradle version is 3.*.* or higher before using "implementation".
Open the project level Gradle file under dependencies:
dependencies{
classpath 'com.android.tools.build:gradle:3.1.2'
}
Open the 'gradle-wrapper.properties' file and set the distributionUrl:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
or latest version.
Sync the project. I Hope this solves your problem.
You need to use at least Gradle 3.4 or newer to be able to use implementation. It is not recommended to keep using the deprecated compile since this can result in slower build times. For more details see the official android developer guide:
When your module configures an implementation dependency, it's letting Gradle know that the module does not want to leak the dependency to other modules at compile time. That is, the dependency is available to other modules only at runtime.
Using this dependency configuration instead of api or compile can result in significant build time improvements because it reduces the amount of projects that the build system needs to recompile. For example, if an implementation dependency changes its API, Gradle recompiles only that dependency and the modules that directly depend on it. Most app and test modules should use this configuration.
https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations
Update: compile will be removed by end of 2018, so make sure that you use only implementation now:
Warning:Configuration 'compile' is obsolete and has been replaced with
'implementation'. It will be removed at the end of 2018
change apply plugin: 'java'
to apply plugin: 'java-library'
java-library-plugin
For me I put my dependencies in the wrong spot.
buildscript {
dependencies {
//Don't put dependencies here.
}
}
dependencies {
//Put them here
}
Solved this by adding my dependancies in the app folder
Go to app < Gradle Scripts < gradle.build(Module: app) and add the depandancies in that file and not the global build.gradle file
So ridiculous, but I still wanna share my experience in case of that someone falls into the situation like me.
Please check if you changed: compileSdkVersion --> implementationSdkVersion by mistake
I moved implementation to module-level build.gradle from root-level build.gradle. It solves the issue.
Your Code
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
Replace it By
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
Replace your implementation with classpath. That should work.
As mentioned here, https://stackoverflow.com/a/50941562/2186220, use gradle plugin version 3 or higher while using 'implementation'.
Also, use the google() repository in buildscript.
buildscript {
repositories {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
These changes should solve the issue.
As suggested in official docs you need add these :
buildscript {
repositories {
// Gradle 4.1 and higher include support for Google's Maven repo using
// the google() method. And you need to include this repo to download
// Android Gradle plugin 3.0.0 or higher.
google()
...
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0'
}
}
adding these remove my error. Also use implementation instead of compile.
In my case it was because I used Implementation instead of implementation.
For me the problem was that I wrote:
android {
compileSdk 31
…
Instead of:
android {
compileSdkVersion 31
So make sure your build.gradle is correct.
If implementation is not defined, you are writing on a wrong file. On Unity 2019+ the correct file is main template grandle and not some of the others.
I have an Android project and I plan to make one of its components a library. This will be a Java library (jar), as the android dependencies are not needed there.
The problem is that this library depends on RxJava. But I would like it to be dependent on the RxJava version which the library client will use, no to be explicitly provided by me in the library's build.gradle.
I thought that maybe Gradle Default dependencies would be the way to go, but it doesn't provide the RxJava dependency at all and the library module doesn't build.
My build.gradle:
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
configurations.all {
pluginTool {
defaultDependencies { dependencies ->
dependencies.add(this.project.dependencies.create("io.reactivex:rxjava:1.1.0"))
}
}
}
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
The problem is that this library depends on RxJava. But I would like it to be dependent on the RxJava version which the library client will use, no to be explicitly provided by me in the library's build.gradle.
I don't know if that's possible because that's not the way dependencies work. Maven Transitive Dependencies explains this issue a little.
For example, you made a library and used a given version of RxJava, say, vn. It implictly means that your lib uses some features of vn that are not present in vn-1 and hopefully won't be deprecated in vn+1 and later. If a lib client were able to choose any RxJava version, it could arbitrarily pick vn-1 and your code would not work. You have a hard dependency on vn and anyone who uses your library should be aware of it.
There's no problem in providing an explicit dependency in your lib's build.gradle. In fact, listing the dependencies will help Gradle resolve the dependency graph, handle conflicts and everything. Here's a bit of what Gradle does: https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html
Finally, even if you find a way to achieve the dependency delegation to the lib client, the application can crash during runtime.