This is my setup:
AndroidStudio Lombok Plugin is installed
Enable Annotation Processing is checked in AndroidStudio Settings
Gradle wrapper is using version 4.6
I am using kotlin version 1.2.71
I am using com.android.tools.build:gradle:3.2.1
I tried "Invalidate cache / Restart AndroidStudio" after each change
Lombok dependencies are defined like this:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
dependencies {
compileOnly "org.projectlombok:lombok:1.18.2"
kapt "org.projectlombok:lombok:1.18.2"
}
When I build the app, I get the followin error:
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.18.2.jar (org.projectlombok:lombok:1.18.2)
I also tried this dependency setup:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
dependencies {
compileOnly "org.projectlombok:lombok:1.18.2"
annotationProcessor "org.projectlombok:lombok:1.18.2"
}
But then I get "cannot find symbol"-errors all over the place, because no getters/setters are generated by lombok.
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.18.2.jar (org.projectlombok:lombok:1.18.2)
Try adding it as annotationProcessor:
annotationProcessor 'org.projectlombok:lombok:1.18.2'
However, read this: Is it possible to use Lombok with Kotlin?
Lombok does not run on your source code, but on the AST. Anyway, it is
an annotation processor that is run at compile-time by the Java
compiler. The Kotlin compiler does not use these annotation
processors. See also the answer
https://stackoverflow.com/a/35530223/2621917 straight from the horse’s
mouth.
Related
The plugins mentioned below are there in the gradle file
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
the following dependency is also added in the same
implementation 'androidx.recyclerview:recyclerview:1.1.0'
Added this one as well;
implementation 'com.android.support:recyclerview-v7:25.3.1'
the error is appearing when I am writing recyclerView in the OnCreate Funtionenter image description here
Could you please suggest, how the error can be resolved.
do check the apt version of rein the
app-> project structure-> dependencies-> + symbol -> library dependencies
try it
Problem statement
I want to use AspectJ in an Android build with Gradle whilst instrumenting the built app with Firebase Performance Monitoring.
Unfortunately the build fails in the DEX merge step with Type android.support.v4.app.INotificationSideChannel$Default is defined multiple times: ...
Findings
In app/build/ajc-transform.log I found:
Wed Jul 22 07:55:14 CEST 2020
ABORT
Exception thrown from AspectJ 1.9.4
This might be logged as a bug already -- find current bugs at
http://bugs.eclipse.org/bugs/buglist.cgi?product=AspectJ&component=Compiler
Bugs for exceptions thrown have titles File:line from the top stack,
e.g., "SomeFile.java:243"
If you don't find the exception below in a bug, please add a new bug
at http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ
To make the bug a priority, please include a test program
that can reproduce this exception.
Expecting .,<, or ;, but found firebaseperf while unpacking <MessageType:Lcom/google/android/gms/internal/firebase-perf/zzdz<TMessageType;TBuilderType;>;BuilderType:Lcom/google/android/gms/internal/firebase-perf/zzdy<TMessageType;TBuilderType;>;>Ljava/lang/Object;Lcom/google/android/gms/internal/firebase-perf/zzgr;
In the project root there is a ajcore.log:
java.lang.IllegalStateException: Expecting .,<, or ;, but found firebaseperf while unpacking <MessageType:Lcom/google/android/gms/internal/firebase-perf/zzdz<TMessageType;TBuilderType;>;BuilderType:Lcom/google/android/gms/internal/firebase-perf/zzdy<TMessageType;TBuilderType;>;>Ljava/lang/Object;Lcom/google/android/gms/internal/firebase-perf/zzgr;
at org.aspectj.util.GenericSignatureParser.parseClassTypeSignature(GenericSignatureParser.java:204)
at org.aspectj.util.GenericSignatureParser.parseFieldTypeSignature(GenericSignatureParser.java:155)
at org.aspectj.util.GenericSignatureParser.parseFormalTypeParameter(GenericSignatureParser.java:130)
at org.aspectj.util.GenericSignatureParser.parseAsClassSignature(GenericSignatureParser.java:51)
at org.aspectj.weaver.UnresolvedType.forGenericTypeSignature(UnresolvedType.java:275)
at org.aspectj.weaver.bcel.BcelWorld.addSourceObjectType(BcelWorld.java:479)
at org.aspectj.weaver.bcel.BcelWorld.addSourceObjectType(BcelWorld.java:453)
at org.aspectj.weaver.bcel.BcelWeaver.addClassFile(BcelWeaver.java:456)
at org.aspectj.weaver.bcel.BcelWeaver.addClassFile(BcelWeaver.java:480)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.initBcelWorld(AjBuildManager.java:908)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performBuild(AjBuildManager.java:253)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBuildManager.java:189)
at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(AjdtCommand.java:114)
at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:60)
at org.aspectj.tools.ajc.Main.run(Main.java:371)
at com.archinamon.api.AspectJWeaver$doWeave$2.invoke(AspectJWeaver.kt:128)
at com.archinamon.api.AspectJWeaver$doWeave$2.invoke(AspectJWeaver.kt:14)
at com.archinamon.api.AspectJWeaver$Companion.runBlocking(AspectJWeaver.kt:182)
at com.archinamon.api.AspectJWeaver.doWeave$android_gradle_aspectj(AspectJWeaver.kt:126)
at com.archinamon.api.transform.AspectJTransform.transform(AspectJTransform.kt:182)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:284)
[...]
Used Gradle configuration
Here's a reduced version of my build.gradle files:
project level:
buildscript {
[...]
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
[...]
classpath "com.archinamon:android-gradle-aspectj:4.2.1"
classpath "com.google.gms:google-services:4.3.3"
classpath "com.google.firebase:firebase-crashlytics-gradle:2.2.0"
classpath "com.google.firebase:perf-plugin:1.3.1"
}
}
[...]
app level:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.firebase.firebase-perf'
[...]
apply plugin: 'com.archinamon.aspectj'
[...]
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
[...]
implementation "com.google.firebase:firebase-analytics:17.4.4"
implementation "com.google.firebase:firebase-analytics-ktx:17.4.4"
implementation ("com.google.firebase:firebase-crashlytics:17.1.1"
implementation ("com.google.firebase:firebase-perf:19.0.7"
[...]
}
Investigation
Firebase-perf conflicting with let plugin
https://github.com/firebase/quickstart-android/issues/770
I've tried the approaches mentioned there, but they did not solve my problem.
I found out that the order of the plugins matters. Applying the AspectJ plugin before the Firebase plugins in the app level build.gradle solved my issue:
apply plugin: 'com.android.application'
apply plugin: 'com.archinamon.aspectj'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.firebase.firebase-perf'
[...]
I have problems referencing my android library modules in my projects. Beside the main app module I use to have an android library module with either util stuff or as data module. I reference it in app module like that:
dependencies {
implementation project(":data")
}
When I build the project, it´s giving me lot of error messages 'Unresolved reference: ...' for all stuff that I reference in the app module to the android library module. But the IDE itself doesn´t have a problem, Intelligent finds all classes, interfaces etc., imports are fine, nothing is red. The android library module itself builds and creates aar-file in the output. It´s the compileDebugKotlin task that fails
Any general idea what may be related to that?
Found the problem, my android library module was missing the kotlin configuration:
apply plugin: 'kotlin-android'
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion:<version>"
}
Although I used kotlin .kt files in it, it could build without and also
Tools -> Kotlin -> 'Configure Kotlin in projects'
had told me 'All modules with Kotlin files are configured'
Your module's build.gradle file should have:
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
dependencies {
...
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
...
}
In my case It was apply plugin: 'kotlin-android',
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
and also added it on build.gradle
androidExtensions {
experimental = true
}
If it is a kotlin module make sure to add in its build.gradle file
apply plugin: 'kotlin'
I was using CoroutineWorkers and in my case I had to add work-runtime-ktx dependency to use it
implementation "androidx.work:work-runtime-ktx:2.4.0"
Is it possible to use kotlin-allopen gradle plugin for android testing with mockito?
I've tried to add kotlin-allopen plugin to my build.gradle and define the annotation.
buildscript {
ext.kotlin_version = '1.0.6'
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-allopen'
apply plugin: 'kotlin-android'
allOpen {
annotation("com.mycompany.OpenForTest")
}
And these for annotation itself
annotation class OpenForTest
It's not working for me. Maybe I miss something?
Yes you can.
Because it's a compiler plugin, you'll get all-open code after compilation.
So it should work with tests.
Don't worry.
Edit: according to the comment area, updating the kotlin plugin version seems work. Currently the newest version is 1.2.41.
First add the dependency in your build.gradle (project) file:
dependencies {
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
}
After that apply the plugin in your build.gradle (app mobdule) file:
apply plugin: 'kotlin-allopen'
Then specify the list of annotations that will make classes open:
allOpen {
annotation('com.example.myproject.OpenForTesting')
}
And use this annotation for every class which you want to be open
#OpenForTesting
Here is the Kotlin official documentation about All-open: https://kotlinlang.org/docs/reference/compiler-plugins.html
Hope this help
While setting up realm in project by following this documentation.
below is my project level gradle :
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// Realm
classpath "io.realm:realm-gradle-plugin:1.2.0"
}
app level gradle :
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'
dependencies {
final DAGGER_VERSION = '2.7'
....
def daggerCompiler = "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
annotationProcessor daggerCompiler
testAnnotationProcessor daggerCompiler
androidTestAnnotationProcessor daggerCompiler
compile "com.google.dagger:dagger:$DAGGER_VERSION"
provided 'org.glassfish:javax.annotation:10.0-b28' //Required by Dagger2
}
This is one of the most serious downsides of Dagger 2 - its error reporting is terrible. I regularly observe these kind of errors, and you can't understand a thing from that message.
The problem is that Dagger 2 pre-processor runs before javac compilation, and if the code couldn't be processed, then pre-processor fails without generating components implementations. To my best knowledge, the pre-processor doesn't report what error caused the failure. Then, when javac compilation executed it fails because it can't find the generated file, but it doesn't proceed to compilation of other files, therefore the only error you see is about missing Dagger component.
What I do in such cases is three stepped solution:
Review VCS history and visit all changed files. Since IDE compiles each file upon visit, I will see if any of them has compilation errors.
If #1 didn't help, I would try to incrementally remove Dagger 2 code from the project (commit beforehand!) and try to recompile on the way. When Dagger 2 is removed from problematic region, Dagger components will be generated and javac comilation will show you the actual errors.
If nothing else helps, I'm visiting all project files one-by-one. Have done it twice already, and it is a nightmare.
I know nothing about Realm, but since I see it uses its own plugin, you could start by changing the order of plugins appliance in build.gradle. Switch these lines:
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'
This answer is based off of Vasiliy's previous answer. I'm promoting my comments to his/her answer to make the solution that worked for me more visible.
As Vasiliy suggested, reversing these lines:
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'
to
apply plugin: 'realm-android'
apply plugin: 'com.neenbedankt.android-apt'
allowed the reporting of an underlying Realm error that was preventing Dagger from generating my application component class (in my case, a breaking change introduced in Realm 2.x).
After addressing this issue, with the reordered apply plugin lines I received this error:
java.lang.IllegalArgumentException: XXX is not part of the schema for this Realm
By reordering the plugins, Realm annotations are not being processed as needed. So the plugin lines must then be restored to:
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'