Ionic Capacitor app give me lots of errors

Viewed 10547

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...

6 Answers

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

enter image description here

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",

Switch to using gradle version 5.6.4. That did the trick for me. LazyConfigurationUsageContext doesn't have support in gradle versions 6.0+

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+

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

enter image description here

i have not downgraded the gradle version 6.1.1 But what i did is that:

I removed these lines from build.gradle file apply plugin: 'com.novoda.bintray-release' & classpath 'com.novoda:bintray-release:0.9.1'

The Issue just gone like Boom !!

I think this Bintray Dependencies just conflicting behind the scene.

Related