You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
4.1 KiB
4.1 KiB
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
# 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
// 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
// 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
// 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
cd test-apps/android-test/android
./gradlew clean
./gradlew --stop
Step 2: Clear Gradle Wrapper Cache
rm -rf ~/.gradle/wrapper/dists/gradle-9.0-milestone-1*
Step 3: Re-sync Project
In Android Studio:
- Click File → Sync Project with Gradle Files
- Or click the Sync Now link in the error banner
Step 4: If Still Failing
# 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
-
Check Java Version
java -version # Should be Java 17+ for AGP 8.1.4
-
Check Android SDK
echo $ANDROID_HOME # Should point to Android SDK location
-
Check Local Properties
# Verify android/local.properties exists cat test-apps/android-test/android/local.properties
-
Recreate Project
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:
- Build the project:
./gradlew build
- Run on device:
npx cap run android
- Test plugin functionality: Use the test API server
- 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