问题
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