Problems compiling in Lombok IntelliJ - mac, annotations enabled - android

I have the latest lombok.jar with plugin installed, downloaded and put it in libs in my project, setting up annotations via Preferences -> Build, Execution, Deployment -> Compiler -> Annotation Processors -> Enable annotations
I am also running Android Annotations, with those annotation processing paths set specifically towards to the androidannotations-api-3.2.jar
Concerning the project, it is a clean import of a 1 year project that's not from eclipse/maven/gradle, and so it doesn't have gradle/maven with it. It is running on Java8 using Android SDK22.
The errors in compilation that I am getting as an example:
Error:(39, 16) java: cannot find symbol
symbol: method getName()
location: variable p of type com.example.Property
I've recently switched from eclipse to IntelliJ, the project can be compiled on Eclipse but I think I am missing something with IntelliJ, thoughts?

The answer to this question is making sure your project is structured in what gradle specifies, there are a multitude of answers here that will help provide you this information. Importing annotations as a dependency will also remove a lot of restrictions you may set on the project end.
Secondly, on the run configurations of the application, make sure that you add the "_" as your activity you plan on running because it has been annotated.

Related

Android studio - run annotation processor manually

Is that possible? I have changed a few basic things in my code and want to make a clean build to see how many things needs to be adjusted now. This results in 1000s of cannot find symbol class ... messages in my Messages Gradle Build window.
So I want to run the annotation processor manually now to get rid of those messages and only see the relevant messages (looking through so many messages is cumbersome and I know that all annotated classes can be build by the annotation processor without problems).
Is that somehow possible? How do I run the annotation processor in android studio manually?
You should never have to run Annotation processors manually (unless of course you are developing one).
Make sure you have Annotation Processors enabled in Android Studio (https://www.jetbrains.com/help/idea/2017.1/configuring-annotation-processing.html), Build > Clean project, and then Build > Rebuild project.
If you have everything set up correctly, this should work. However if your build is failing due to an annotation processor (Example: Dagger not meeting dependencies graph) then you will need to figure out the underlying issue.
If you are working with kotlin and using kapt there should be a task named kaptDebugKotlin you can access using gradle CLI by simply executing this command in the terminal ./gradlew app:kaptDebugKotlin
Make sure you replace app with your module name in case you have a multi-module project.
If you are working with java then simply replace app:kaptDebugKotlin with compileDebugJavaWithJavac and that should execute your annotation processor.
to force the build to continue in case of compilation error add --continue to the command in the terminal.
Happy coding.

NoClassDefFoundError for Dagger-2 generated class, using Maven in Eclipse Neon Android

I am new to Dagger-2. Previously I have successfully tried Dagger-2 demo program. Now I want to try the same in Android. For that I have done the following:
I have used Eclipse Neon for Android. In it I have installed "Android for Maven Eclipse" and m2e-apt. Then created an Android project and converted it to maven. Set java version to 1.7 for the project. Added Dagger 2.5 and Dagger-compiler 2.5 to the pom. Added the working demo code into the Android project. Unchecked the "Java Build Path -> Source -> Allow output folders for source folders". All dependencies are resolved (Eclipse doesn't report any error/warning). Dagger generates its classes. Now when I run the project, I get "NoClassDefFoundError", specifically missing Class1Module_ProvideClass1Factory. I used "apktool" to look inside the dex file. It is there. Also, prior to loading that class, some other Dagger generated classes are loaded successfully but fails only for this class. Where am I missing?

Dagger example built through eclipse fails with 'Please ensure that code generation was run for this module.'

I'm using Dagger for dependency injection in Android, using Eclipse to build. I've cloned android-activity-graphs to use as an example.
I've set up my environment according to staxgr from https://github.com/square/dagger/issues/126
These are my libs: dagger-1.1.0.jar, dagger-compiler-1.1.0.jar, and javax.inject.jar
And lastly, I've changed the source folders in Eclipse to point to src/main/java (instead of just src/) so that Eclipse detects the related files through the package keyword.
The project builds, but fails immediately when it's run with this exception:
Caused by: java.lang.IllegalStateException:
Module adapter for class
com.example.dagger.activitygraphs.AndroidModule could not be loaded.
Please ensure that code generation was run for this module.
at dagger.internal.FailoverLoader.getModuleAdapter(FailoverLoader.java:41)
at dagger.internal.Modules.getAllModuleAdapters(Modules.java:43)
at dagger.ObjectGraph$DaggerObjectGraph.makeGraph(ObjectGraph.java:167)
at dagger.ObjectGraph$DaggerObjectGraph.access$000(ObjectGraph.java:134)
at dagger.ObjectGraph.create(ObjectGraph.java:126)
at com.example.dagger.activitygraphs.DemoApplication.onCreate(DemoApplication.java:29)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1000)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4391)
How do I get Dagger examples to work through eclipse?
The problem is I am missing the javawriter library. Also, you MUST use version 2.2.1 of javawriter and NOT the latest which is 2.3.0 (this will probably change, but remains true at the time of writing this on 11/27/2013). The link provided should take you to the correct place. Please double triple check this, for a total of six times. I'll also include a list of other reasons why you might see this message.
First, please ensure that all these checkboxes are checked.
Project -> Properties ->Java Compiler -> Enable Project Specific Settings
Project -> Properties ->Java Compiler -> Annotation Processing -> Enable Project Specific Settings
Project -> Properties ->Java Compiler -> Annotation Processing -> Factory path -> Enable Project Specific Settings.
Then on the same screen, click "Add jars" and add: javawriter-2.2.1.jar, dagger-1.1.0.jar, dagger-compiler-1.1.0.jar and javax.inject.jar in this list as well for a total of four jars.
Those four jars should be in a folder called 'libs' on your project's main path.
If you are using libraries and want to use Dagger for DI in those libraries, you will have to do the steps above on those projects as well.

