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

Android - Fix Drawable v4 paths in Android Artifact Resources (Libraries) #13128

Closed
wants to merge 11 commits into from

Conversation

jpshelley
Copy link
Contributor

@jpshelley jpshelley commented Mar 24, 2017

Quick apologies for the lengthiness of this description. Want to make sure I'm clear and it is understood what is being altered.

Thanks for submitting a PR! Please read these instructions carefully:

  • Explain the motivation for making this change.
  • Provide a test plan demonstrating that the code is solid.
  • Match the code formatting of the rest of the codebase.
  • Target the master branch, NOT a "stable" branch.

Motivation (required)

#5787

Unknown source file : /home/tom/projects/blueprint-native/android/app/build/intermediates/res/merged/release/drawable-mdpi-v4/images_google.png: error: Duplicate file.

Unknown source file : /home/tom/projects/blueprint-native/android/app/build/intermediates/res/merged/release/drawable-mdpi/images_google.png: Original is here. The version qualifier may be implied.

At Hudl, we've been attempting to package our React Native code into Library Dependencies (Cocoapods / Android Artifact Resource (aar)). Recently in React Native 0.42.0, there was an upgrade to the Android Project's gradle plugin from 1.3.1 to 2.2.3. This update drastically effected the outcome of drawable resources in Android without anyone noticing.

There are 4 outcomes to consider with this change:

  1. You are developing in an Android Application using Gradle 1.3.1 or lower
  2. You are developing in an Android Application using Gradle 2.2.3 or higher
  3. You are developing in an Android Library Module using Gradle 1.3.1 or lower
  4. You are developing in an Android Library Module using Gradle 2.2.3 or higher

With the upgrade to 2.2.3, Android changed the way aapt builds its resources. Any Library created with 2.2.3, has its resources ending with a v4 suffix. The reasoning behind this I'm not sure of but assume it deals with Vector support that was added around that time.

The change I've added checks if React Native is being ran in an Android Library vs an Application, and appends the v4 suffix to the merged asset folders.

Test Plan (required)

