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

fix: react android kotlin plugin version conflict #34255

Closed
wants to merge 4 commits into from

Conversation

hurali97
Copy link
Collaborator

@hurali97 hurali97 commented Jul 23, 2022

Summary

Fixes #34229

Basically, the react android conflicts with the kotlin version that's defined in the top level build.gradle. To resolve it, the approach was to get the kotlinVersion defined in top level build.gradle and use it. If it's not defined, we use the default(1.6.10 as of now).

The reason behind not using the DSL is that it doesn't allow us to use the variables due to it's constrained syntax.
See here

So the idea was to use the build script to resolve the kotlin plugin and it works 👍 .

Kindly asking for review @cortinico :)

Changelog

[Android] [Changed] - refactored usage of kotlin plugin

Test Plan

Ran the node ./scripts/run-ci-e2e-tests.js --js --android --ios to verify it doesn't introduce any unexpected issues.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 23, 2022
@react-native-bot react-native-bot added the Platform: Android Android applications. label Jul 23, 2022
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jul 23, 2022
@analysis-bot
Copy link

analysis-bot commented Jul 23, 2022

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 4899f8c
Branch: main

@JB-CHAUVIN
Copy link

LGTM, working on my big project.

@kelset kelset requested a review from cortinico July 26, 2022 11:17
Copy link

@Raden-Hor Raden-Hor left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@cortinico cortinico left a comment

Choose a reason for hiding this comment

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

Thanks for sending this over @hurali97 🙏 really appreciate.
Are we able to iterate on this a bit?

Comment on lines +8 to +12
buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.hasProperty("kotlinVersion") ? rootProject.ext.kotlinVersion : KOTLIN_VERSION}"
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this will have unwanted side effects. Specifically mixing buildscript{} and plugins{} in Gradle is not advised.

It seems like a workaround that we could live with 🤔 But I would look for a solution that uses only plugins{} if possible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As far as I looked, having dynamic version in plugins isn't quite possible. Since, we require to use the kotlinVersion from root level if that's present.

See here

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a note on why this is needed otherwise we'll forget about it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So the reason to go with this approach is:

use the kotlinVersion defined in top level build.gradle. If it's not defined, we use the default(1.6.10 as of now) defined in gradle.properties. We couldn't add dynamic version using the plugins DSL because of the constrained syntax, so we had to introduce the buildScript for this. See here

Should I add it as a comment in the build.gradle or are we good here?

Copy link
Contributor

Choose a reason for hiding this comment

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

We're good here 👍
I'm looking into cleaning this up a bit in the future so this will hopefully go.

@cortinico
Copy link
Contributor

Plus can we make the CI green?

@hurali97
Copy link
Collaborator Author

Plus can we make the CI green?

So CI is failing at:

/root/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java:19: error: package com.facebook.react.common.mapbuffer does not exist

and

/app/sdks/hermes/API/hermes/hermes.cpp:727:46: error: only virtual member functions can be marked 'override'

It would be great if you can help me out in this, as I don't think this might be related to the changes in this PR.

@cortinico
Copy link
Contributor

/root/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java:19: error: package com.facebook.react.common.mapbuffer does not exist

This is actually related. com.facebook.react.common.mapbuffer is a package that contains only Kotlin code. So it means that the Kotlin plugin is not applied correctly and that code doesn't get compiled

@hurali97
Copy link
Collaborator Author

hurali97 commented Jul 31, 2022

/root/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java:19: error: package com.facebook.react.common.mapbuffer does not exist

This is actually related. com.facebook.react.common.mapbuffer is a package that contains only Kotlin code. So it means that the Kotlin plugin is not applied correctly and that code doesn't get compiled

Whoa, okay. I will update once I test it on local.

@hurali97
Copy link
Collaborator Author

hurali97 commented Jul 31, 2022

@cortinico I updated the build.gradle and kotlin compilation issue is resolved. But test_android on CI is failing because of the following:

/root/react-native/sdks/hermes/API/hermes/hermes.cpp:727:46: error: only virtual member functions can be marked 'override'
jsi::BigInt createBigIntFromInt64(int64_t) override;

Also build_hermes_macos fails because:

./utils/build-apple-framework.sh: line 91: cd: ./destroot/Library/Frameworks: No such file or directory

