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?
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.
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.
I do have a project with an app and a library module that contains JNI code. I added a test class to the 'androidTest' folder in order to test all this in a device environment.
At the time doing, Android Studio 2.2.2 was able to identify the code as test (adding all the nice icons to run the whole class test and so on).
Now (a large number of commits and git rebasing later) I want to do some more work, but Android Studio refuses to accept the code as test code, although gradle itself (invoked with :libname:connectedAndroidTest) does perform the tests and writes timing info into some XML in the ./build/outputs/androidTest-results/connected of the library module folder.
The AS editor marks all unit testing related imports in red. When I try to resolve the "problem" AS suggests to "Add library 'runner-0.5' to classpath" although build.gradle already contains that reference.
AFAIR I was also able to select the library module in the "Module" setting in the General tab of the Android Test run configuration. But that doesn't work anymore.
What puzzles me is, that I some had this all working from within the IDE and now it doesn't work anymore. Although the gradle call will still run the test cases that the compiler doesn't complain about anything...
Any ideas anybody?
PS:
I do know that I can move the "androidTest" code into a differen module. However I do already have 10+ modules in my project. And since gradle is able to run the test, why is Android Studio not anymore?
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.