Sher Mi
Sher Mi

Reputation: 738

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

Upvotes: 9

Views: 42853

Answers (3)

MarckSi
MarckSi

Reputation: 41

For me, this error start after upgrade the sdkVersion from 31 to 33 and gradle version.

I did check the changes in git, and notice that the package attribute was removed from AndroidManifest.xml.

So I did add this attribute again.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.yourpackage">

Upvotes: 1

Patrick Lafferty
Patrick Lafferty

Reputation: 557

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">

Upvotes: 36

Sher Mi
Sher Mi

Reputation: 738

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>

Upvotes: 6

Related Questions