Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic Capacitor app give me lots of errors

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

like image 975
pirmax Avatar asked Apr 06 '20 18:04

pirmax


2 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

like image 146
Jeffrey Nicholson Carré Avatar answered Sep 18 '22 14:09

Jeffrey Nicholson Carré


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",
like image 37
Carl Poole Avatar answered Sep 20 '22 14:09

Carl Poole