Skip to content

Android build/Linking issue on older RN versions: PackageList.java: error: package undefined does not exist import undefined.MyPackage #429

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

Closed
1 of 2 tasks
Tom-Bury opened this issue Jul 28, 2023 · 7 comments · Fixed by #431
Assignees
Labels
bug Something isn't working

Comments

@Tom-Bury
Copy link

Description

[Issue started from a discussion at #428]

I'm facing an issue with the plain starter template for a Native UI component on Android when including the library on older React Native version apps.

I've spun up a quick test repo which consists of a plain library setup & two plain RN apps. One on the latest RN version, the other on 0.68.6. The 68.6 RN app fails to build on Android:

.../test-create-react-native-library/AwesomeOldProject/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:15: error: package undefined does not exist
import undefined.TestCreateReactNativeLibraryPackage;
                ^
.../test-create-react-native-library/AwesomeOldProject/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:61: error: cannot find symbol
      new TestCreateReactNativeLibraryPackage()

You can find the repo here: https://github.com/Tom-Bury/test-create-react-native-library

The base steps in generating it were:

  1. Generate the plain Native UI library
  2. Pack that
  3. Generate 2 RN testapps using npx react-native@X.XX.X init AwesomeProject --version X.XX.X
  4. Include the tarball in both & add it as a dependency
  5. Use the library view in both App.tsx
  6. In each, try running yarn run android -> the new RN version runs fine, the old one fails

Packages

  • create-react-native-library
  • react-native-builder-bob

Selected options

From the discussion wih @atlj, it seems like the issue is with the template; not per se Bob

Link to repro

https://github.com/Tom-Bury/test-create-react-native-library

Environment

``
System:
OS: macOS 13.0
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 62.55 MB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.12.0 - ~/.nvm/versions/node/v18.12.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v18.12.0/bin/yarn
npm: 8.19.2 - ~/.nvm/versions/node/v18.12.0/bin/npm
Watchman: 2023.04.10.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.12.0 - /Users/tombury/.rbenv/shims/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
Android SDK: Not Found
IDEs:
Android Studio: 2022.1 AI-221.6008.13.2211.9477386
Xcode: 14.1/14B47b - /usr/bin/xcodebuild
Languages:
Java: 11.0.18 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.68.6 => 0.68.6
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

@Tom-Bury Tom-Bury added the bug Something isn't working label Jul 28, 2023
@atlj atlj self-assigned this Jul 28, 2023
@atlj
Copy link
Collaborator

atlj commented Jul 28, 2023

Were you also able to verify whether iOS works properly?

@Tom-Bury
Copy link
Author

Haven't tested iOS yet

@Tom-Bury
Copy link
Author

Tom-Bury commented Jul 28, 2023

The code generating the PackageList.java is https://github.com/react-native-community/cli/blob/90edee94442c8ca5aac52a74e7bafbf7df32b434/packages/cli-platform-android/native_modules.gradle

When looking at the two app's lockfiles, there's big version changes for @react-native-comunnity/cli-platform-android (using yarn list --pattern @react-native-community/cli-platform-android):

In the old 0.68.6 RN app:

yarn list v1.22.19
├─ @react-native-community/cli-hermes@6.3.1
│  └─ @react-native-community/cli-platform-android@6.3.1
└─ @react-native-community/cli-platform-android@7.0.1

In the newest RN app:

yarn list v1.22.19
└─ @react-native-community/cli-platform-android@11.3.5

@Tom-Bury
Copy link
Author

Don't have much time left, so will pick up back on Monday. For now it seemed like the missing package name from the libraries AndroidManifest seemed to cause the issue. Adding that back resolved it.

@atlj
Copy link
Collaborator

atlj commented Jul 28, 2023

This might be tied to the Android Gradle Plugin version. The whole story:

  1. feat(android): gradle namespace support for AGP versions >7.3 #399
  2. fix: don't use deprecated package field in AndroidManifest on AGP >= 7.3 #420

So basically with Android Gradle Plugin Version 8 (Which is going to be used with RN 0.73+), the package name from the manifest is deprecated. You use the namespace on build.gradle files instead. It seems like our efforts to support this change might have broken the backward compatibility though.

And here is the original issue: react-native-community/discussions-and-proposals#671

Thank you for detecting it. We'll see what can be done.

@HancleLee
Copy link

This might be tied to the Android Gradle Plugin version. The whole story:

  1. feat(android): gradle namespace support for AGP versions >7.3 #399
  2. fix: don't use deprecated package field in AndroidManifest on AGP >= 7.3 #420

So basically with Android Gradle Plugin Version 8 (Which is going to be used with RN 0.73+), the package name from the manifest is deprecated. You use the namespace on build.gradle files instead. It seems like our efforts to support this change might have broken the backward compatibility though.

And here is the original issue: react-native-community/discussions-and-proposals#671

Thank you for detecting it. We'll see what can be done.

add the package definition to the AndroidManifest.xml of my Native UI library -- works for me.

@atlj
Copy link
Collaborator

atlj commented Jul 31, 2023

@HancleLee Yes but now the issue is, it will raise a warning for library consumers that use newer versions of React Native while building on Android. While this might be a temporary solution, a better solution might be needed for create-react-native-library.

satya164 added a commit that referenced this issue Aug 1, 2023
The React Native CLI relies on the filename `AndroidManifest.xml` to be able parse the package name.
But we were using `AndroidManifestLegacy.xml` instead which broke the lib for older RN versions (AGP 7).
This change makes it so that we use `AndroidManifest.xml` for older RN versions and `AndroidManifestNew.xml` for newer RN
versions.

Fixes #429
satya164 added a commit that referenced this issue Aug 1, 2023
### Summary

The React Native CLI relies on the filename `AndroidManifest.xml` to be
able parse the package name. But we were using
`AndroidManifestLegacy.xml` instead which broke the lib for older RN
versions (AGP 7). This change makes it so that we use
`AndroidManifest.xml` for older RN versions and `AndroidManifestNew.xml`
for newer RN versions.

Fixes #429

### Test plan

- Create an app with RN 0.68 and install the library without these
changes - see that `yarn android` fails
- Create an app with RN 0.68 and install the library with these changes
- see that `yarn android` succeeds
- Create an app with latest RN and install the library with these
changes - see that `yarn android` succeeds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants