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] Wrong packageName for multiple app modules #938

Closed
ecexplorer opened this issue Jan 30, 2020 · 9 comments
Closed

[Android] Wrong packageName for multiple app modules #938

ecexplorer opened this issue Jan 30, 2020 · 9 comments
Labels

Comments

@ecexplorer
Copy link

Environment

System:
OS: macOS 10.15.2
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Memory: 81.31 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.4.0 - /usr/local/bin/node
Yarn: 1.17.0 - /usr/local/bin/yarn
npm: 6.9.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.5977832
Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.5 => 0.61.5
npmGlobalPackages:
create-react-native-module: 0.11.0
react-native-cli: 2.0.1

Description

On an Android Project which has multiple app modules, the generated PackageList (presumably for auto-linking) attempts to import the wrong BuildConfig and R resources for any module which is not first (alphabetically).
So, assuming you go to build the second app module, the CLI will attempt to import the module's BuildConfig and R resources under the package name of the first module.

Reproducible Demo

  • Create a new React Native project using the CLI
  • in the android folder, copy the app directory into another new directory ("bapp")
  • add the new module in the settings.gradle for the project
  • rename the package id to be different from the app module.
  • attempt to build the bapp module

Expected behavior: bapp should build.
Observed behavior: bapp fails to build as generated PackageList file attempts to import BuildConfig & R using package id from app module.

@ecexplorer
Copy link
Author

Yes, I know that I can use react-native.config.js to configure packageName. By doing this, I can set the value to the module I want to build and it will build that module. As I'm looking to build multiple, the hack that I have to use is to have my module's build.gradle file modify the config each time I look to build.
Alternatively, I'm sure I could have both use the same package id, and then just have the release variant specify an application id suffix that would seperate each app. Again, that feels like a hack.

@thymikee
Copy link
Member

Hey there! We try to partially tackle this with #871, can you have a look?

@thymikee thymikee added bug Something isn't working and removed bug report labels Mar 11, 2020
@ecexplorer
Copy link
Author

ecexplorer commented Mar 12, 2020

@thymikee #871 will resolve this issue. Thanks!

Edit: Misreported, further testing shows issue not resolved

@grabbou
Copy link
Member

grabbou commented Mar 19, 2020

We're working on merging it soon. Thanks for opening issue and providing additional context!

@grabbou
Copy link
Member

grabbou commented Mar 19, 2020

Unfortunately, this PR is not fixing your issue.

Yes, I know that I can use react-native.config.js to configure packageName. By doing this, I can set the value to the module I want to build and it will build that module. As I'm looking to build multiple, the hack that I have to use is to have my module's build.gradle file modify the config each time I look to build.

Currently, it is a CLI limitation that we support a SINGLE module, not an array. We will need to change the core of the CLI to support it.

It's on our backlog.

@grabbou
Copy link
Member

grabbou commented Mar 19, 2020

To make this work, we would have to get rid of packageName while generating PackageList class (because it's just a single value, where we have an array of different packages).

Instead, change this:

List packages = new PackageList(this).getPackages();

to

List packages = new PackageList(this, <<pass_here>>).getPackages();

and then, encourage users to use some helpers, such as:

new MyModule(getBuildProperty("name"))

so that we can define that later, not while generating the PackageList file.

@grabbou
Copy link
Member

grabbou commented Mar 19, 2020

Another option is to detect multiple packages and generate PackageList for each of them, e.g. PackageListAppA, PackageListAppB, depending on what you want to use.

This is non-breaking.

This would require we convert packageName from string to string[] at a configuration level. We will have to do that anyway for run-android.

@jasongaare
Copy link

Unsure if this is related, but I've been struggling to get auto inking to work on Android since upgrading:

react-native: 0.61.5 => 0.62.2
@react-native-community/cli: 3.0.0 => 4.8.0

The issue lies with attempting to autolink a library that is contained in our repository as a submodule directory. This submodule also happens to contain a runnable React Native app (which is why I suspect the issue occurs).

Prior to the version upgrades listed above, the autolinking worked as expected. Now it fails and presents this error:

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not resolve project :companycam_companycam-camera.
     Required by:
         project :app
      > Unable to find a matching configuration of project :companycam_companycam-camera:
          - None of the consumable configurations have attributes.

Ultimately the only solution I could get to work was to disable autolinking on Android for that dependency and revert to manual linking, which then works as expected.

This is an acceptable solution for me, but curious if there is a bigger issue or way to resolve this for others that may have the came experience.

@github-actions
Copy link

There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants