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

feat!: API 34 Support #1678

Merged
merged 18 commits into from May 13, 2024
Merged

feat!: API 34 Support #1678

merged 18 commits into from May 13, 2024

Conversation

breautek
Copy link
Contributor

@breautek breautek commented Oct 21, 2023

Platforms affected

Android

Motivation and Context

Adds in support for the next android platform

Closes #1661
Closes #1596

Description

This PR supercedes and includes #1596

This PR does a few different things to provide API 34 support which will be noted below.

Breaking Changes

These are notable changes that is breaking that may affect plugins or workflows. It doesn't highlight all breaking changes in which were hidden inside implementation details.

  • JDK 17 is now required
  • Cordova-Android will now use Gradle 8.7 by default
  • Android Studio Jellyfish. Android Studio is not required for building via the Cordova CLI.

Default Configuration Changes

Target SDK: 34
Gradle Version: 8.7
AGP Version: 8.3.0
Kotlin JVM Target: 1.8 (If kotlin is enabled)
Min Build Tools: 34

Java/Kotlin Changes

Source/Target compatibility we changed from Java 8 to 17 on both the framework and app template projects.

Source & Target compatibility have been reverted back to 8, but 2 new preferences are added to allow developers to experiment: AndroidJavaSourceCompatibility and AndroidJavaTargetCompatibility which adjusts the respective gradle compile options. By default, these values are 8, which is the same values used before.

Additionally, AndroidKotlinJVMTarget preference was added to select the Kotlin JVM target. By default, the Kotlin JVM Target will be same as AndroidJavaTargetCompatibility. Updating AndroidJavaTargetCompatibility will influence the Kotlin JVM target unless if AndroidKotlinJVMTarget is also explicitly defined.

BuildConfig

Previously this I believe was implicitly enabled, but now needs to be explictly enabled otherwise the following may occur

* What went wrong:
A problem occurred configuring project ':app'.
> com.android.builder.errors.EvalIssueException: defaultConfig contains custom BuildConfig fields, but the feature is disabled.
  To enable the feature, add the following to your module-level build.gradle:
  `android.buildFeatures.buildConfig true`

I however did not encounter this on a simple project, so it might be required depending on what the plugins does.

AGP 8.3

AGP 8.2 is the minimum version required for API 34 builds. Attempting build against API 34 on earlier versions will produce warnings and/or errors.

AGP 8.3 is however the latest version that can be used with standard Android Studio configurations.

AGP 8.4 was tested with and will mostly work, but will not work inside Android Studio without further configuration. Because we don't want to impose Android Studio configurations onto the user, AGP 8.3 is chosen for cordova-android@13 release.

Gradle -b flag

This flag has been deprecated and scheduled to be removed in gradle's next major release.
The gradle projects must follow a standard structure now. Cordova's generated project already follows the standard structure thus for cordova build commands the -b append can simply just be removed, we don't need to explicitly declare the build.gradle file.

It was also used against the wrapper.gradle file which changes are noted below.

gradle.wrapper

The "intentionally empty" gradle.wrapper file has been removed.

We no longer manually manage gradle versions. Instead, we let gradle do it for us by utilising their --gradle-version argument. A new function was introduced to replace the old runGradleWrapper to:

  1. setup the gradle wrapper if not already present
  2. install/update the gradle wrapper to the specified version.

By default, this will be 8.7 as defined in the defaults json config file, but may be overwritten by GradleVersion preference, or CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL environment variable.

If CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL is defined, the preference will be ignored and --distribution-url will be used instead, maintaining the ability for corporations to install their own gradle wrapper from their own source.

The Gradle Wrapper was previously checked into the repo and was removed. It has since returned as using the system gradle to generate the wrapper caused issues. Namely it would require end-users to have an appropriate gradle version that satisfies AGP, which kind of defeats the purpose of using wrappers.

Because -b flag will be going away, there is now a tools project that is templated and copies. This project serves as the old wrapper.gradle, in that it's an empty project that can be used by the system gradle of a varying version range to produce the gradle wrapper at the version that we need to build the android project.

~obsolete gradle-wrapper notes~

This section is no longer in the PR

While personally I do not agree with how Gradle handles this, it is their recommendation to check in the Gradle wrapper, including the jar file into the source.

To make the Wrapper files available to other developers and execution environments, you need to check them into version control. Wrapper files, including the JAR file, are small. Adding the JAR file to version control is expected. Some organizations do not allow projects to submit binary files to version control, and there is no workaround available.

As usual, you should commit the changes to the Wrapper files to version control.

This done for both our test project and the app template. On platform add, the wrapper will be copied from the template. Individual projects via GradleVersion may change the wrapper version.

