Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'

Hi, I´m having the following error while trying to “run” my Android app in Android studio:
Could not determine the dependencies of task ‘:app:compileDebugJavaWithJavac’.

Could not resolve all task dependencies for configuration ‘:app:debugCompileClasspath’.
Could not resolve project :capacitor-android.
Required by:
project :app
No matching configuration of project :capacitor-android was found. The consumer was configured to find an API of a component, as well as attribute ‘com.android.build.api.attributes.BuildTypeAttr’ with value ‘debug’ but:
- None of the consumable configurations have attributes.

At the end of the build, Android studio result in that error and open the device emulator without open the app.

Just in case, I add the android capacitor in a virtual linux machine with “ionic capacitor add android”, then “ionic capacitor copy android” without issues but I copied the Android project generated from my Linux virtual machine (currently using virtual box) to my windows PC in order to open the app in Android studio (this due to resources limitations) but when execute “run” I had the above issue. Please help.

Hi pabloArayacr02,

This error might occurs when some Cordova or Capacitor plugin has old android support dependencies instead of using the new AndroidX equivalent. You should report the issue in the plugin repository so the maintainers can update the plugin to use AndroidX dependencies.

Evaluate your plugins and remove/modify/upgrade as necessary and try a new build with the changes.

As a workaround, you can also patch some plugins using jetifier:

npm install jetifier
npx jetify

The jetifier should be in package.json file.

You need to include a postinstall script in package.json for jetifier to run. This can be done as shown below:

"scripts": { 
...
"postinstall": "jetifier"
}

Finally, if the npm running the jetifier script needs permissions.

In the file named .npmrc (create the file if not already present) in the root of your project, add the following contents.

unsafe-perm=true

Cheers,