# Android Test App Gradle Sync Troubleshooting ## Problem: Gradle Sync Failure **Error Message:** ``` Unable to find method 'org.gradle.api.artifacts.Dependency org.gradle.api.artifacts.dsl.DependencyHandler.module(java.lang.Object)' ``` ## Root Cause The Android test app was using **Gradle 9.0-milestone-1** (pre-release) with **Android Gradle Plugin 8.0.0**, causing version incompatibility issues. ## Solution Applied ### 1. Updated Gradle Version **File:** `android/gradle/wrapper/gradle-wrapper.properties` ```properties # Changed from: distributionUrl=https\://services.gradle.org/distributions/gradle-9.0-milestone-1-bin.zip # To: distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip ``` ### 2. Updated Android Gradle Plugin **File:** `android/build.gradle` ```gradle // Changed from: classpath 'com.android.tools.build:gradle:8.0.0' // To: classpath 'com.android.tools.build:gradle:8.13.0' ``` ### 3. Updated Google Services Plugin ```gradle // Changed from: classpath 'com.google.gms:google-services:4.3.15' // To: classpath 'com.google.gms:google-services:4.4.0' ``` ### 4. Updated AndroidX Dependencies **File:** `android/variables.gradle` ```gradle // Updated to latest stable versions: androidxAppCompatVersion = '1.7.1' // was 1.6.1 androidxActivityVersion = '1.8.2' // was 1.7.0 androidxCoreVersion = '1.12.0' // was 1.10.0 androidxFragmentVersion = '1.6.2' // was 1.5.6 coreSplashScreenVersion = '1.0.1' // was 1.0.0 androidxWebkitVersion = '1.8.0' // was 1.6.1 compileSdkVersion = 34 // was 33 targetSdkVersion = 34 // was 33 ``` ## Manual Fix Steps If you encounter this issue again: ### Step 1: Clean Gradle Cache ```bash cd test-apps/android-test/android ./gradlew clean ./gradlew --stop ``` ### Step 2: Clear Gradle Wrapper Cache ```bash rm -rf ~/.gradle/wrapper/dists/gradle-9.0-milestone-1* ``` ### Step 3: Re-sync Project In Android Studio: 1. Click **File** → **Sync Project with Gradle Files** 2. Or click the **Sync Now** link in the error banner ### Step 4: If Still Failing ```bash # Delete all Gradle caches rm -rf ~/.gradle/caches rm -rf ~/.gradle/wrapper # Re-download Gradle cd test-apps/android-test/android ./gradlew wrapper --gradle-version 8.4 ``` ## Prevention ### Use Stable Versions Always use stable, tested version combinations: | Android Gradle Plugin | Gradle Version | Status | |----------------------|----------------|---------| | 8.13.0 | 8.13 | ✅ Latest Stable | | 8.1.4 | 8.4 | ✅ Stable | | 8.0.0 | 8.0 | ✅ Stable | | 7.4.2 | 7.5 | ✅ Stable | | 8.0.0 | 9.0-milestone-1 | ❌ Incompatible | ### Version Compatibility Check - **Android Gradle Plugin 8.13.0** requires **Gradle 8.0+** - **Gradle 8.13** is the latest stable version - **AndroidX AppCompat 1.7.1** is the latest stable version - Avoid pre-release versions in production ## Additional Troubleshooting ### If Sync Still Fails 1. **Check Java Version** ```bash java -version # Should be Java 17+ for AGP 8.1.4 ``` 2. **Check Android SDK** ```bash echo $ANDROID_HOME # Should point to Android SDK location ``` 3. **Check Local Properties** ```bash # Verify android/local.properties exists cat test-apps/android-test/android/local.properties ``` 4. **Recreate Project** ```bash cd test-apps/android-test rm -rf android/ npx cap add android ``` ## Success Indicators After applying the fix, you should see: - ✅ **Gradle sync successful** - ✅ **No red error banners** - ✅ **Build.gradle file opens without errors** - ✅ **Project structure loads correctly** ## Next Steps Once Gradle sync is successful: 1. **Build the project**: `./gradlew build` 2. **Run on device**: `npx cap run android` 3. **Test plugin functionality**: Use the test API server 4. **Validate notifications**: Test the Daily Notification Plugin ## Related Issues - **Build failures**: Usually resolved by Gradle sync fix - **Plugin not found**: Check Capacitor plugin installation - **Permission errors**: Verify Android manifest permissions - **Runtime crashes**: Check plugin initialization code