Should the end user choose a gradle version below what was required by AGP, gradle will update the gradle version, but builds will fail. Attempting to update the version back to an acceptable version will cause the gradle wrapper task to fail as the wrapper task also loads in AGP. To avoid this, Cordova does a version check before executing the wrapper task and will not update the wrapper if it's below the minimum required.

Note that while by preference both Gradle Version and AGP versions are configurable, the version check is not. This means that even if you drop Gradle and AGP down a version, the current >= 8.6 check will remain. I think this is OK since these preferences are documented for internal development use.

Lastly, because of the introduction of using --gradle-version and letting gradle manage our wrappers, the clean gradle wrapper script we had for our test project became obsolete and was removed.

Android Studio

With AGP 8.3, Android Studio Jellyfish will now be required for opening the native project.

CI

JDK was updated from 11 to 17, which is a requirement to build for API 34

Testing

Ran NPM test
Ran in sample cordova hello world app, with variety of different configurations
Ran in one of my projects

Known Issues

  • The core splashscreen plugin does not compile when targeting JDK 17.

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

@breautek breautek added this to the 13.x milestone Oct 21, 2023
@codecov-commenter
Copy link

codecov-commenter commented Oct 21, 2023

Codecov Report

Attention: Patch coverage is 86.36364% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 72.50%. Comparing base (ed8e5d2) to head (b974bba).

Files Patch % Lines
lib/builders/ProjectBuilder.js 80.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1678      +/-   ##
==========================================
+ Coverage   72.15%   72.50%   +0.35%     
==========================================
  Files          23       23              
  Lines        1839     1837       -2     
==========================================
+ Hits         1327     1332       +5     
+ Misses        512      505       -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

