apache / cordova-android

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

feat!: API 34 Support #1678

Open breautek opened 6 months ago

breautek commented 6 months ago

Platforms affected

Android

Motivation and Context

Adds in support for the next android platform

Closes https://github.com/apache/cordova-android/issues/1661 Closes https://github.com/apache/cordova-android/pull/1596

Description

This PR supercedes and includes https://github.com/apache/cordova-android/pull/1596

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

Default Configuration Changes

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

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

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 encounter this on a simple project, so it might be required depending on what the plugins does.

AGP 8.2

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

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.

Android Studio

The recommended Android Studio to use with AGP 8.2 is Android Studio Hedgehog.

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 Ran in one of my projects

Pending Tasks:

These are tasks that are still need to be done before this PR is ready for review.

Checklist

codecov-commenter commented 6 months ago

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (4742358) 72.35% compared to head (c94b62c) 72.60%.

Files Patch % Lines
lib/builders/ProjectBuilder.js 62.50% 3 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1678 +/- ## ========================================== + Coverage 72.35% 72.60% +0.24% ========================================== Files 23 23 Lines 1834 1825 -9 ========================================== - Hits 1327 1325 -2 + Misses 507 500 -7 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.