apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.66k stars 1.54k forks source link

cordova-android 9.0 problem - Could not initialize class com.android.build.gradle.internal.VariantManager #1078

Closed fjellandermedia closed 3 years ago

fjellandermedia commented 4 years ago

Issue Type

Description

Build fails, even on new projects. It works with cordova-android@8.1, but not on cordova-android@9.0. This is the output:

Gabriels-MBP:test gabriel$ cordova build android Checking Java JDK and Android SDK versions ANDROID_SDK_ROOT=/Users/gabriel/Library/Android/sdk (recommended setting) ANDROID_HOME=/Users/gabriel/Library/Android/sdk (DEPRECATED) Using Android SDK: /Users/gabriel/Library/Android/sdk Subproject Path: CordovaLib Subproject Path: app

FAILURE: Build failed with an exception.

  • Where: Build file '/Users/gabriel/Documents/cordova/test/platforms/android/app/build.gradle' line: 20

  • What went wrong: A problem occurred evaluating project ':app'. Could not initialize class com.android.build.gradle.internal.VariantManager

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 1s Command failed with exit code 1: /Users/gabriel/Documents/cordova/test/platforms/android/gradlew cdvBuildDebug -b >/Users/gabriel/Documents/cordova/test/platforms/android/build.gradle`

I have updated to latest Cordova CLI and latest SDK:s and build tools in Android Studio.

Command or Code

cordova create test se.fjellandermedia.test testApp cd test cordova platform add android cordova build android

Environment, Platform, Device

Macbook Pro, macOS 10.15.6

Version information

Checklist

fjellandermedia commented 3 years ago

Can someone please help me with this. I've tried countless things: tweaked gradle version, kotlin version, updated everything in Android Studio, removing and reinstalling the cordova platform, reinstalling cordova, and more. I always get the same error message. Everything works on cordova-android@8.1.0 but not on cordova-android@9.0.0.

breautek commented 3 years ago

Please provide the output of cordova info

fjellandermedia commented 3 years ago

Cordova Packages:

cli: 10.0.0
    common: 4.0.2
    create: 3.0.0
    lib: 10.0.0
        common: 4.0.2
        fetch: 3.0.0
        serve: 4.0.0

Project Installed Platforms:

android: 9.0.0

Project Installed Plugins:

Environment:

OS: macOS Catalina 10.15.7 (19H2) (darwin 19.6.0) x64
Node: v12.13.0
npm: 6.14.8

android Environment:

android:

ERROR: Command failed with ENOENT: android list target spawn android ENOENT

Project Setting Files:

config.xml:

<?xml version='1.0' encoding='utf-8'?>

TestApp A sample Apache Cordova application that responds to the deviceready event. Apache Cordova Team
package.json:

--- Start of Cordova JSON Snippet --- { "plugins": {}, "platforms": [ "android" ] } --- End of Cordova JSON Snippet ---

breautek commented 3 years ago

Do you have android API 29 installed?

You can install it via Android Studio SDK Manager.

Make sure you have the android platform 29 installed under SDK Platforms and build tools 29 under SDK Tools. You may need to check Show Package Details to see specific versions for each item. Cordova is specifically tested against build tools version 29.0.2.

Given that you're missing an executable, you may also need to install the command line tools, also available under SDK Tools tab. I believe it's a separate entry now and not automatically included with the android platform.

fjellandermedia commented 3 years ago

Yes, I have it installed. I earlier had build-tools 29.0.3 but I now unistalled it and installed build-tools 29.0.2 instead. It didn't work, however.

Skärmavbild 2020-10-28 kl  14 18 20 Skärmavbild 2020-10-28 kl  14 27 02

The first time I try to build after a reinstall of the android platform I get this error message:

Gabriels-MacBook-Pro:test gabriel$ cordova build android Checking Java JDK and Android SDK versions ANDROID_SDK_ROOT=/Users/gabriel/Library/Android/sdk (recommended setting) ANDROID_HOME=/Users/gabriel/Library/Android/sdk (DEPRECATED) Using Android SDK: /Users/gabriel/Library/Android/sdk

BUILD SUCCESSFUL in 1s 1 actionable task: 1 executed Subproject Path: CordovaLib Subproject Path: app Starting a Gradle Daemon, 4 stopped Daemons could not be reused, use --status for details

FAILURE: Build failed with an exception.

BUILD FAILED in 6s Command failed with exit code 1: /Users/gabriel/Documents/cordova/test/platforms/android/gradlew cdvBuildDebug -b /Users/gabriel/Documents/cordova/test/platforms/android/build.gradle

All consecutive times I get the error message in my first post.

fjellandermedia commented 3 years ago

Given that you're missing an executable, you may also need to install the command line tools, also available under SDK Tools tab. I believe it's a separate entry now and not automatically included with the android platform.

I had one instance of the command line tools installed, I now try to install some of the others.

Skärmavbild 2020-10-28 kl  14 30 54
breautek commented 3 years ago

Does this work without kotlin?

Try turning kotlin off by using

<preference name="GradlePluginKotlinEnabled" value="false" />

False should be the default value for this setting.

fjellandermedia commented 3 years ago

Does this work without kotlin?

Try turning kotlin off by using

<preference name="GradlePluginKotlinEnabled" value="false" />

False should be the default value for this setting.

In the config.xml?

breautek commented 3 years ago

In the config.xml?

Yes

fjellandermedia commented 3 years ago

I tried it. After a reinstallation of cordova-android it doesn't show the first error anymore. It does however still show the

com.android.build.gradle.internal.VariantManager

error i mentioned in my first post.

Thank you very much for investigating this with me. I very much appriciate it!

breautek commented 3 years ago

I tried it. After a reinstallation of cordova-android it doesn't show the first error anymore. It does however still show the

com.android.build.gradle.internal.VariantManager

error i mentioned in my first post.

Thank you very much for investigating this with me. I very much appriciate it!

Well now I'm going to start blaming gradle...

First I want to make sure you're using a compatible java version though. Can you run java -version and give me the output.

Also print out the information from the following command:

/Users/gabriel/Documents/cordova/test/platforms/android/gradlew -v

fjellandermedia commented 3 years ago

This is now resolved! I think it was the java version. I had (if memory serves) 1.8.0_20, so I realize now it was quite old. I downloaded the latest 1.8 and now I have 1.8.0_271 and this error is no more.

Thank you very much Norman, for your time. I very much appriciate it! I wish there was anything I could do for you.

breautek commented 3 years ago

Glad I could help :)

jayeshdhage07 commented 3 years ago

Could not initialize class com.android.build.gradle.internal.VariantManager

_I am having the same issue, Java version I am using "1.8.0271"

Ionic:

Ionic CLI : 6.12.4 (C:\Users\Administrator\AppData\Roaming\npm\node_modules\@ionic\cli)

Cordova:

Utility:

  1. cordova-res : not installed
  2. native-run : 1.3.0

System: