Skip to content

Commit 87dd7d3

Browse files
authored
add TROUBLESHOOTING.md
1 parent 54ed0f1 commit 87dd7d3

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

docs/dev-notes/TROUBLESHOOTING.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# 🛠️ Troubleshooting
2+
3+
This document covers common local development issues and how to resolve them.
4+
5+
## 🐘 Gradle CLI Fails Due to JDK 21
6+
7+
When running Gradle tasks outside Android Studio, errors may occur if the CLI uses a different JDK version than what's required by the project.
8+
9+
Recent versions of Android Studio (e.g. **Meerkat**) use **JDK 21** by default for Gradle. However, the project requires **JDK 17** due to compatibility constraints with [project's current Kotlin version](../buildSrc/src/main/kotlin/io.customer/android/Versions.kt#L27).
10+
11+
If the CLI uses JDK 21 (e.g. via system default), commit hooks may fail due to incompatibility with required JDK 17 as the [hook runs a Gradle task](../lefthook.yml#L6) to verify API changes in code files.
12+
13+
### Resolution Steps
14+
15+
**1. Set Gradle JDK to 17 in Android Studio**
16+
17+
Navigate to:
18+
19+
- Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle
20+
- Set Gradle JDK to JDK 17 version (e.g. `jbr-17`)
21+
- Apply changes and sync project
22+
23+
For step-by-step instructions, [refer to this answer](https://stackoverflow.com/a/79049864/1771663).
24+
25+
**2. List installed JDKs**
26+
27+
To identify installed JDK versions:
28+
```bash
29+
/usr/libexec/java_home -V
30+
```
31+
32+
**3. Configure CLI to use JDK 17**
33+
34+
Update shell profile (`~/.zshrc`, `~/.bash_profile`, etc.) to ensure the CLI uses JDK 17 for all Gradle tasks.
35+
36+
- **Option 1:** Set the path explicitly
37+
(Use this if a specific JDK 17 path is known or was listed in Step 2. The example path below may differ.)
38+
```bash
39+
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jbr-17.0.14.jdk/Contents/Home"
40+
export PATH="$JAVA_HOME/bin:$PATH"
41+
```
42+
43+
- **Option 2:** Use latest installed JDK 17 dynamically
44+
```bash
45+
export JAVA_HOME=$(/usr/libexec/java_home -v 17)
46+
export PATH="$JAVA_HOME/bin:$PATH"
47+
```
48+
49+
**4. Apply the environment change**
50+
51+
Run following command or restart the terminal:
52+
```bash
53+
source ~/.zshrc # or source ~/.bash_profile
54+
```
55+
56+
**5. Verify the JDK version used by Gradle**
57+
58+
Confirm that the CLI uses JDK 17 by running:
59+
```bash
60+
./gradlew -version
61+
```
62+
63+
Expected output:
64+
```
65+
JVM: 17.x.x
66+
```
67+
68+
### Notes
69+
70+
- This guide is written for macOS. Commands and paths may differ on other operating systems.
71+
- These are one-time setup steps per machine.
72+
- This setup ensures consistent behavior between Android Studio and CLI builds and avoids version mismatch issues before pushing updates.
73+
- Unused JDKs can be removed from `/Library/Java/JavaVirtualMachines` if needed.

0 commit comments

Comments
 (0)