How to configure IntelliJ IDEA correctly to process Android Annotations?

How to configure IntelliJ IDEA correctly to process annotations?
Using the maven target processor:process works fine, but how do I process without using the maven target in IntelliJ IDEA (using it's Annotation Processing preferences)?
Under IntelliJ's preferences / Annotation Processors, I have the following setting:
"Enable annotation processing" is checked, with option "Obtain processors from project classpath"
I leave the "Annotation Processors" section empty, since it should be found through the classpath automatically I assume.
Under processed module I select my Android module and 'target/generated-sources/apt' as the 'Generated Sources Directory Name'.
In my project structure, I have the module dependencies "Maven: com.googlecode.androidannotations:androidannotations:2.6" and "Maven: com.googlecode.androidannotations:androidannotations:api:2.6" set so that I have the processor in my classpath.
But building the project doesn't process the annotations, and instead I get a warning 'Annotation processing without compilation requested but no processors were found.'
And if I try to set the Annotation Processor manually to 'com.googlecode.androidannotations.AndroidAnnotationProcessor' and choosing '/path/to/libs/androidannotations-2.6-api.jar' as the path to the processor, I'm getting the error "Annotation processor 'com.googlecode.androidannotations.AndroidAnnotationProcessor' not found" when trying to build the project.
This is my config in screenshots: http://imageshack.us/photo/my-images/841/intellijaa.png/
I still haven't gotten it to work using "Obtain processors from project classpath", but it's working now when selecting the path/jar to the processor manually.
I had actually tried that before but my mistake was that I had selected the AA-api.jar instead of the regular AA.jar.
Thanks to Dave, who gave a hint via screenshot on the AA google groups:
https://groups.google.com/forum/?fromgroups#!topic/androidannotations/PnAWuSQHkhg

How to build Android project with Scala sources in IntelliJ IDEA (Community Edition)?

I am trying to build an Android project with Scala sources in IntelliJ IDEA (Community Edition). I am using Scala sources from Java files: auto-complete works correctly, but build cannot resolve Scala classes in Java: cannot find symbol class MyScalaClass.
(I managed that in Eclipse, but Scala support in Eclipse is poor.)
Any hints or tutorials?
Update: I have added Scala module in addition to Android module. Now, build fails during generating classes.dex with message:
Error: trouble writing output: format == null
I found that it is a limitation of Dalvik: issue 7147.
How can I strip unused methods/classes in IDEA without using Ant script? (I was using ProGuard in Ant script, but I was unable make IDEA to parse Scala error messages from Ant results.)
The scala/java system requires that you:
- Build scala first, giving the compiler both scala and java files.
- Build the java sources with the compiled scala classes in the path for javac.
The second is probably what you lack. Refer to how to add directory to classpath in an application run profile in intellij idea? to add a classpath to Intellij (I suppose you did it for the android runtime, so you probably already know it).
You should use ProGuard to strip down unused classes.
Follow the instructions here (Specifically take a look at the progaurd-project.txt:
https://github.com/yareally/android-scala-intellij-no-sbt-plugin

Categories

Resources