-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Better Android Gradle Plugin 3.x integration #20526
Conversation
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.
hramos is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
This pull request was closed by @CFKevinRef in da6a5e0. Once this commit is added to a release, you will see the corresponding version tag below the description at da6a5e0. If the commit has a single |
…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. #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 #5787 and now my build runs as intended with the assets being placed where they should be. Additional resources: * #5787 * http://stackoverflow.com/questions/35700272/android-build-tool-adds-v4-qualifier-to-drawable-folders-by-default-in-generated * #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 #13128 Differential Revision: D7828618 Pulled By: hramos fbshipit-source-id: a7ad7b63b1b51cbfd2ea7656e4d77321306ce33a
Summary: Mirrors facebook#17967 which was imported and reverted Original: Better integration with the Android Gradle-based build process, especially the changes introduced by the [Android Gradle Plugin 3.x and AAPT2](https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html). Fixes facebook#16906, the `android.enableAapt2=false` workaround is no longer required. Bases the task generation process on the actual application variants present in the project. The current manual process of iterating build types and product flavors could break down when more than one dimension type is present (see https://developer.android.com/studio/build/build-variants.html#flavor-dimensions). This also exposes a very basic set of properties in the build tasks, so that other tasks can more reliably access them: ```groovy android.applicationVariants.all { variant -> // This is the generated task itself: def reactBundleTask = variant.bundleJsAndAssets // These are the outputs by type: def resFileCollection = reactBundleTask.generatedResFolders def assetsFileCollection = reactBundleTask.generatedAssetsFolders } ``` I've tested various combinations of product flavors and build types ([Build Variants](https://developer.android.com/studio/build/build-variants.html)) to make sure this is consistent. This is a port of what we're currently deploying to our CI process. [ ANDROID ] [ BUGFIX ] [ react.gradle ] - Support Android Gradle Plugin 3.x and AAPT2 [ ANDROID ] [ FEATURE ] [ react.gradle ] - Expose the bundling task and its outputs via ext properties Pull Request resolved: facebook#20526 Differential Revision: D9164762 Pulled By: hramos fbshipit-source-id: 544798a912df11c7d93070ddad5a535191cc3284
Mirrors #17967 which was imported and reverted
Original:
Better integration with the Android Gradle-based build process, especially the changes introduced by the Android Gradle Plugin 3.x and AAPT2.
Fixes #16906, the
android.enableAapt2=false
workaround is no longer required.Bases the task generation process on the actual application variants present in the project. The current manual process of iterating build types and product flavors could break down when more than one dimension type is present (see https://developer.android.com/studio/build/build-variants.html#flavor-dimensions).
This also exposes a very basic set of properties in the build tasks, so that other tasks can more reliably access them:
I've tested various combinations of product flavors and build types (Build Variants) to make sure this is consistent. This is a port of what we're currently deploying to our CI process.
[ ANDROID ] [ BUGFIX ] [ react.gradle ] - Support Android Gradle Plugin 3.x and AAPT2
[ ANDROID ] [ FEATURE ] [ react.gradle ] - Expose the bundling task and its outputs via ext properties
Pull Request resolved: #20526
GitHub Author: CFKevinRef git@kcjr.io