2017-05-26 53 views
0

我在AwesomeProject入門示例( https://facebook.github.io/react-native/docs/getting-started.html)中添加了啓動畫面https://medium.com/handlebar-labs/how-to-add-a-splash-screen-to-a-react-native-app-ios-and-android-30a3cec835aerun-android在連接到設備時給出錯誤

我連我的Nexus 6P就跑反應原生運行Android和我收到此錯誤

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) 

但是,如果我運行模擬器上進行同樣的沒有錯誤

+0

也許有年底推出是你的模擬器中的一些緩存,Android平臺總是做到這一點 –

+0

@shresthaal,檢查我的答案,讓我知道它是否適用於你 –

回答

2

按照您發佈的教程,您的新啓動器活動是SplashActivity而不是MainActivity。但默認情況下,react-native cli會嘗試啓動導致此權限錯誤的MainActivity。在此路徑中閱讀runAndroid.js文件中的代碼; your_project/node_modules /反應本地/本地CLI/runAndroid.js。還請檢查這些命令,您可以在啓動應用程序時使用這些命令。

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', 
    }], 
}; 

它不應該在模擬器上工作。嘗試從模擬器卸載應用程序並再次運行,它將無法工作。

我們解決這一問題在運行終端

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

注意下面的命令,我們將活動名稱使用「- 主活動」命令

相關問題