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 projects with 'apply plugin: "com.android.library"' now fail to build #22310

Closed
3 tasks done
jtreanor opened this issue Nov 16, 2018 · 0 comments
Closed
3 tasks done
Labels
Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.

Comments

@jtreanor
Copy link
Contributor

Environment

Run react-native info in your terminal and paste its contents here.

React Native Environment Info:
    System:
      OS: macOS 10.14.1
      CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
      Memory: 279.43 MB / 32.00 GB
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 10.12.0 - ~/.nvm/versions/node/v10.12.0/bin/node
      Yarn: 1.10.1 - /usr/local/bin/yarn
      npm: 6.4.1 - ~/.nvm/versions/node/v10.12.0/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
      Android SDK:
        API Levels: 23, 24, 26, 27, 28
        Build Tools: 27.0.0, 27.0.3, 28.0.2, 28.0.3
        System Images: android-27 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 3.2 AI-181.5540.7.32.5056338
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.6.1 => 16.6.1
      react-native: 0.57.5 => 0.57.5
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native-create-library: 3.1.2

Description

Any Android React Native project which uses apply plugin: "com.android.library" currently fails to build. The problem is that a recent change (#20526) to react.gradle now uses android.applicationVariants when configuring the project. This is not present for library projects, so it fails.

Prior to this changes, Android library projects could be build successfully, so this is a regression.

Reproducible Demo

I have put a simple project to demonstrate the issue here: https://github.com/jtreanor/sample-library-react-native.

This project is the generated content of react-native init SampleLibrary with the only change being modifying build.gradle to add apply plugin: "com.android.library"

The following steps will reproduce the error:

  1. git clone git@github.com:jtreanor/sample-library-react-native.git
  2. cd sample-library-react-native
  3. yarn install
  4. cd android && ./gradlew build

You will see an error that looks something like this:

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
@react-native-bot react-native-bot added the Platform: Android Android applications. label Nov 16, 2018
@facebook facebook locked as resolved and limited conversation to collaborators Dec 7, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Dec 7, 2019
KusStar pushed a commit to KusStar/react-native that referenced this issue Nov 11, 2020
…roid.library"` (facebook#22312)

Summary:
This PR allows Android projects that use `apply plugin: "com.android.library"` to build successfully. A recent regression caused by facebook#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 facebook#22310.
Pull Request resolved: facebook#22312

Differential Revision: D13373742

Pulled By: cpojer

fbshipit-source-id: 64c35ab7a6d5d0d840a43729123e70dd8e0d36e0
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

2 participants