Skip to content

Commit

Permalink
Fix build error for Android projects that use `apply plugin: "com.and…
Browse files Browse the repository at this point in the history
…roid.library"` (#22312)

Summary:
This PR allows Android projects that use `apply plugin: "com.android.library"` to build successfully. A recent regression caused by #20526 means that building one of these projects always fails with this error:

```
FAILURE: Build failed with an exception.

* Where:
Script '/Users/james/src/SampleLibrary/node_modules/react-native/react.gradle' line: 15

* What went wrong:
A problem occurred configuring project ':app'.
> Could not get unknown property 'applicationVariants' for object of type com.android.build.gradle.LibraryExtension.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
```

This change updates `react.gradle` to cater to both application and library projects by selectively using `android.applicationVariants` or `android.libraryVariants`.

Fixes #22310.
Pull Request resolved: #22312

Differential Revision: D13373742

Pulled By: cpojer

fbshipit-source-id: 64c35ab7a6d5d0d840a43729123e70dd8e0d36e0
  • Loading branch information
jtreanor authored and facebook-github-bot committed Dec 7, 2018
1 parent 2831d9e commit c090758
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion react.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def bundleConfig = config.bundleConfig ? "${reactRoot}/${config.bundleConfig}" :


afterEvaluate {
android.applicationVariants.all { def variant ->
def isAndroidLibrary = plugins.hasPlugin("com.android.library")
def variants = isAndroidLibrary ? android.libraryVariants : android.applicationVariants
variants.all { def variant ->
// Create variant and target names
def targetName = variant.name.capitalize()
def targetPath = variant.dirName
Expand Down Expand Up @@ -96,6 +98,9 @@ afterEvaluate {
def packageTask = variant.hasProperty("packageApplication")
? variant.packageApplication
: tasks.findByName("package${targetName}")
if (variant.hasProperty("packageLibrary")) {
packageTask = variant.packageLibrary
}

def resourcesDirConfigValue = config."resourcesDir${targetName}"
if (resourcesDirConfigValue) {
Expand Down

0 comments on commit c090758

Please sign in to comment.