Changing MainActivity entry while integrating React native and android application

有些话、适合烂在心里 提交于 2020-08-10 12:57:57

问题


I am are working on POC to integrate native android app with React Native. After following all steps in react native official docs for integration, I had an error MainActivity.java does not exist. Not sure but I guess its cosreact-native run-android works through MainActivity.java. But in native android app we dun have any such activity file. From AndroidManifest.xml it looks this is the first activity:

<application
    android:name=".core.exampleApplication"

so to customize to this activity file, I came across cli option :

yarn react-native run-android --main-activity core.exampleApplication

but it throws this error:

Starting: Intent { cmp=com.comp.android/.core.exampleApplication }
Error type 3
Error: Activity class {com.comp.android/com.comp.android.core.exampleApplication} does not exist.

package name/applicationId is com.comp.android

anyone got an idea how to fix this? or any experience you guys want to share?

Edit intent filter looks like this:

<activity
        android:name=".ui.SplashActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

        <meta-data android:name="android.app.shortcuts"
                   android:resource="@xml/shortcuts" /> -->
</activity>

回答1:


You should look into AndroidManifest.xml and search for <activity> tag which contains this code:

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

After you identified your activity, run command yarn react-native run-android --main-activity com.comp.android.core.YOUR_ACTIVITY. Pay your attention to full package name, your activity may not be part of .core package.

EDIT: Use command yarn react-native run-android --main-activity ui.SplashActivity. Sorry, now I read react-native-cli code and you don't need full package name here



来源:https://stackoverflow.com/questions/63117217/changing-mainactivity-entry-while-integrating-react-native-and-android-applicati

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!