Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native: Error: Package name not found

After integrating RN into an existing Android project, I get the following error:

Error: Package name not found in /home/.../AndroidManifest.xml at Object.projectConfig (/home/.../rn_integrated_app/node_modules/@react-native-community/cli-platform-android/build/config/index.js:74:11) at Object.get project [as project]

As I understand the problem is that there is no package attribute in the relevant AndroidManifest.xml file. Since my project has many flavors, the package attribute is added dynamically, while compiling, through app/build.gradle:

def pkgDataEntry = getRightValue(packagesData, variantMap)
variant.getMergedFlavor().applicationId = pkgDataEntry.pkg 

So that the final merged manifest file does have the package attribute.

The error occurs here(@react-native-community/cli-platform-android/build/config/index.js):

  const packageName = userConfig.packageName || getPackageName(manifest);

  if (!packageName) {
    throw new Error(`Package name not found in ${manifestPath}`);
  }

Is there a way to make RN read the merged manifest file? If not, how can I modify userConfig to contain the package name? I couldn`t find anything about it in the docs.

Thank you

like image 228
Sharon Mishayev Avatar asked May 05 '26 15:05

Sharon Mishayev


2 Answers

For me, the solution was to add the "package" tag to the manifest tag. I didn't have to create another dummy folder.

The manifest open tag now looks like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.yourProjectName">
like image 133
Patrick Lafferty Avatar answered May 08 '26 06:05

Patrick Lafferty


If anybody encounters the same issue, when having multiple flavors and AndroidManifest.xml files,here`s my conclusion: RN has some kind of a bug that it requires the first folder alphabetically, in android/app/src, which has AndroidManifest.xml file,to have the package attribute. Otherwise, it will throw an error.

A simple solution would be to create a dummy folder, e.g aaa (first alphabetically) and to create AndroidManifest.xml inside of it, with the following attribute - package:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="aaa"
    xmlns:tools="http://schemas.android.com/tools">
    <uses-permission
        android:name="android.permission.GET_ACCOUNTS"
        tools:node="remove"/>
</manifest>
like image 27
Sharon Mishayev Avatar answered May 08 '26 06:05

Sharon Mishayev