I using lombok on some project, and with the new Android Studio 2.4 Update now (Preview) I get this strange error:
What went wrong: Execution failed for task
':core:javaPreCompileRelease'. Annotation processors must be
explicitly declared now. The following dependencies on the compile
classpath are found to contain annotation processor. Please add them
to the annotationProcessor configuration.
- lombok-1.16.16.jar Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath
= true to continue with previous behavior. Note that this option is deprecated and will be removed in the future. See
https://developer.android.com/r/tools/annotation-processor-error-message.html
for more details.
I already tried:
annotationProcessor "org.projectlombok:lombok:1.16.16"
but has no effect.
I also tested:
android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath
= true
But also has no effect.
Also checked the support page for further information but with no luck, anyone of you possibly?
https://developer.android.com/studio/preview/features/index.html?utm_source=android-studio#annotationProcessor_config
Update:
provided "org.projectlombok:lombok:1.16.16" // keep
annotationProcessor "org.projectlombok:lombok:1.16.16" // add this
Just worked perfectly, but I have two Android Studio modules, and two build.gradle files.
The error log just changed a bit (module prefix), and I thought the fix didn't work.
But after applying the fix to both build.gradle files everything worked perfectly.
I had the same problem but needed a slightly different fix (although the idea came from the accepted answer above - https://stackoverflow.com/a/43820494/1777346)
Turned out I already had the provided and annotationProcessor in both build.gradle files.. but, I also had a compile entry. Removing it fixed this issue for me:
compile 'org.projectlombok:lombok:1.16.16' // remove this
provided 'org.projectlombok:lombok:1.16.16'
annotationProcessor "org.projectlombok:lombok:1.16.16"
Just figured I'd add my findings in case it helps anyone. I'm using Android Studio 3.0 Canary 4 and gradle:3.0.0-alpha4 in my unending quest to get build times down.. which never seems to pay off :)
Related
I am using Gradle to build an Android Studio project. I am using auto-value in one of my modules but for some reason, any version of auto-value higher than 1.5.3 causes a compilation failure.
My dependency in build.gradle for the module looks like this:
annotationProcessor 'com.google.auto.value:auto-value:1.5.3'
If I just change that 1.5.3 to 1.6.5, I get the following error when building (syncing works fine):
Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain annotation processor. Please add them to the annotationProcessor configuration.
- auto-value-1.5.3.jar (com.google.auto.value:auto-value:1.5.3)
Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior. Note that this option is deprecated and will be removed in the future.
See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.
I even tried using the recommended instructions on the documentation:
api "com.google.auto.value:auto-value-annotations:1.6.2"
annotationProcessor "com.google.auto.value:auto-value:1.6.2"
Any clue what to do here?
I'm getting the next crash when I launch my Android app after adding the first Dagger module.
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/collect/ImmutableMap;
at com.sofaking.moonworshipper.DaggerAppComponent.getMapOfClassOfAndProviderOfFactoryOf(DaggerAppComponent.java:35)
at com.sofaking.moonworshipper.DaggerAppComponent.getDispatchingAndroidInjectorOfActivity(DaggerAppComponent.java:41)
at com.sofaking.moonworshipper.DaggerAppComponent.injectApp(DaggerAppComponent.java:64)
at com.sofaking.moonworshipper.DaggerAppComponent.inject(DaggerAppComponent.java:59)
at com.sofaking.moonworshipper.DaggerAppComponent.inject(DaggerAppComponent.java:16)
The issue seems to be identical to this one on GitHub:
https://github.com/google/dagger/issues/897
I understand that Dagger is trying to use Guava, although it shouldn't - But I'm not sure what to do to fix this. It's not a proguard issue.
I tried to include guava in my dependencies - which presented the next error while compiling:
Error: Program type already present: com.google.common.util.concurrent.internal.InternalFutures
which makes sense, as there are other libraries in my code which depend on guava.
implementation 'com.google.dagger:dagger:2.15'
kapt 'com.google.dagger:dagger-compiler:2.15'
compile 'com.google.dagger:dagger-android:2.15'
compile 'com.google.dagger:dagger-android-support:2.15'
kapt 'com.google.dagger:dagger-android-processor:2.15'
// tried adding this as well, didn't work
api 'com.google.guava:guava:27.0-android'
Edit: Here's tree of resolved dependecies: https://pastebin.com/RsPPjD6H
After seeing that Dagger depends on com.google.guava:guava:23.3-jre, I tried adding the next line in my Gradle build file:
api 'com.google.guava:guava:23.3-android'
And it works!
The word "compile" is not used anymore. Use "implementation" instead in your dependencies. I don't know if that is causing the issue but maybe.
I build the project at gitlab ci
./gradlew assembleDebug --stacktrace
and sometimes it throws an error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithDexBuilderForDebug'.
> com.android.build.api.transform.TransformException: java.lang.IllegalStateException: Dex archives: setting .DEX extension only for .CLASS files
At my local pc it works correctly.
kotlin version is 1.2
multidex is enabled
What is the reason of this error?
./gradlew clean fixed the same error for me.
For Cordova developers,
If you get this build error in your project, as said Pierrick Martellière in the comments of this answer, in you project folder use :
cordova clean
It makes a cleaning and a build immediately
It seems I found the solution.
At the build moment gradle was showing warnings for me:
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
app: 'androidProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'com.arello-mobile:moxy-compiler:1.5.3' and apply the kapt plugin: "apply plugin: 'kotlin-kapt'".
I made a misspelling and forgot to remove unnecessary annotationProcessor for library:
annotationProcessor "com.arello-mobile:moxy-compiler:$moxyVersion"
kapt "com.arello-mobile:moxy-compiler:$moxyVersion"
So I removed first line.
After that I applied kapt plugin apply plugin: 'kotlin-kapt' and fixed some build errors in code after it.
After all I realized that I forgot to replace compile to implementation in some places. It is weird but without it build didn't work.
This changes fix my error build.
Simple Solution
For Ionic and Cordove Projects
cordova clean
Above answer is mostly right but in my case, i get this exception when i crate same name java and kotlin file then deletes one of them.
Solutions are: just Build -> Clean Project my project and it works. And my project also enabled multiDex.
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
As mentioned above by #mixel cleaning gets the job done. But as an option not to do it manually just add the gradle 'clean' task into app run configuration so it will be done all the time before launch. Of cource, it can slow down the whole process a bit.
I was able to get the problem to go away by closing and restarting Android Studio. Perhaps even a Rebuild Project would have done it as well (did not try that though).
Configuring for multidexing did not solve this issue for me.
However I did come up with a resolution...of sorts. Basically it involved creating a pull request for a second branch on the same commit as the build that was failing. The build for this pull request succeeded, and then Bitbucket thought that the original pull request was ok and allowed us to merge, even though we had made no changes on that branch. There is some unexplained weirdness there but the technique worked.
Here's how I did it:
Assume that the branch that is failing is called bad-branch.
I created a new branch called bad-branch-copy on the commit that was common between bad-branch and develop. Then I merged bad-branch into bad-branch-copy. The end result of this was a fast forward such that bad-branch-copy ended up on the same commit as bad-branch. I was expecting a separate commit so this result surprised me, but I was grasping at straws anyway so I kept going.
I then pushed bad-branch-copy to GitHub and created a pull request from bad-branch-copy to develop. This triggered a build on bad-branch-copy -> develop, which was successful.
At that point, buddybuild showed a successful build on bad-branch-copy -> develop and still showed a failure on bad-branch -> develop. However, Bitbucket showed a successful build on the pull request for bad-branch. Yes, that's right: buddybuild showed a failure but Bitbucket said it was ok.
We were then able to merge the bad-branch pull request and all was well with the world. Please don't ask me why, I will not answer. :)
I think the same thing could be accomplished with
git checkout bad-build
git checkout -b bad-build-copy
git push origin bad-build-copy
followed by creating a pull request for bad-build-copy.
Currently using Android Studio 3.3.2 I just disabled the instant run and it worked.
What resolved the issue for me was manually adding all the conflicting files manually. For example in my gradle file I had:
implementation 'com.android.support:support-compat:27.1.1'
it was underlined with red. I hovered over the line and android studio said there was a conflict with another file using a lower version. The error was similar to
come.android.support:support-annotations:26.0.1 conflicts/mix versions with 27.1.1.
It gave me the names of the files and I manually added them with the corresponding version so they would all match
compile 'com.android.support:support-annotations:27.1.1'
compile 'com.android.support:support-compat:27.1.1'
compile 'com.android.support:support-core-ui:27.1.1'
compile 'com.android.support:animated-vector-drawable:27.1.1'
compile 'com.android.support:appcompat-v7:27.1.1'
compile 'com.android.support:design:27.1.1'
None of the current solutions worked for me and it was fixed by simply disabling Instant Run.
please find here the solution of this problem,
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Previously my gradle used to look like this and worked fine (apart from few registered bugs)
implementation 'com.dji:dji-sdk:4.3.2'
Now, after changing to
implementation 'com.dji:dji-sdk:4.4.0'
the Camera and other files cannot be recognized anymore. I am attaching a screenshot of the unrecognized imports.
However when I am trying to add
//dji-drones-sdk
implementation 'com.dji:dji-sdk:4.4.0'
provided 'com.dji:dji-sdk-provided:4.4.0'
I am getting "could not download dji-sdk-provided.jar"
Screenshot attached
All the examples and github codes are in version 4.3.2. Can anyone help me out?
Here is the link to the dji sdk
I have found the issue. After Gradle 3.4, the "provided" is replaced by "compileOnly"
I quote,
Gradle adds the dependency to the compilation classpath only (it is not added to the build output). This is useful when you're creating an Android library module and you need the dependency during compilation, but it's optional to have present at runtime. That is, if you use this configuration, then your library module must include a runtime condition to check whether the dependency is available, and then gracefully change its behavior so it can still function if it's not provided. This helps reduce the size of the final APK by not adding transient dependencies that aren't critical. This configuration behaves just like provided (which is now deprecated).
Hence using compileOnly in place of provided will do the trick.
Here is a link to the gradle changes documentation
To support Instant Run in my version of Android Studio, I needed to upgrade my Gradle plugin from version 2.2.3 to 2.3.3
I'm aware I'm supposed to migrate to annoationProcessor and I believe I've followed that guide correctly
after doing so, the Android DataBinding code generation fails
The migration guide linked earlier states that all I need is to
Make sure you are on the Android Gradle 2.2 plugin or newer
Remove the android-apt plugin from your build scripts
Change all apt, androidTestApt and testApt dependencies to their new format
This should be all that's needed to successfully build the project. Yet it doesn't build.
Build output
Gradle build finished with 101 error(s) and 23 warning(s) in 12s 481ms
All of the errors follow the same pattern:
C:\Users...\FooAdapter.java
error: package com.example.app.databinding does not exist
error: cannot find symbol class ItemFooBinding
An interesting message can be found in the build console:
Warning:The following options were not recognized by any processor: '[android.databinding.minApi, android.databinding.enableDebugLogs, android.databinding.sdkDir, android.databinding.bindingBuildFolder, android.databinding.enableForTests, android.databinding.modulePackage, android.databinding.generationalFileOutDir, android.databinding.xmlOutDir, android.databinding.artifactType, android.databinding.printEncodedErrors, android.databinding.isTestVariant]'
I would like to point out that...
I presume I don't have an error in some XML file, binding expression or a naming issue. The same set of sources and XML build when I switch back to the Git branch with the old gradle plugin version (and all of the other source files up-to-date)
I did increase the limit of output build errors as discussed here, although this doesn't seem to be relevant right now, since as you can see, I currently have "only" 101 errors. :)
Additional info
The following diffs show how I've modified my gradle files:
build.gradle DiffChecker link
app/build.gradle DiffChecker link
Also, as a quick overview, here is the list of some of the "more interesting" plugins & libraries used by the project:
Kotlin
Android DataBinding
Realm
Retrofit
Dagger
ButterKnife (I know...)
Multidex Support Library
Does anyone have a clue what could be the issue? Any help or idea will be greatly apprecitated!
I had exactly the same warning. This line in gradle solved the issue:
kapt "com.android.databinding:compiler:3.0.1"
Hopefully, it will help somebody
Update:
3.0.1 is Android Plugin Version.
When you see innumerable build errors mentioning databinding as in this case, the problem usually lies somewhere else. Databinding just gets stopped in its tracks by unrelated build problems and complains exceedingly loudly. The only way to deal with it is to locate the build errors that are not tied to databinding. Once they are fixed, databinding can do its thing again and be silent. Unfortunately you often have to repeat this approach several times until you have found all non-databinding issues. It's an arduous task for sure, but unfortunately there is nothing else you can do until Google manages to provide a saner build environment.
This is the reason why you are advised to increase the build error limit beyond 100 - you would not see the actual errors causing your problems, because they commonly do not show up early in the list.
I will chance a guess - Dagger 2 is a common source of triggering this problem, which could be related to your annotationProcessor change; so look out for Dagger errors. But your issues could be caused by other things, like other annotation processors as you mentioned - you wouldn't know for sure until you diligently dig through your build errors.
It seems it all comes down to my project using Kotlin. Actually we have it mixed: some classes use plain old Java while others are written in Kotlin. An incomplete migration. :)
I assume that without Kotlin, replacing apt with annotationProcessor would be enough and I wouldn't have ran into this issue at all.
Solution
Annotations need to be processed by both annotationProcessor and kapt, which seems to be Kotlin's own annotation processor.
For each Gradle dependency that uses annotations, you should have both of the following in your app-level build.gradle:
annotationProcessor 'com.example.my.library:x.y.z
kapt 'com.example.my.library:x.y.z