Any leads here?

@cortinico
Copy link
Contributor

Any leads here?

IMHO a you should be find with a rebase this time

@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,610,467 +0
android hermes armeabi-v7a 7,026,972 +0
android hermes x86 7,911,133 +0
android hermes x86_64 7,884,455 +0
android jsc arm64-v8a 9,488,774 +0
android jsc armeabi-v7a 8,267,524 +0
android jsc x86 9,426,974 +0
android jsc x86_64 10,019,738 +0

Base commit: 051a677
Branch: main

@hurali97
Copy link
Collaborator Author

hurali97 commented Aug 5, 2022

@cortinico Thanks for your help 🙂 All is 🟢

@facebook-github-bot
Copy link
Contributor

@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @hurali97 in be35c6d.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Aug 8, 2022
kelset pushed a commit that referenced this pull request Aug 11, 2022
Summary:
Fixes #34229

Basically, the react android conflicts with the kotlin version that's defined in the top level build.gradle. To resolve it, the approach was to get the `kotlinVersion` defined in top level build.gradle and use it. If it's not defined, we use the default(1.6.10 as of now).

The reason behind not using the DSL is that it doesn't allow us to use the variables due to it's constrained syntax.
See [here](https://docs.gradle.org/current/userguide/plugins.html#sec:constrained_syntax)

So the idea was to use the build script to resolve the kotlin plugin and it works 👍 .

Kindly asking for review cortinico :)

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Android] [Changed] - refactored usage of kotlin plugin

Pull Request resolved: #34255

Test Plan: Ran the node ./scripts/run-ci-e2e-tests.js --js --android --ios to verify it doesn't introduce any unexpected issues.

Reviewed By: dmitryrykun

Differential Revision: D38468567

Pulled By: cortinico

fbshipit-source-id: f9ab635fcf033f1d337ed90793ba1667957b8e01
roryabraham pushed a commit to Expensify/react-native that referenced this pull request Aug 17, 2022
Summary:
Fixes facebook#34229

Basically, the react android conflicts with the kotlin version that's defined in the top level build.gradle. To resolve it, the approach was to get the `kotlinVersion` defined in top level build.gradle and use it. If it's not defined, we use the default(1.6.10 as of now).

The reason behind not using the DSL is that it doesn't allow us to use the variables due to it's constrained syntax.
See [here](https://docs.gradle.org/current/userguide/plugins.html#sec:constrained_syntax)

So the idea was to use the build script to resolve the kotlin plugin and it works 👍 .

Kindly asking for review cortinico :)

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Android] [Changed] - refactored usage of kotlin plugin

Pull Request resolved: facebook#34255

Test Plan: Ran the node ./scripts/run-ci-e2e-tests.js --js --android --ios to verify it doesn't introduce any unexpected issues.

Reviewed By: dmitryrykun

Differential Revision: D38468567

Pulled By: cortinico

fbshipit-source-id: f9ab635fcf033f1d337ed90793ba1667957b8e01
roryabraham pushed a commit to Expensify/react-native that referenced this pull request Aug 17, 2022
Summary:
Fixes facebook#34229

Basically, the react android conflicts with the kotlin version that's defined in the top level build.gradle. To resolve it, the approach was to get the `kotlinVersion` defined in top level build.gradle and use it. If it's not defined, we use the default(1.6.10 as of now).

The reason behind not using the DSL is that it doesn't allow us to use the variables due to it's constrained syntax.
See [here](https://docs.gradle.org/current/userguide/plugins.html#sec:constrained_syntax)

So the idea was to use the build script to resolve the kotlin plugin and it works 👍 .

Kindly asking for review cortinico :)

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Android] [Changed] - refactored usage of kotlin plugin

Pull Request resolved: facebook#34255

Test Plan: Ran the node ./scripts/run-ci-e2e-tests.js --js --android --ios to verify it doesn't introduce any unexpected issues.

Reviewed By: dmitryrykun

Differential Revision: D38468567

Pulled By: cortinico

fbshipit-source-id: f9ab635fcf033f1d337ed90793ba1667957b8e01
@yakubbaev
Copy link

Included in v0.70.0-rc.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Platform: Android Android applications. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error: plugin already on the classpath must not include a version
8 participants