问题
I'm on Windows 10 and I've created a Ionic 5.0.7 app with Capacitor 2.0.0.
I use this command to build app:
ionic build
After, I use this command:
npx cap sync
And, to finish, I use this command to open Android Studio:
npx cap open android
The first problem come during building on Android Studio:
org.gradle.api.reflect.ObjectInstantiationException: Could not create an instance of type com.novoda.release.internal.compat.gradle5_3.AndroidSoftwareComponentCompat_Gradle_5_3.
Caused by: org.gradle.api.reflect.ObjectInstantiationException: Could not create an instance of type com.novoda.release.internal.compat.gradle5_3.AndroidSoftwareComponentCompat_Gradle_5_3.
And...
java.lang.NoClassDefFoundError: org/gradle/api/internal/java/usagecontext/LazyConfigurationUsageContext
Caused by: java.lang.NoClassDefFoundError: org/gradle/api/internal/java/usagecontext/LazyConfigurationUsageContext
I've other random errors... It's weird...
回答1:
Update
Check @Carl Pool 's answer They fixed it in the new capacitor Version, no need to downgrade anymore
Old Answer
To fix this downgrade Gradle and Gradle plugin in Android Studio.
File -> Project Structure -> Project
If you keep the plugin to 4.0.0 it will require a minimum Gradle version of 6 so put it back to a lower version like 3.6.3
Version 6 of Gradle does not support LazyConfigurationUsageContext as mentionened by @NishaBhat, so use 5.6.4 instead.
This issue currently has a ticket on Github: https://github.com/ionic-team/capacitor/issues/3003
回答2:
This issue has been resolved in Capacitor version 2.1.2
.
https://github.com/ionic-team/capacitor/issues/3003
Please update the Capacitor dependencies in package.json to version 2.1.2
and then in Android Studio click the button to sync the project with Gradle.
"@capacitor/android": "^2.1.2",
"@capacitor/core": "2.1.2",
回答3:
Switch to using gradle version 5.6.4. That did the trick for me. LazyConfigurationUsageContext doesn't have support in gradle versions 6.0+
回答4:
Same problem.. had many issues:
Errors and how I solved:
Error 1. Gradle sync failed: Server returned HTTP response code: 403 for URL: http://services.gradle.org/distributions/gradle-5.6.4-all.zip
Solution - Downloaded the zip file and stored in on my local in the \android\gradle\wrapper folder.
Updated the distribution URL to: distributionUrl=./gradle-5.6.4-all.zip
Error 2. java.lang.NoClassDefFoundError & java.lang.NoClassDefFoundError:
Solution - Downloaded Gradle version 5.6.4 and updated the environment variables.
Error 3. Failed to install the following Android SDK packages as some licences have not been accepted. build-tools;28.0.3 Android SDK Build-Tools 28.0.3
Updated as per the image below
回答5:
I was getting an error
Cause: org/gradle/api/internal/java/usagecontext/LazyConfigurationUsageContext
I solved by downgraded distributionUrl(gradle/wrapper/gradle-wrapper.properties
) to https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
it will give an error if above 6+
来源:https://stackoverflow.com/questions/61066014/ionic-capacitor-app-give-me-lots-of-errors