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.
Related
I have several tests in common module for multi platform Kotlin project. When I execute those tests using gradle, e.g. ./gradlew :android:test, they all go through and the tests run.
I have now encountered a more complicated problem where I would like to debug an actual test in IntelliJ. Unfortunately, upon selecting the debug option in IntelliJ, I get an No JDK specified error.
I am using the following dependencies for testing:
testImplementation "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version"
testImplementation "org.jetbrains.kotlin:kotlin-test-common:$kotlin_version"
with $kotlin_version being 1.2.41.
The common module settings looks like this:
SDKs section also correctly recognises JDKs:
I have tried changing the Module SDK from Kotlin SDK to java, however IntelliJ then wants me to require jUnit for test execution, which I would prefer not to, if possible.
Is there a way how to make the debugger run in IntelliJ for the Kotlin code?
Found the solution.
Just like it does not make sense to execute tests using Gradle in the common module alone, e.g. ./gradlew :common:test and the tests need to be executed for a specific platform ./gradlew :android:test, because the common module might contain expected declarations which are supposed to be implemented per platform using the actual keyword, it also does not make sense to debug in the common module directly.
Instead, for such purposes, the test to be debugged must be placed in a specific platform module, for my purpose I have chosen the Android module, and then it can be executed and debugged.
As I have mentioned, this approach is necessary because in the Android module the expected structures are actually replaced by the actual implementations.
I'm trying to get a better picture of what happens behind the scenes in Android Studio when building an Android application. I've been reading up on Gradle, but one thing I cannot figure out is how to see the respective CLI command and arguments that is being invoked by Gradle. It seems to be abstracted and not logged to the Gradle Console or Event Log.
The closest I've gotten to seeing what's going on inside Gradle is the AOSP code.
2.2.2 Source:
https://android.googlesource.com/platform/tools/base/+/gradle_2.2.2/build-system/gradle-core/src/main/java/com/android/build/gradle/tasks
Goals
I want to be able to see the respective CLI command that is generated by the Gradle tasks inside Android Studio.
Use Case Example
I want to view the Legacy Android Build Process in depth. This includes going through the following:
Source Code / Library Code -> javac -> Java bytecode (.class) -> proguard -> minimized bytecode (.class) -> dex -> DEX bytecode (.dex)
For example I would want to see the respective javac command invoked by AndroidJavaCompile. https://android.googlesource.com/platform/tools/base/+/gradle_2.2.2/build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/factory/AndroidJavaCompile.java
I fear that the only way to do this is to look directly through source code or even build directly from source.
Due Diligence
I've done quite a bit of searching on Google, Android blogs, Google I/O talks, Android books, and much more. I haven't been able to find a straight-forward answer.
That's not possible. Simply, because most of the Gradle tasks do not invoke CLI commands.
Every Gradle build file is a piece of Groovy code that gets executed in a JVM along with the Gradle API (written in Java). Therefor, you can implement any task or configuration functionality directly in any JVM language, from which most plugins make use of instead of executing command line tools. Nevertheless, this is possible by using or extending the Exec task.
The compilation step is handled by a AndroidJavaCompile task, which extends the common JavaCompile Gradle task by some version checks and the Instant Run feature. However, you don't know how Gradle actually compiles the .java files. In the internal source files for the JavaCompile task of the Gradle API, there seem to be various implementations (DaemonJavaCompiler, JdkJavaCompiler and even CommandLineJavaCompiler). Since you can specify CompilerOptions with your task, Gradle seems to choose the real compiler based on these options. Please note, that even if a CommandLineJavaCompiler exists, it is also possible (and highly likely), that Gradle prefers to use the javax.tools package and its JavaCompiler implementation to compile the source files instead of invoking a command line tool.
I also took a look on the ProGuard step in your example build process: ProGuard can be used as command line tool, where you can specify arguments to define how it'll work. But ProGuard also provides a Gradle task (ProGuardTask), that executes without invoking ProGuard from command line. The ProGuard Java code will be executed in the Gradle JVM.
As you can see, even if each Gradle task may be replaced by one (or multiple) CLI command(s), Gradle does not execute these commands. Instead, the functionality is called directly in the Gradle JVM. If you want to get a better insight, you can increase the Gradle log level. Good implementations of Gradle tasks should provide all necessary information in logs.
I'm trying to fire off various android based gradle tasks e.g. assemble, after 'gradle clean test' is run.
Some background...
My company has jenkins and it is managed by a separate team so I don't have access to configure it myself. On any changes to the remote repo (git) a jenkins job will fire, running gradle clean test and using a build.gradle file that we have inside our repo.
I'm told that this is the only command that the build team will provide and if I want any further actions running, I'll have to configure them inside the build.gradle script.
I am imagining that I can possibly do something like afterTest(:assemble) or maybe addTestListener() but I can't seem to find any examples on google.
Can anyone here help me? Is this even possible or should I ask my build team to allow me to run a diff gradle task depending on what I want?
Configuring CI jobs uniformly is a good idea. However, there is no good way to have additional independent tasks executed when gradle clean test is run. They'd have to at least run gradle clean build so that you can add tasks with build.dependsOn(myTask). (However, keep in mind that build already depends on assemble.) Or they run a custom task such as gradle (clean) ciBuild which by default only depends on test, and to which further task dependencies can be added as necessary.
I am having the exactly opposite problem of this other question (Command to run annotations in Intellij IDEA 12).
On my configuration, using Android Annotations, every time I rebuild the project it won't process the annotations and report the supposedly generated classes, which end with an '_', do not exist.
But when I run the project, it processes the annotations as expected.
How do I get the 'rebuild' to process 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