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] react-native run-android: Parsing of AndroidManifest.xml wrong #5546

Closed
fkrauthan opened this issue Jan 26, 2016 · 13 comments
Closed
Labels
Good first issue Interested in collaborating? Take a stab at fixing one of these issues. Resolution: Locked This issue was locked by the bot.

Comments

@fkrauthan
Copy link

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.

@facebook-github-bot
Copy link
Contributor

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!

@satya164
Copy link
Contributor

A PR is welcome to improve the process.

@jayesbe
Copy link

jayesbe commented Mar 6, 2016

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.

@grabbou grabbou added the Good first issue Interested in collaborating? Take a stab at fixing one of these issues. label Apr 20, 2016
@ElvisChiang
Copy link

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(' ')})...`

@kgritesh
Copy link

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.

@mkonicek
Copy link
Contributor

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.

@alexustinovsm
Copy link

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

@fkrauthan
Copy link
Author

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

@vongohren
Copy link

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

@southerneer
Copy link

southerneer commented Mar 9, 2017

New product pains link: https://react-native.canny.io/feature-requests/p/android-support-varying-application-ids-for-different-build-variantsflavors

...and it seems like old links redirect correctly now.

@Nandez89
Copy link

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

@ovy9086
Copy link

ovy9086 commented Apr 7, 2018

yep. issue still occurs, and it is annoying.

@AndrewJack
Copy link
Contributor

AndrewJack commented Apr 8, 2018

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

@facebook facebook locked as resolved and limited conversation to collaborators Jul 20, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Good first issue Interested in collaborating? Take a stab at fixing one of these issues. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests