-
Notifications
You must be signed in to change notification settings - Fork 968
Update and fix Gradle setup #588
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
Update and fix Gradle setup #588
Conversation
b69cc2a
to
444404f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks great!
What do you think @mikehardy?
jsconfig.json | ||
commitlint.config.js | ||
changelog.js | ||
assets/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep this and not publish them to npm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, it should not be published. Please also check the updated files
section in package.json
- It works in tandem with npmignore, and declares files that are included.
444404f
to
a30a2d0
Compare
Rebased onto latest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks good
it would be cool to test against our example
@jgcmarins - Thanks for your comment and review.
|
I was thinking of testing against our example
yes, it's unrelated |
@jgcmarins do tou think you are good to go with this PR? I was seeing that the CI are broken, but this dont looks related to this |
Yes |
a30a2d0
to
5eb4f5f
Compare
*/xcuserdata/ | ||
.DS_Store | ||
.npmignore | ||
Pods/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@friederbluemle just a question - I notice you put sub-.npmignore files in here and android and I just recently published a react-native-device-info package with accidental inclusions of stuff here, even though I attempted to npmignore them at the top level. Have you seen that before? Is that why you have layered npmignore going on in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @mikehardy - Good question. The way NPM handles npmignore, gitignore, and the files
field in package.json
can be surprising and unintuitive. There are a bunch of special cases if one file exists but not the other, the files
field is present or not, if matches are located at the root level or in a subfolder etc.
The reason I put two .npmignore
files in the android/
and ios/
folder is because the very precisely ignore only files related to that platform with minimal duplication (for example, you won't find a .gradle/
in the ios/
folder).
Since android/
and ios/
are included using the files
field in package.json
, it is not possible to just use one .npmignore
file at the root level to exclude files from those directories. Hope that makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clear as mud :-), but the tools' fault not yours as it is not easy to un-tangle how the different include/excludes work (what priority, whitelist or blacklist, when directives short-circuit other directives etc). For now in RNDI I just do a clean pre-package but I had not thought of nested npmignore files. Thanks for the explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a good article that explains some of it in more detail:
https://medium.com/@jdxcode/for-the-love-of-god-dont-use-npmignore-f93c08909d8d
I also opened this one in react-native-device-info
with similar changes:
react-native-device-info/react-native-device-info#872
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great job here
thanks
5eb4f5f
to
69061d8
Compare
Rebased and updated to latest Android Gradle plugin @jgcmarins - Could you take another quick look at this and merge if you have a minute? Thanks! 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great
69061d8
to
eeb7817
Compare
url 'https://maven.google.com' | ||
// The Android Gradle plugin is only required when opening the android folder stand-alone. | ||
// This avoids unnecessary downloads and potential conflicts when the library is included as a | ||
// module dependency in an application project. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@friederbluemle this is not really the place to mention it but this just came through and reminded me - the one place I've seen this style fail is react-native-webview. It depends on kotlin, and that has to be on the classpath or the module build breaks a project build, but most projects (? my project anyway) does not by default have kotlin yet. So until (if?) the react-native template is altered to include kotlin not all modules may be de-duplicated like this. To be clear: not related to this PR, just for information
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the heads-up @mikehardy 👌
@jgcmarins - Rebased again onto the latest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great job, thanks
@friederbluemle should we upgrade example as well? |
@jgcmarins Thanks for merging! 👍 |
* master-base: (215 commits) Update react-native to 0.61.4 (react-native-share#637) Update and fix Gradle setup (react-native-share#588) set useNativeDriver explicitly for Animations (react-native-share#633) correctly type image source (react-native-share#632) ci(fix): adapt to new workflow (react-native-share#626) fix: added missing "v" to `source` field in podspec (react-native-share#619) chore(readme): mocking with Jest example (react-native-share#610) iOS 13: Resolve promise if ShareSheet is manually dismissed (react-native-share#607) Update README.md fix: remove uncessary tools replace on build gradle chore(lint): fixing lint errors Makes sharing with Snapchat work on Android (react-native-share#464) Fixed validate error Removed react-native Share dependency Only call successCallback when completed is true Change readme.md Update Gradle wrapper to 5.6.2 build(deps): bump eslint-utils from 1.4.0 to 1.4.2 (react-native-share#580) Send email to predefined email address - Example Send email to predefined email address ...
Overview
Android Gradle plugin
This wraps the Android Gradle plugin dependency in the
buildscripts
section ofandroid/build.gradle
in a conditional:A small change with a big impact:
The Android Gradle plugin is only required when opening the project stand-alone, not when it is included as a dependency. By doing this, the project opens correctly in Android Studio, and it can also be consumed as a native module dependency from an application project without affecting the app project (avoiding unnecessary downloads/conflicts/etc).
Gradle wrapper
Similarly, the Gradle wrapper (and related scripts) are only required for stand-alone editing/building of the
android
folder. It should not be distributed. Android Studio will automatically generate a wrapper, or alternatively one can be generated on the command line on-the-fly (see below).UPDATE 2019-11-19: Due to CI changes since this PR was opened, the Gradle wrapper has temporarily been added back. It will be removed in a follow-up PR that also includes other simplifications to the CI config.
Support lib conflict
There was also an
appcompat-v7
leftover in build.gradle which caused the following error in Android Studio:Since this project has already been converted to AndroidX, and React Native 0.60+ pulls in the androidx dependencies, this line is no longer needed.
.npmignore config
In a separate commit, this PR also includes a small update to the npmignore config of the project. By defining precisely which files get added to the distributed archive, along with excluding things like the Gradle wrapper jar a significant size reduction of the distribution artifact to almost a third of the previous value was achieved:
Before:
After:
Test Plan
What's required for testing (prerequisites)?
Android Studio and/or Gradle installed locally.
What are the steps to reproduce (after prerequisites)?
Open
android
in Android Studio:Or:
Generate a Gradle wrapper on the fly, and build on command line:
cd android/ gradle wrapper --gradle-version 5.4.1 --distribution-type all ./gradlew build
Successfully verified and tested on:
Once approved, please use a normal GitHub merge (i.e. NO rebase/squash merge) to integrate the commit(s) from the PR head branch. The changes are broken up into meaningful, atomic commits, and my branch should already be up-to-date with the latest base branch. If it isn't, or if you want me to change anything, please let me know, and I will update the branch as soon as possible. Thank you!