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: android gradle wrapper update #2131

Conversation

adamTrz
Copy link
Collaborator

@adamTrz adamTrz commented Oct 24, 2023

Summary:

Check version of Android Gradle and update it when necessary.

Fixes #1837

Test Plan:

android/gradle/wrapper/gradle-wrapper.jar
android/gradle/wrapper/gradle-wrapper.properties
android/gradlew
android/gradlew.bat
  • Install dependencies
  • Then try tu run build-android or run-android against test project
  • CLI should ask you to update Gradle Wrapper and do the update

image

Checklist

  • Documentation is up to date to reflect these changes.
  • Follows commit message convention described in CONTRIBUTING.md

import execa from 'execa';

// TODO: Fetch it from somewhere?
const gradleWrapperVersionsMap: Record<number, string> = {
Copy link
Collaborator Author

@adamTrz adamTrz Oct 24, 2023

Choose a reason for hiding this comment

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

Don't really like this hardcoded array. Maybe we could fetch data about gradle versions from core somewhere?
(But that would be time consuming and then we definitely shouldn't be running checkGradleWrapper on each run of command... ) 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

In ideal world flow should look like this IMO:

  1. We cache package.json,
  2. While running run/build-android we check is it changes, if yes we do a request to GitHub and look for branch related to react-native version that is presented in package.json, then we do the logic and we run ./gradlew wrapper ...

The drawback here is that we need to be sure the source of informations, if something change in future in response we potentially will need to release X patch releases.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just get it from the react-native package directly?

% cat node_modules/react-native/template/android/gradle/wrapper/gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-all.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I'm not sure this if this isn't overly aggressive. For instance, Gradle 7.5 works fine with 0.72, but with this change, you're forcing people to upgrade even though they might not be ready for that yet. We have a similar check in RNTA, but using hard-coded values because the template isn't always right: https://github.com/microsoft/react-native-test-app/blob/1289c283c034472be5adbdc33a2238fb08b27875/android/test-app-util.gradle#L9-L45

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also, I'm not sure this if this isn't overly aggressive. [...]

Maybe we can extend prompt question with "No, don't ask again" option and store that value in cache so we won't be asking repeatedly?

}
// TODO: Do we care about minor and patch or only major version?
if (
gradleVersionForCurrent.slice(0, 2) !== gradlewWrapperVersion.slice(0, 2)
Copy link
Collaborator Author

@adamTrz adamTrz Oct 24, 2023

Choose a reason for hiding this comment

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

Do we care about patch versions of gradle or major.minor is enough here?
cc @cortinico ?

Copy link
Member

Choose a reason for hiding this comment

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

We care about every version as they might change the wrapper script at any time

@adamTrz adamTrz force-pushed the feat/android-gradle-wrapper branch 3 times, most recently from db5025a to f5b6103 Compare October 24, 2023 17:44
};

export const checkGradleWrapper = async (projectRoot: string) => {
if (process.env.CI) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this check is enough. You also need to check whether you're in an interactive shell. Otherwise this will just stall.

import execa from 'execa';

// TODO: Fetch it from somewhere?
const gradleWrapperVersionsMap: Record<number, string> = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I'm not sure this if this isn't overly aggressive. For instance, Gradle 7.5 works fine with 0.72, but with this change, you're forcing people to upgrade even though they might not be ready for that yet. We have a similar check in RNTA, but using hard-coded values because the template isn't always right: https://github.com/microsoft/react-native-test-app/blob/1289c283c034472be5adbdc33a2238fb08b27875/android/test-app-util.gradle#L9-L45

Comment on lines +43 to +51
return await prompt({
name: 'update',
type: 'select',
message: `Upgrade Gradle Wrapper to ${gradleVersionForCurrent}?`,
choices: [
{title: 'Yes', value: true},
{title: 'No', value: false},
],
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if run-android is doing too much here. Shouldn't we instead redirect people to run the doctor command instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, good call!

Copy link

There hasn't been any activity on this pull request in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

@github-actions github-actions bot added the stale label Jan 30, 2024
@github-actions github-actions bot closed this Feb 6, 2024
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.

Scaffold Gradle Wrapper differenly
4 participants