run-android 连接到设备时出错 [英] run-android gives error when connected to a device

查看:80
本文介绍了run-android 连接到设备时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了启动画面,https://medium.com/handlebar-labs/how-to-add-a-splash-screen-to-a-react-native-app-ios-and-android-30a3cec835ae,到 AwesomeProject 示例到入门 (https://facebook.github.io/react-native/docs/入门.html).

I added a splash screen,https://medium.com/handlebar-labs/how-to-add-a-splash-screen-to-a-react-native-app-ios-and-android-30a3cec835ae, to the AwesomeProject example to Getting Started ( https://facebook.github.io/react-native/docs/getting-started.html).

我连接了我的 nexus 6p 并运行了 react-native run-android 并且我收到了这个错误

I connected my nexus 6p and ran react-native run-android and I am getting this error

This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html
Running /home/Android/Sdk/platform-tools/adb -s 84B7N15A10013562 reverse tcp:8081 tcp:8081
Starting the app on 84B7N15A10013562 (/home/Android/Sdk/platform-tools/adb -s 84B7N15A10013562 shell am start -n com.testprj1/.MainActivity)...
Starting: Intent { cmp=com.testprj1/.MainActivity }
java.lang.SecurityException: Permission Denial: starting Intent { flg=0x10000000 cmp=com.testprj1/.MainActivity } from null (pid=23823, uid=2000) not exported from uid 10161
        at android.os.Parcel.readException(Parcel.java:1684)
        at android.os.Parcel.readException(Parcel.java:1637)
        at android.app.ActivityManagerProxy.startActivityAsUser(ActivityManagerNative.java:3137)
        at com.android.commands.am.Am.runStart(Am.java:643)
        at com.android.commands.am.Am.onRun(Am.java:394)
        at com.android.internal.os.BaseCommand.run(BaseCommand.java:51)
        at com.android.commands.am.Am.main(Am.java:124)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:262)

但是,如果我在模拟器上运行相同,则没有错误

But, if i run same on an emulator there is no errors

推荐答案

根据您发布的教程,您的新启动器活动是 SplashActivity 而不是 MainActivity.但是默认情况下,react-native cli 会尝试启动 MainActivity,这会导致此权限错误.在这个路径读取runAndroid.js文件中的代码;your_project/node_modules/react-native/local-cli/runAndroid.js.还要检查您在启动应用程序时可以使用的这些命令.

According to the tutorial you posted, your new launcher activity is SplashActivity and not the MainActivity. But by default react-native cli tries to launch MainActivity which causes this permission error. Read the code in runAndroid.js file at this path; your_project/node_modules/react-native/local-cli/runAndroid.js. Also check these commands which you can use while launching the app.

module.exports = {
  name: 'run-android',
  description: 'builds your app and starts it on a connected Android 
  emulator or device',
  func: runAndroid,
  options: [{
       command: '--install-debug',
    },
    {
      command: '--root [string]',
      description: 'Override the root directory for the android build (which contains the android directory)',
      default: '',
    },
    {
      command: '--flavor [string]',
      description: '--flavor has been deprecated. Use --variant instead',
    },
    {
      command: '--variant [string]',
    },
    {
      command: '--main-activity [string]',
      description: 'Name of the activity to start',
      default: 'MainActivity',
    },
    {
      command: '--deviceId [string]',
      description: 'builds your app and starts it on a specific device/simulator with the given device id (listed by running "adb devices" on the command line).',
    },
    {
      command: '--no-packager',
      description: 'Do not launch packager while building',
  }],
};

它也不应该在模拟器上工作.尝试从模拟器卸载应用程序并再次运行,它不会工作.

It should not have worked on emulator as well. Try uninstalling the app from emulator and run again, it will not work.

现在要解决这个问题,请在终端中运行以下命令

Now to solve the issue run the following command in terminal

react-native run-android --main-activity SplashActivity

请注意,我们在最后使用--main-activity"命令添加要启动的活动名称

Notice that we are adding activity name to launch in the end using "--main-activity" command

这篇关于run-android 连接到设备时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