React-native: [Android] react-native run-android: Parsing of AndroidManifest.xml wrong

Created on 26 Jan 2016  路  13Comments  路  Source: facebook/react-native

I saw that for the command react-native run-android you guys are getting the package name of the application out of app/src/main/AndroidManifest.xml. This is ok if you change the application package in the gradle file AND in the AndroidManifest.xml.

A better way would be to look at the final generated AndroidManifest.xml in the build directory to find the actual application id to start up the application.

Good first issue Locked

Most helpful comment

I changed the Application ID and not the package name. the result is I can compile and launch the app for android via Android Studio.. but running from the command line results in

Error type 3
Error: Activity class {com.foo/com.foo.MainActivity} does not exist.

All 13 comments

Hey fkrauthan, thanks for reporting this issue!

React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.

  • If you don't know how to do something or something is not working as you expect but not sure it's a bug, please ask on StackOverflow with the tag react-native or for more real time interactions, ask on Discord in the #react-native channel.
  • If this is a feature request or a bug that you would like to be fixed, please report it on Product Pains. It has a ranking feature that lets us focus on the most important issues the community is experiencing.
  • We welcome clear issues and PRs that are ready for in-depth discussion. Please provide screenshots where appropriate and always mention the version of React Native you're using. Thank you for your contributions!

A PR is welcome to improve the process.

I changed the Application ID and not the package name. the result is I can compile and launch the app for android via Android Studio.. but running from the command line results in

Error type 3
Error: Activity class {com.foo/com.foo.MainActivity} does not exist.

To respect applicationId in android/app/build.gradle then try to start activity by {applicationId}/{originalPackage}.MainActivity
Keeping MainActivity in original path is good for future migration.

--- a/local-cli/runAndroid/runAndroid.js
+++ b/local-cli/runAndroid/runAndroid.js
@@ -149,6 +149,11 @@ function run(args, reject) {
   }

   try {
+    const applicationId = fs.readFileSync(
+      'app/build.gradle',
+      'utf8'
+    ).match(/applicationId "(.+?)"/)[1];
+
     const packageName = fs.readFileSync(
       'app/src/main/AndroidManifest.xml',
       'utf8'
@@ -161,7 +166,7 @@ function run(args, reject) {
     if (devices && devices.length > 0) {
       devices.forEach((device) => {

-        const adbArgs = ['-s', device, 'shell', 'am', 'start', '-n', packageName + '/.MainActivity'];
+        const adbArgs = ['-s', device, 'shell', 'am', 'start', '-n', applicationId + '/' + packageName + '.MainActivity'];

         console.log(chalk.bold(
           `Starting the app on ${device} (${adbPath} ${adbArgs.join(' ')})...`

I have pushed a PR #8950 to solve this issue. I am using the advice given by @fkrauthan and am reading the package name from the final generated AndroidManifest.xml in the build directory. The real difficulty in the task is to figure out the path for the the generated manifest file as it depends upon the build type, product flavor as well the architecture that the build is run for.

Hi there! This issue is being closed because it has been inactive for a while.

But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/android-react-native-run-android-parsing-of-androidmanifestxml-wrong

Product Pains has been very useful in highlighting the top bugs and feature requests:
https://productpains.com/product/react-native?tab=top

Also, if this issue is a bug, please consider sending a pull request with a fix.

Ammm... Isn't it in react-native cli?

No looks like this issue is still valid. I can't believe that no one accepted the PR that someone already made.

This thing is still alive? Im experiencing problems with this now, aswell are others: http://stackoverflow.com/questions/41771892/react-native-app-wont-start-when-using-applicationidsuffix

Also the productpain page is not working anymore: "Oops! We couldn't find the page you were looking for."

Still having the same issue the app builds and installs but can't be opened on the emulator when running react-native run-android

Error type 3
Error: Activity class {packageName/packageName.MainActivity} does not exist.

I have a buildType for debug that adds the applicationIdSuffix '.dev' and I'm guessing this is why it can't find the activity to open but I'm not sure how to solve it. I definitely need the two build types

yep. issue still occurs, and it is annoying.

There are a ton of additional parameters you can pass in to resolve your issue.

For example:

react-native run-android --appIdSuffix dev --main-activity MainActivity --appFolder tvApp

See here: https://github.com/facebook/react-native/blob/master/local-cli/runAndroid/runAndroid.js#L301

Was this page helpful?
0 / 5 - 0 ratings