Skip to content

Latest commit

 

History

History
203 lines (124 loc) · 8.55 KB

IDE-Setup.md

File metadata and controls

203 lines (124 loc) · 8.55 KB

IDE Setup

Arcs can be developed in the IDE of your choice. Here are some helpful hints to get started.

Android Studio

  1. Install Android Studio. When prompted, install the needed SDK Android 10 (SDK version 29).

  2. Open Android Studio and install the Bazel extension (Configure > Plugins). This should prompt you to restart the IDE, if not restart anyway.

  3. Upon restarting Android, click "Import Bazel Project"

  4. Select the workspace by navigating to the arcs folder, then click "Next".

  5. Choose "Import project view file" and click on the three dots.

  6. Navigate to the arcs folder, and select the as.bazelproject file. Click "OK".

  7. Click "Next".

  8. Click "Finish".

  9. Install or Update the Kotlin Plugin, at minimum version 1.3+.

  • If installed, update the plugin to the latest version via Tools > Kotlin > Configure Kotlin Plugin Updates.

IntelliJ

Install IntelliJ. Community Edition is sufficient. For web technologies support, install Ultimate Edition.

  • During the setup (within Featured Plugins stage), ensure that Android is enabled.

Add Bazel support

  1. Open IntelliJ and install the Bazel extension (Configure > Plugins). This should prompt you to restart the IDE, if not restart anyway.

  2. Upon restarting IntelliJ, click "Import Bazel Project"

  3. Select the workspace by navigating to the arcs folder, then click "Next".

  4. Choose "Import project view file" and click on the three dots.

  5. Navigate to the arcs folder, and select the ij.bazelproject file. Click "OK".

  6. Click "Next".

  7. Click "Finish".

  8. Install or Update the Kotlin Plugin, at minimum version 1.3+.

  • If installed, update the plugin to the latest version via Tools > Kotlin > Configure Kotlin Plugin Updates.

Add Android support

If you have Android Studio already installed, you may skip the next few steps, as this will be automated.

  1. Download the command line tools for your OS.

  2. After extraction, store the tools directory in the platform-appropriate location

OS Location
Linux /home/<USER_NAME>/Android/Sdk
Windows C:\Users\<USER_NAME>\AppData\Local\Android\sdk
MacOS /Users/<USER_NAME>/Library/Android/sdk
  1. Download an SDK using the sdkmanager binary in Android/sdk/tools:
  $ sdkmanager --update
  $ sdkmanager --list
  $ sdkmanager 'platforms;android-29'

(If you encounter "Warning: File ~/.android/repositories.cfg could not be loaded.", create one with "touch ~/.android/repositories.cfg".)

  1. Within IntelliJ, go to File > Project Structure

  2. Go to Platform Settings > SDKs

  3. Click the + button, choose Android SDK

  4. Navigate to the sdk folder that contains the tools directory, using the above table.

Visual Studio Code

TBD

Troubleshooting

Error:Cannot run program "bazel" (in directory "$path"): error=2, No such file or directory

  1. Go to your IDE Preferences > Bazel Settings

  2. Find the Bazel binary location, and click the three dots next to it.

  3. Navigate to the correct location, and select the Bazel binary.

  • If you don't know where the Bazel binary is located, open a terminal and run which bazel.
  1. Click "Apply" then "OK"

  2. Re-import the project by hitting the Bazel logo in the upper right hand corner.

Android SDK not installed

Android Studio: Follow the prompts and then restart your IDE. IntelliJ: Follow the above instructions.

arcs/.aswb or arcs/.ijwb already exists

You may have already imported the project into your preferred IDE. Please try reopening it.

Optional: Delete the hidden folder and repeat the appropriate steps above.

Typescript is not supported by this IDE

If web technology support is not needed, choose .bazelproject instead of ij.bazelproject. If web technologies are needed, consider upgrading to the ultimate edition of IntelliJ.

My OS (read: MacOS) doesn't let me point to the Android SDK / It only displays user created directories

Consider using the IDE file chooser instead of the native one.

IDE not responding after Bazel Sync

  • Try increasing the memory heap allocation.
  • Open the .bazelproject file. Comment out the targets or directories that are not relevant to your current task, then re-sync.

IDE shows Unresolved Reference for generated entities

Assumptions:

  • Your Kotlin plugin is at version 1.3.61 or higher: Preferences > Plugins > Installed > Kotlin
  • Your IDE is at an recent enough version
IDE Version
Android Studio 3.5+
IntelliJ TBD
  • Bazel is version 1.2 (2.0+ may cause problems)

Verified Fixes:

  • Local solution: Right click the directory with the BUILD file > Partially Sync /...
  • Global solution: Non-incrementally sync the project: Bazel > Sync > Non-incrementally sync project with BUILD file
  • Note: This works because the project may require two builds or syncs in order to "warm up" the generated sources.

Hail-Mary Fixes:

  • Try Invalidating Caches: File > Invalidate Caches > Invalidate and Restart
  • Try this workaround (1 should be sufficient).

Bazel cannot read environment variables

  • Workaround: Launch your IDE from the command line
OS Command
Linux /opt/android-studio-stable/bin/studio.sh
Windows TBD
MacOS /Applications/Android Studio.app/Contents/MacOS/studio
  • Create a ~/.xsessionrc file with the following contents:

    if [ -f ~/.profile ]; then
         . ~/.profile
    fi
    

    Please subsitute .profile (or repeat) with either .bash_profile or .bashrc -- wherever you have vital environment variables. After, log out and log back in to your system.

  • Otherwise, try one of these workarounds.

.../arcs/WORKSPACE:33:1: //external:android/sdk depends on @androidsdk//:sdk in repository @androidsdk which failed to fetch. no such package '@androidsdk//': Either the path attribute of android_sdk_repository or the ANDROID_HOME environment variable must be set.

Follow these steps.

Error:(15, 1) Couldn't build file path/to/file/ParticleName_GeneratedSchemas.jvm.kt: error executing shell command: '/bin/bash -c bazel-out/k8-fastbuild/bin/path/to/file/ParticleName_genrule_jvm.sh' failed (Exit 127)

Follow these steps.

node: not found or tsc: not found

Follow these steps.

Robolectric Errors in Android JUnit Tests

Examples:

  • Can not set static final org.robolectric.internal.IShadow field org.robolectric.shadow.api.Shadow.SHADOW_IMPL to org.robolectric.internal.bytecode.ShadowImpl
  • java.lang.NoClassDefFoundError: Could not initialize class org.robolectric.util.reflector.UnsafeAccess

The likely culprit is an incompatibility between the version of Robolectric and the version of Java on your machine.

We recommend that you use Java 8 or 11. Other Java versions have been associated with errors at the time of writing (2020-07).

To check the Java versions installed on your machine, run:

  • MacOS: /usr/libexec/java_home -V.
  • Linux: sudo update-alternatives --config java
  • Windows: Consult this documentation.

java -version will show which one is in use.

To choose a new version of Java, update your JAVA_HOME variable:

  • MacOS / Linux: add export JAVA_HOME=<path/to/JDK11/or/JDK1.8> to the appropriate ~/.profile file (i.e. ~/.bash_profile or ~/.bashrc). Thereafter, restart your IDE.
  • Windows: See this documentation.

References

Bazel integration with IntelliJ documentation