framework/build.gradle Outdated Show resolved Hide resolved
EiyuuZack added a commit to OutSystems/cordova-android that referenced this pull request Nov 29, 2023
From upstream (apache#1678):

Gradle -b flag

This flag has been deprecated and scheduled to be removed
in gradle's next major release. The gradle projects must follow a
standard structure now. Cordova's generated project already follows the
standard structure thus for cordova build commands the -b append can
simply just be removed, we don't need to explicitly declare the
build.gradle file.

It was also used against the wrapper.gradle file which changes are noted
below.

gradle.wrapper

The "intentionally empty" gradle.wrapper file has been removed.

We no longer manually manage gradle versions. Instead, we let gradle do
it for us by utilising their --gradle-version argument. A new function
was introduced to replace the old runGradleWrapper to:

setup the gradle wrapper if not already present install/update the
gradle wrapper to the specified version. By default, this will be 8.4
as defined in the defaults json config file, but may be overwritten by
GradleVersion preference, or CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL
environment variable.

If CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL is defined, the preference
will be ignored and --distribution-url will be used instead, maintaining
the ability for corporations to install their own gradle wrapper from
their own source.

References https://outsystemsrd.atlassian.net/browse/RNMT-6402
EiyuuZack added a commit to OutSystems/cordova-android that referenced this pull request Nov 29, 2023
From upstream (apache#1678):

Gradle -b flag

This flag has been deprecated and scheduled to be removed
in gradle's next major release. The gradle projects must follow a
standard structure now. Cordova's generated project already follows the
standard structure thus for cordova build commands the -b append can
simply just be removed, we don't need to explicitly declare the
build.gradle file.

It was also used against the wrapper.gradle file which changes are noted
below.

gradle.wrapper

The "intentionally empty" gradle.wrapper file has been removed.

We no longer manually manage gradle versions. Instead, we let gradle do
it for us by utilising their --gradle-version argument. A new function
was introduced to replace the old runGradleWrapper to:

 1. setup the gradle wrapper if not already present
 2. install/update the gradle wrapper to the specified version

By default, this will be 8.4 as defined in the defaults json config
file, but may be overwritten by GradleVersion preference, or
CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL environment variable.

If CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL is defined, the preference
will be ignored and --distribution-url will be used instead, maintaining
the ability for corporations to install their own gradle wrapper from
their own source.

References https://outsystemsrd.atlassian.net/browse/RNMT-6402
@breautek breautek force-pushed the api34-support branch 2 times, most recently from b756804 to 24b72b5 Compare December 1, 2023 18:12
EiyuuZack added a commit to OutSystems/cordova-android that referenced this pull request Dec 4, 2023
The mapping is pretty straightforward:

AndroidJavaSourceCompatibility > Java Source Files - defaults to (Java) 8
AndroidJavaTargetCompatibility > Java Compiler - defaults to (Java 8
AndroidKotlinJvmTarget > Kotlin Compiler - defaults to '1.8'

AndroidJavaTargetCompatibility and AndroidKotlinJvmTarget should target
the same semantic Java version to avoid build conflicts due to different
JDKs. Only sane defaults are provided, no further checks are performed.

See apache#1678 for more info.

References https://outsystemsrd.atlassian.net/browse/RNMT-6402
@breautek breautek mentioned this pull request Dec 19, 2023
@breautek breautek force-pushed the api34-support branch 2 times, most recently from de2f1f3 to 0a1f947 Compare January 14, 2024 01:35
@breautek breautek marked this pull request as ready for review January 14, 2024 01:46
@erisu erisu modified the milestones: 13.x, 13.0.0 May 7, 2024
framework/cdv-gradle-config-defaults.json Outdated Show resolved Hide resolved
lib/prepare.js Show resolved Hide resolved
Copy link
Member

@erisu erisu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A missing small revert change.

Also the .ratignore changes could be reverted, but if reverted, need to add at least gradle-wrapper.properties. This this file is detected if anyone runs locally a rat test after running npm test.

Also needs to rebase with the main branch and fix the conflict in ci.yml.

Other then the above, everything LGTM.

I ran an npm t and confirmed that Gradle issues were resolved.

LICENSE Outdated Show resolved Hide resolved
@erisu
Copy link
Member

erisu commented May 13, 2024

Additional note regarding PR description:

Android Studio

The recommended Android Studio version to use with AGP 8.4 is Android Studio Jellyfish.

I consider it a 'hard requirement' for users to upgrade to Android Studio Jellyfish at a minimum for successful builds and seamless functionality from Android Studio, as the term 'recommended' suggests that the version is not mandatory.

Older versions of Android Studio are not compatible with AGP 8.4 and will fail.

For instance, attempting to build on the following older versions of Android Studio will result in the following error messages:

Android Studio Hedgehog

The project is using an incompatible version (AGP 8.4.0) of the Android Gradle plugin. The latest supported version is AGP 8.2.0-rc03.
See Android Studio & AGP compatibility options.

Android Studio Iguana

The project is using an incompatible version (AGP 8.4.0) of the Android Gradle plugin. The latest supported version is AGP 8.3.0-alpha14.
See Android Studio & AGP compatibility options.

@breautek
Copy link
Contributor Author

Also the .ratignore changes could be reverted, but if reverted, need to add at least gradle-wrapper.properties. This this file is detected if anyone runs locally a rat test after running npm test.

Sounds like we can keep the .ratignore as is then, cause if it detects those files after a test run, then you'll probably need the gradlew scripts to be ignored as well.

@breautek
Copy link
Contributor Author

I consider it a 'hard requirement' for users to upgrade to Android Studio Jellyfish at a minimum for successful builds and seamless functionality from Android Studio, as the term 'recommended' suggests that the version is not mandatory.

Older versions of Android Studio are not compatible with AGP 8.4 and will fail.

I've updated the wording, also added a smaller Breaking Changes section that highlights in short bullet-form of the notable breaking changes.

jcesarmobile and others added 16 commits May 13, 2024 07:17
API 34: Upgrade AGP from 8.2.0-rc01 to 8.2.0-rc02

API 34: Upgrade AGP from 8.2.0-rc02 to 8.2.0-rc03

API 34: Upgrade AGP from 8.2.0-rc03 to 8.2.0

feat: add AndroidKotlinJVMTarget preference to set the kotlin JVM target
This is in addition to the java source / target compatibility preferences.
AndroidKotlinJVMTarget is only affective if Kotlin is enabled.

chore: Upgrade Gradle from 8.4 to 8.5

AGP 8.2.0 -> 8.2.1

Gradle 8.5 -> 8.7

fix: Add --validate-url to gradle wrapper commands

AGP 8.4.0
The new default value is null. When null, it will by default
to the Java Target compatibility. Updating AndroidJavaTargetCompatibility
will also influence the Kotlin JVM target, unless if AndroidKotlinJVMTarget
is also explicitly defined.
@breautek
Copy link
Contributor Author

I've reverted AGP down to 8.3

Jellyfish appears to bundle Gradle 8.4 by default and will fail on installing the wrapper due to AGP 8.4's requirement on Gradle 8.6. In order to use AGP 8.4 on Jellyfish, the user would have to do additional configurations to specify an alternate gradle.

@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@breautek breautek requested a review from erisu May 13, 2024 12:51
Copy link
Member

@erisu erisu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM

I have tested the following:

  • cordova platform add
  • cordova build android
  • Android Studio Jellyfish
    • Gradle Sync
    • Build and Run on Emulator

I confirmed that Gradle 8.7 and AGP 8.3 is used.

@breautek breautek merged commit 89a0a72 into apache:master May 13, 2024
14 checks passed
@breautek breautek deleted the api34-support branch May 13, 2024 13:29
graphefruit added a commit to graphefruit/Beanconqueror that referenced this pull request May 25, 2024
…eded). apache/cordova-android#1678

Added kotlin version etc.

Removing splash files, after they are not longer supported with android
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support AGP 8.1+ by using JVM 17
7 participants