Multiple test were performed.

  1. I first started out validating my assumption about the asset merger by creating a new Android Project to verify my assumptions above.

    1. Application + >= 2.2.3 -- hdpi contains my drawable. hdpi-v4 contains dependency's drawables.
    2. Application + <= 1.3.1 -- Same as above (I expect because deps are compiled against gradle 2.2.3+ themselves.
    3. Library + >= 2.2.3 -- Only -v4 folders found! Resources from the library are packages in the app's build output in similar -v4 folder too.
    4. Library + <= 1.3.1 -- Same as ii. & iii. -v4 contains other resources, but my resources are located in non -v4 folder.
  2. I then wanted to validate against React Native itself. So I updated my react native code using this PR/Branch, and tested against my project locally. Unfortunately I cannot share that code as it is private, but before this change I was getting the same error as mentioned in gradlew assembleRelease failing at processReleaseResources [0.19] #5787 and now my build runs as intended with the assets being placed where they should be.

Additional resources:

Please let me know if more information is needed, further test plans, etc. With this change we should be able to upgrade to Gradle 2.3.0 as well to support the latest version of Android Studio.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. GH Review: review-needed labels Mar 24, 2017
* master: (161 commits)
  Use the absolute path to the sourcemap in the CS bundle
  packager: index files by dir for fast matching
  Revert D4840716: Refactor interfaces
  packager: GlobalTransformCache: make key globalized
  Check that RCTDidInitializeModuleNotification is being called with the correct bridge
  Refactor interfaces
  Report JS errors in debug console
  Apple TV documentation
  Move away from rnplay to snack, with embedded examples!
  use performanceNow instead of Date.now() in ScrollResponder
  Deploy v0.43.0
  Removed some no-longer-necessary Flow ignores.
  Update Keyboard.js
  configurable devEnabled in React.gradle
  Use tag ids for testID
  Update IntegrationWithExistingApps.md
  Update docs to clarify `RCT_REMAP_METHOD` usage.
  Enable flow in react-native-implementation
  Improve z-index implementation on Android
  Remove the dependency of I18nManagerModule on ReactApplicationContext
  ...
@jpshelley
Copy link
Contributor Author

@vonovak @AndrewJack Would you be able to review? I noticed both of you as the most recent to edit/review this file in git.

@vonovak
Copy link
Contributor

vonovak commented Apr 10, 2017

@jpshelley I don't understand drawables, but just wondering - why you use moveFunc.curry("ldpi").call() instead of just moveFunc("ldpi")?

@AndrewJack
Copy link
Contributor

AndrewJack commented Apr 10, 2017

Does this only occur when applying the script to a library project?

This script was made to support Applications (com.android.application). Not sure if we want to add this to the gradle script?

Do you have a sample project that reproduces this issue?

@jpshelley
Copy link
Contributor Author

@AndrewJack From what I've gathered, it is only happening on Library Projects, that is correct. At Hudl we are taking a similar approach as Artsy and compiling our React Native code into a Library Project that can be imported into our main native apps, in order to minimize friction.

In the Test Plan I have already created 4 separate projects that show the Android build outputs for drawables to back up my claims. I can create a sample react native project that demonstrates this later today and will comment back when I have them done.

@jpshelley
Copy link
Contributor Author

Sorry for the delay @AndrewJack here are the following:

  1. A fresh project ran using react-native init DemoAndroidLibrary: jpshelley/DemoAndroidLibrary@8ca63b8
  2. A migration of React Native to an Android Library without any Images yet: jpshelley/DemoAndroidLibrary@c374a54
  3. Adding Drawables to the project: jpshelley/DemoAndroidLibrary@45e4611
  4. Upgrading Gradle and running the react native bundle command: jpshelley/DemoAndroidLibrary@6cf4eb4

Project 4 is the only one that doesn't work. Its due to the bundler (which can be ran on any commit to verify) and the upgrade of Gradle which mismatches Android Library's declared drawable folder name.

@grahammcculloch
Copy link

@AndrewJack keen to see this PR merged - will make my dev much less painful!

@AndrewJack
Copy link
Contributor

Why not just copy react.gradle in your own project and edit what you need? It's purposely a gradle script for this reason.

Your use case seems fairly uncommon so I'd hesitate including these changes.

@jpshelley
Copy link
Contributor Author

@AndrewJack We could do that, but then if react.gradle were to change in the future we would be out of the loop on any important alterations.

@jpshelley
Copy link
Contributor Author

Its been over a month, is there any remaining issues with this PR? Can it be merged?

@TBouder
Copy link

TBouder commented Jul 28, 2017

+1

@facebook-github-bot
Copy link
Contributor

@jpshelley I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project.

@facebook-github-bot
Copy link
Contributor

@jpshelley I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project.

@stale
Copy link

stale bot commented Nov 26, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Nov 26, 2017
@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Nov 28, 2017
@pull-bot
Copy link

Warnings
⚠️

📋 Release Notes - This PR appears to be missing Release Notes.

@facebook-github-bot label Needs more information

Generated by 🚫 dangerJS

@facebook-github-bot
Copy link
Contributor

@jpshelley I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project.

@pull-bot
Copy link

pull-bot commented Jan 4, 2018

Warnings
⚠️

📋 Release Notes - This PR appears to be missing Release Notes.

Generated by 🚫 dangerJS

@facebook-github-bot
Copy link
Contributor

@jpshelley I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project.

@jpshelley
Copy link
Contributor Author

@philikon @satya164 you both seem to edit this file the most. Thoughts on getting a review to merge?

@react-native-bot react-native-bot added Missing Changelog This PR appears to be missing a changelog, or they are incorrectly formatted. Ran Commands One of our bots successfully processed a command. Android labels Mar 16, 2018
@react-native-bot react-native-bot added Platform: Android Android applications. Ran Commands One of our bots successfully processed a command. labels Mar 18, 2018
@getaaron
Copy link
Contributor

Could we please merge this? 🙃

  • People are manually hacking the react.gradle file to work around this
  • It's a pretty common issue

@philikon @satya164 @AndrewJack

@getaaron
Copy link
Contributor

(@jpshelley There's a merge conflict now)

@facebook-github-bot
Copy link
Contributor

@jpshelley I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project.

@satya164
Copy link
Contributor

satya164 commented May 1, 2018

Thanks for the PR!

@facebook-github-bot shipit

@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label May 1, 2018
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@satya164 is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

macdoum1 pushed a commit to macdoum1/react-native that referenced this pull request Jun 28, 2018
…ies)

Summary:
_Quick apologies for the lengthiness of this description. Want to make sure I'm clear and it is understood what is being altered._

Thanks for submitting a PR! Please read these instructions carefully:

- [x] Explain the **motivation** for making this change.
- [x] Provide a **test plan** demonstrating that the code is solid.
- [x] Match the **code formatting** of the rest of the codebase.
- [x] Target the `master` branch, NOT a "stable" branch.

facebook#5787
```
Unknown source file : /home/tom/projects/blueprint-native/android/app/build/intermediates/res/merged/release/drawable-mdpi-v4/images_google.png: error: Duplicate file.

Unknown source file : /home/tom/projects/blueprint-native/android/app/build/intermediates/res/merged/release/drawable-mdpi/images_google.png: Original is here. The version qualifier may be implied.
```

At Hudl, we've been attempting to package our React Native code into Library Dependencies _(Cocoapods / Android Artifact Resource (aar))_. Recently in React Native 0.42.0, there was an upgrade to the Android Project's gradle plugin from 1.3.1 to 2.2.3. This update drastically effected the outcome of drawable resources in Android without anyone noticing.

**There are 4 outcomes to consider with this change:**
1. You are developing in an Android Application using Gradle 1.3.1 or lower
2. You are developing in an Android Application using Gradle 2.2.3 or higher
3. You are developing in an Android Library Module using Gradle 1.3.1 or lower
4. You are developing in an Android Library Module using Gradle 2.2.3 or higher

With the upgrade to 2.2.3, Android changed the way aapt builds its resources. Any Library created with 2.2.3, has its resources ending with a `v4` suffix. The reasoning behind this I'm not sure of but assume it deals with Vector support that was added around that time.

The change I've added checks if React Native is being ran in an Android Library vs an Application, and appends the v4 suffix to the merged asset folders.

Multiple test were performed.

1. I first started out validating my assumption about the asset merger by creating a new Android Project to verify my assumptions above.
   1. [Application +  >= 2.2.3](https://github.com/jpshelley/TestAndroidLibraryDrawables/tree/master/app/build/intermediates/res/merged/debug) -- `hdpi` contains my drawable. `hdpi-v4` contains dependency's drawables.
   2. [Application + <= 1.3.1](https://github.com/jpshelley/TestAndroidLibraryDrawables/tree/Android-LegacyVersion/app/build/intermediates/res/merged/debug) -- Same as above (I expect because deps are compiled against gradle 2.2.3+ themselves.
   3. [Library + >= 2.2.3](https://github.com/jpshelley/TestAndroidLibraryDrawables/tree/Android-UsingAndroidLibrary/library/build/intermediates/res/merged/debug) -- Only `-v4` folders found! Resources from the library are packages in the app's build output in similar `-v4` folder too.
   4. [Library + <= 1.3.1](https://github.com/jpshelley/TestAndroidLibraryDrawables/tree/Android-UsingAndroidLibraryLegacyVersion/library/build/intermediates/res/merged/debug) -- Same as ii. & iii. `-v4` contains other resources, but my resources are located in non -v4 folder.

2. I then wanted to validate against React Native itself. So I updated my react native code using this PR/Branch, and tested against my project locally. Unfortunately I cannot share that code as it is private, but before this change I was getting the same error as mentioned in facebook#5787 and now my build runs as intended with the assets being placed where they should be.

Additional resources:
* facebook#5787
* http://stackoverflow.com/questions/35700272/android-build-tool-adds-v4-qualifier-to-drawable-folders-by-default-in-generated
* facebook#12710

Please let me know if more information is needed, further test plans, etc. With this change we should be able to upgrade to Gradle 2.3.0 as well to support the latest version of Android Studio.
Closes facebook#13128

Differential Revision: D7828618

Pulled By: hramos

fbshipit-source-id: a7ad7b63b1b51cbfd2ea7656e4d77321306ce33a
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. Import Started This pull request has been imported. This does not imply the PR has been approved. Missing Changelog This PR appears to be missing a changelog, or they are incorrectly formatted. Platform: Android Android applications. Ran Commands One of our bots successfully processed a command.
Projects
None yet
Development

Successfully merging this pull request may close these issues.