Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to open Project in Android Studio #1760

Open
TiBz0u opened this issue Jan 15, 2025 · 8 comments
Open

Impossible to open Project in Android Studio #1760

TiBz0u opened this issue Jan 15, 2025 · 8 comments
Labels
Milestone

Comments

@TiBz0u
Copy link

TiBz0u commented Jan 15, 2025

Hi,

We are using Cordova since a long time. Build is well working through the Cordova CLI.

However, i'm wondering why gradle is now moved to "tools" folder into the android project.

Due to that, we cannot import the project into Android Studio. I have the following error.

> Failed to apply plugin 'com.android.internal.version-check'.
   > Minimum supported Gradle version is 8.4. Current version is 8.2. If using the gradle wrapper, try editing the distributionUrl in /Users/<user_name>/workspace/<client_name>/<project_name>/platforms/android/gradle/wrapper/gradle-wrapper.properties to gradle-8.4-all.zip`

The gradle folder is placed into a TOOLS folder...

Do I miss something?

Thanks in advance

Ionic:

Ionic CLI : 7.2.0
Ionic Framework : @ionic/angular 6.3.2
@angular-devkit/build-angular : 13.3.9
@angular-devkit/schematics : 13.3.9
@angular/cli : 13.3.9
@ionic/angular-toolkit : 6.1.0

Cordova:

Cordova CLI : 12.0.0 ([email protected])
Cordova Platforms : android 13.0.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 15 other plugins)

Utility:

cordova-res : 0.15.4
native-run : not installed globally

System:

Android SDK Tools : 26.1.1
ios-deploy : 1.12.2
ios-sim : 8.0.2
NodeJS : v16.20.2
npm : 8.19.4
OS : macOS Unknown
Xcode : Xcode 15.4 Build version 15F31d

Kr.

TiBz0u

@breautek
Copy link
Contributor

However, i'm wondering why gradle is now moved to "tools" folder into the android project.

The AGP (Android Gradle Plugin) is the thing that does the minimum supported gradle check. The problem is if you have a single gradle project, then using the gradle wrapper (or gradlew) command to update the gradle wrapper will fail due to... the minimum version check, because the wrapper task still loads AGP and AGP will complain.

Part of this is because Gradle community recommends checking the gradle wrapper so that end users don't have to update their own gradle wrapper, so if there was a version bump it can be managed by a single person. However, that means checking in binary code into the repository and distributing that which is against Apache policies for security reasons.

So in order to reduce reliance on a particular system gradle version, but still allow older gradle wrappers to update to a newer version, we have a "dummy" tools project that doesn't import the AGP and the CLI is configured to use the wrapper from the dummy project. Hence why this works from the cordova CLI.

Android Studio will have it's own configurations and you'll need to configure gradle to use a compatible gradle version. This might also mean having to upgrade Android Studio if you're using an older version. Cordova Android 13 should work with Android Studio Ladybug out of the box, assuming default settings on both the Cordova Android project and Android Studio.

Hopefully this answers your question?

@TiBz0u
Copy link
Author

TiBz0u commented Jan 15, 2025

Hi @breautek ,
Thanks for your quick response. Is it a recent changes? Like Cordova-Android 13? I don't remember having this way of working before.

Second, I think the documentation here must be updated https://github.com/apache/cordova-android/blob/master/README.md

Thrid, I have Iguana. Is it a reason Ladybug works?
https://developer.android.com/build/releases/gradle-plugin#android_gradle_plugin_and_android_studio_compatibility

Thanks!

@breautek
Copy link
Contributor

breautek commented Jan 15, 2025

Like Cordova-Android 13? I don't remember having this way of working before.

Cordova-android 12 and earlier did behave slightly different in that the gradle wrapper task was executed on the main android project, using the system gradle version. This means you'd need to install and upgrade your system gradle install to a version compatible by the AGP version being used. So if AGP required min 8.3 for example, you would need system gradle install at version 8.3 at least, for cordova android to install it's desired wrapper.

In cordova-android 13 using the dummy tools project, the gradle version installed on the system is much more flexible and isn't restricted to what AGP needs. The project can still install the correct wrapper version which is then used by the builds (which will also satisfy AGP requirements)

Second, I think the documentation here must be updated https://github.com/apache/cordova-android/blob/master/README.md

Can you explain what part of the README should be updated?

Thrid, I have Iguana. Is it a reason Ladybug works?
https://developer.android.com/build/releases/gradle-plugin#android_gradle_plugin_and_android_studio_compatibility

Iguana is definitely older. Cordova-android 13 is configured to use AGP 8.3.0 by default. I also think Android Studio has an embedded gradle that it uses, which is likely 8.2 based on the error message. Iguana supports up to AGP 8.3 (according to Android docs) but will probably require additional configurations to make it work.

Ladybug is definitely recommended for Cordova-Android 13 though, as it was the version used for testing on Cordova Android 13 release. FWIW, setting up a new cordova android project and then opening it up in Android Studio Ladybug it builds without further action. My system gradle version is also 8.7.

@TiBz0u
Copy link
Author

TiBz0u commented Jan 17, 2025

Hi @breautek ,

Thanks for your response.

AGP 8.3 requires Gradle 8.4 and Android tells me 8.2. Maybe that have Gradle included but potentially, not smart from Google to not include the right version :/

Regarding my remark for the documentation, if everything works out of the box in Ladybug, it's good.
https://github.com/apache/cordova-android/blob/master/README.md#debugging-in-android-studio

For opening on Android Studio for debug purpose, only way for me is to add a Gradle Wrapper and I can click on the elephant icon (Sync Project with Gradle files).

However, i can use my system gradle to build with

gradle cdvBuildDebug
gradle cdvBuildRelease

Side question I see normal that gradle cdvPrintProps fails?

Kr.

@breautek
Copy link
Contributor

For opening on Android Studio for debug purpose, only way for me is to add a Gradle Wrapper and I can click on the elephant icon (Sync Project with Gradle files).

With Iguana or Ladybug?

With Ladybug I can build and debug just fine, using a sample "HelloWorld" cordova application. I did not use any Cordova CLI commands other than to add the plaform.

Image

The only time I'd have to sync with gradle is if there was an actual gradle file change while the IDE was opened.

Now I am pretty sure when using the IDE, you end up using the embedded gradle runtime (e.g. you don't use the tools gradle wrapper stuff.) If you right click the android module and Open Module Settings. Project Structure dialog will open and under the Project menu I think you can change the Gradle Version that the IDE uses:

Image

Which for me is Gradle 8.9 (gradle wrapper is actually configured to use 8.7 so I think that shows it's not using the "correct" gradle version)

AGP 8.3 requires Gradle 8.4 and Android tells me 8.2. Maybe that have Gradle included but potentially, not smart from Google to not include the right version :/

Yah you'd think they would just not declare Iguana as a supported IDE if Iguana ships/uses with Gradle 8.2, but I think perhaps using the Project Structure settings maybe you can select a newer gradle version. Ideally 8.7 but any version that is 8.4+ should work.

Side question I see normal that gradle cdvPrintProps fails?

I'm not actually familiar with that gradle task. Good chance it's bugged but if it's failing gracefully and it's job is just to print stuff probably not a big deal.

@breautek
Copy link
Contributor

breautek commented Jan 17, 2025

Which for me is Gradle 8.9 (gradle wrapper is actually configured to use 8.7 so I think that shows it's not using the "correct" gradle version)

I think perhaps if Cordova CLI as part of the prepare step initialized the gradle wrapper and copied/moved the wrapper to the proper folder, then the IDE would just pick up the wrapper.

This way it can initialise the wrapper using nearly any gradle version using the :tools module, which doesn't depend on AGP and is not restricted to gradle requirements of AGP, but then have the IDE still use the expected wrapper. Reason why this is important is because if the project uses AGP 8.3, which expects Gradle 8.4... then you couldn't use Gradle 8.2 to install a Gradle wrapper 8.4+. That's why the tools project doesn't import AGP and is used exclusively to setup the wrapper. We are just missing a move/copy step (not sure which one would be best, we might want to retain a wrapper copy inside the tools project)

Right now Cordova only sets up the wrapper on build (e.g. cordova build android). You can easily test if this will work with Iguana if you run the Cordova CLI build command. platforms/android/tools/ should now have the gradle wrapper.

cordova create testapp
cd testapp
cordova platform add android@13
cordova build android
cd platforms/android
cp -r tools/gradle ./
cp tools/gradlew* ./

Now open the project in Android Studio Iguana, and you should see it using Gradle 8.7 and I assume it would build just find on that IDE version since Android does state the IDE supports AGP 8.3.

If that works, I can look into making this improvement in the CLI so that the wrapper is placed in the proper location for IDE usage.

@TiBz0u
Copy link
Author

TiBz0u commented Jan 17, 2025

Hi @breautek ,

I always speak about Iguana. I have atm some security constraints to update Android Studio by myself on my current workstation.

Now I am pretty sure when using the IDE, you end up using the embedded gradle runtime (e.g. you don't use the tools gradle wrapper stuff.) If you right click the android module and Open Module Settings. Project Structure dialog will open and under the Project menu I think you can change the Gradle Version that the IDE uses:

Even if open the project structure in Android Studio and choose 8.4, 8.7 or even 8.9, the IDE fails with the same error.

Image
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.version-check'.
   > Minimum supported Gradle version is 8.4. Current version is 8.2.

Regarding your last message, it's quite funny because it was what I'm doing (manually) since I created this ticket to make it work for debugging purpose :) But for me, it was a "workaround" thinking I miss something else :)

cp -r tools/gradle ./
cp tools/gradlew* ./

With those two commands, the Sync With Gradle button works directly.

Meanwhile, I'll add a after_build hook for this copy.

Thanks for the support and will try to be there the 31th Jan for the Cordova Meeting.

@breautek
Copy link
Contributor

Regarding your last message, it's quite funny because it was what I'm doing (manually) since I created this ticket to make it work for debugging purpose :) But for me, it was a "workaround" thinking I miss something else :)

I see haha! Yah I realised I kinda went in a circle, but I do now fully understand the issue I think and I do plan on addressing it some point. But I don't know if it will make it into any patch release. Right now I don't have much volunteer time available to contribute. I'll make a milestone and add this issue though so it's not forgotten, but it might only be addressed in the next major. Kinda depends on how things gets rolled out, if it gets too close to major release time for API 36 support.

Thanks for the support and will try to be there the 31th Jan for the Cordova Meeting.

Awesome! :)

@breautek breautek added the bug label Jan 17, 2025
@breautek breautek added this to the 13.0.1 milestone Jan 17, 2025
@breautek breautek modified the milestones: 13.0.1, 14.0.0 Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants