# General Guidelines for Resolving Android Build Errors  

When a build error occurs, follow these steps:  
1. Identify the error from the build logs.  
2. Match it against known error patterns listed below.  
3. Apply the appropriate fix using the provided commands.  
4. Retry the build and check if the issue is resolved.  

## 1. Missing Dependency Errors (JitPack-based Libraries)
Error Message: "Could not find net.opacapp:multiline-collapsingtoolbar:27.1.1"
Fix:
1. Confirm whether the dependency version exists in public Maven repositories:
    ```
    curl -I https://repo.maven.apache.org/maven2/<group_path>/<artifact>/<version>/<artifact>-<version>.pom
    ```
If the result is `404`, it doesn't exist there.
2. If it's a GitHub-based library, switch to the JitPack-compatible Maven coordinates:
    ```
    implementation 'com.github.<user>:<repo>:+'
    ```
Use `+` as <tag>, which means use the **latest successfully built version** from GitHub.
3. In `build.gradle` (project-level) ensure JitPack is in the repositories:
    ```
    allprojects {
        repositories {
            google()
            mavenCentral()
            maven { url 'https://jitpack.io' }
        }
    }
    ```

## 2. Library Method Signature Error  
Error Message: "No signature of method: java.util.ArrayList.call() is applicable for argument types"
Fix: 
1. In `build.gradle`, ensure that `dependencies` section does not contain outdated or incompatible libraries.  
   - Upgrade the Android Gradle Plugin if necessary:  
     ```
     ./gradlew dependencies | grep 'com.android.tools.build'
     ```
   - If outdated, update the plugin in `build.gradle`:  
     ```
     dependencies {
         classpath 'com.android.tools.build:gradle:7.0.0' // Example version
     }
     ```
   - Run a Gradle sync:  
     ```
     ./gradlew clean build
     ```

## 3. Java Version Mismatch
Error Message: "Could not determine java version from '17.0.14'.", "Unsupported class file major version 61"
Fix:
1. Get gradle version of the project:
   ```
   grep distributionUrl gradle/wrapper/gradle-wrapper.properties | sed -E 's/.*gradle-([0-9.]+)-.*/\1/'
   ```
   You should capture `5.2` (for example)
2. Check the compatible Java version based on identified Gradle version in below table:
   || Gradle version || Java version ||
   || 2.0~ || 8 ||
   || 5.5~ || 11 ||
   || 7.3~ || 17 ||
   || 8.5~ || 21 ||
   For example, if Gradle version is 7.0.2, you should install Java 11.
3. Install Java:
   ```
   apt update && apt install -y openjdk-<version>-jdk
   ```
   Try older Java versions upon install failure. If already installed, proceed to next step.
4. **IMPORTANT** Execute this line:
   ```
   export JAVA_HOME=<new_java_path>
   ```

## 4. Missing keystore file
Error Message: "Keystore file '.*' not found for signing config", "signing.properties (No such file or directory)"
Fix:
1. Create a dummy keystore file:
    ```
    touch signing.properties
    ```
    or
    ```
    touch <filename>.keystore
    ```
  

## Final Notes
- IMPORTANT: If `gradlew not found` or unknown error happens when executing Gradle commands, use `find . -name gradlew` command to locate gradlew. Make sure that your working directory is the folder with the gradlew file every command.
- If you're not sure which error or the same error persists over several cycles, then check logs using stacktrace option.
- Use `--refresh-dependencies` if dependencies are outdated:  
  ```
  ./gradlew --refresh-dependencies
  ```
- Avoid `./gradlew clean` commands since they have minor impact on resolving issues while being excessively lengthy. Use it only when you get unfamiliar build errors repeatedly.
- Avoid using git clone to start since the directory is already cloned, unless you meet many errors and need to reset the environment.
- If BUILD SUCCESS but the output includes warning, ignore them and check if the .apk file is generated. Your primary goal is to generate the .apk file.
- When using linux commands, always use bash compatible commands.
- Use `find . -name *.apk` to check output .apk file.
- Empty output does not necessarily mean command failure. For example, `export` or `chmod` commands do not output anything, so you can continue.
- Some projects explicitly state required dependencies and environment versions in `README.md`. If build fails, read the `README.md` file to look for the cause of failure.
- Command `goals_accomplished` is used only for build success. Do not use the command until you have built a working .apk file. DO NOT call this command on build failures. Instead, attempt different kinds of approaches to the problem.
- Avoid interactive prompts at all costs. Use specific non-interactive flags instead.
- If you encounter multiple issues, approach them one by one. Attempts to resolve multiple issues in a single command might be not only ineffective but also cause other problems.