Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

InstallingEnvironment

Csaba Kozák edited this page Feb 17, 2019 · 40 revisions

Introduction

Developing an annotation processor is not something very common, but hopefully we went through many different bugs and solved them. We now have a quite stable and clean dev environment, so you should be able to contribute to AndroidAnnotations by following these simple steps.

Installing the environment

  • Install Git
  • Install JDK 1.8
  • Install IntelliJ
  • Install the latest version of the Android SDK
    • In the SDK Manager, Install the latest SDK Tools, Build Tools, Platform Tools and SDK Platform 16
    • Set the ANDROID_HOME environment variable: export ANDROID_HOME=<path_to_android-sdk>

Getting the sources

  • Fork the repository
  • Clone the repository to your computer:
git clone git@github.com:YOUR_USERNAME/androidannotations.git

Importing into IntelliJ

  • First make sure the project builds on the command line. Open a terminal in the AndroidAnnotations folder inside the repository, then execute ./mvnw install.
  • Go to File > Open > browse folder the AndroidAnnotations file in the repository and double-click it.
  • The IDE will show Non-managed pom.xml file found notification, expand it and click Add as a Maven Project.
  • Unfortunately, due to an IntelliJ bug, you have to adjust the AndroidManifest.xml and res folder paths manually. Go to File > Project structure > Facets. For each facet, in the Structure tab, change the manifest to point to src/main/AndroidManifest.xml inside the module, and the resources directory to point to src/main/res inside the module. In the Maven tab, uncheck the Manifest and Resources directory checkboxes, so IntelliJ will not undo your settings when you reimport the project.

Running the compile-time tests

Compile-tests can be found under the src/test/java folder of the processor modules. These tests can verify the validation, and also check whether the generated compiles, and contains the expected strings. But does not run the generated code.

  • To run these tests, simply open a test class, and in the left side of the editor, click the test marker. You can also debug them in this way, the debugger will hit the breakpoints you put in the processor code.
  • Alternatively, you can right click a package, or the processor module itself in the Project explorer, then select Run tests in or Debug tests in.

Running the functional tests

These tests can be found in the test modules (xx-test) under the src/test/java folder. These tests verify that the generated code compiles, and also run it then assert the expected runtime behavior.

  • To run these tests, right click the method name, the class name or the file in the project explorer. Click Debug or Run, then choose the second option in the selector ( JUnit test case icon ).

Debugging processing in the test projects

It is little bit trickier to debug the code generation of the xx-test modules, because you have to attach the debugger to the compiler itself.

  • Go to File > Settings > Build, Execution, Deployment > Compiler. In the Shared build process VM options field, enter -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005, then click OK.
  • Go to Run > Edit configurations. Add a new Remote configuration with the green plus button.
  • Go to an annotated class in a test module, change it. Then click Build > Make module. The compilation will wait for you to attach the debugger.
  • Run the previously created remote configuration. Now you are debugging the processing, and which will stop at breakpoints.

Note: You may have to run the remote configuration several times, as the compiler will wait when building the other dependent modules. We did not found a way to modify the compiler settings only for the test module, please share it, if you do.

Note: Do not forget to remove the flags in Shared build process VM options if you do not want to debug, because the build will always pause if you hit Make (due to suspend=y).

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Extending AndroidAnnotations

Clone this wiki locally