1

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>
Yogesh Devgun
  • 1,297
  • 1
  • 19
  • 36
  • You confused `Activity` with `Application` class. What activity your manifest contains? – Vadim Goroshevsky Jul 27 '20 at 14:23
  • @VadimGoroshevsky Maybe I am not native developer and Manifest file contains multiple activties. Our Android project doesn't contain any MainActivity.java. So can you please suggest where I can find equivalent to that in code? I thought application name `.core.exampleApplication` might be the first activity. – Yogesh Devgun Jul 27 '20 at 14:27
  • Did you take `package name/applicationId is com.comp.android` from `AndroidManifest` or from `build.gradle`? – Vadim Goroshevsky Jul 27 '20 at 15:28
  • I took from apps build.gradle, AndroidManifest mentions just this with applicationId: `android:authorities="${applicationId}.provider"` – Yogesh Devgun Jul 27 '20 at 15:32
  • `AndroidManifest` has root tag `` with attribute `package`. Is it the same as `applicationId`? – Vadim Goroshevsky Jul 27 '20 at 15:53
  • `android/app/build.gradle`, `android/app/src/main/java/com/app/MainActivity.java`, `android/app/src/main/java/com/app/MainApplication.java`, `android>app>src>main>AndroidManifest.xml package/applicationId` was not same in these 4, I updated and now it works fine. – Yogesh Devgun Jul 29 '20 at 10:15
  • It worked now it doesn't not sure what's an issue, @VadimGoroshevsky https://stackoverflow.com/questions/63174957/activity-class-rcm-samapp-com-comp-android-ui-does-not-exist – Yogesh Devgun Jul 30 '20 at 15:53

2 Answers2

2

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

Vadim Goroshevsky
  • 1,486
  • 10
  • 19
  • Yes there is Launcher intent filter, I was confusing it with class. Activity name is SplashActivity and its first line mentions `com.comp.android.ui` so I used `yarn react-native run-android --main-activity com.comp.android.ui.SplashActivity`. But now it gives an error: ```Starting: Intent { cmp=com.comp.android/.com.comp.android.ui.SplashActivity } Error type 3 Error: Activity class {com.comp.android/com.comp.android.com.comp.android.ui.SplashActivity} does not exist.``` – Yogesh Devgun Jul 27 '20 at 15:06
  • Please take a look at edited post. Sorry, now I read `react-native-cli` code and you don't need full package name here – Vadim Goroshevsky Jul 27 '20 at 15:20
  • I tried from root and android folder both: `yarn react-native run-android --main-activity ui.SplashActivity` Error: Activity class {com.comp.android/com.comp.android.ui.SplashActivity} does not exist. – Yogesh Devgun Jul 27 '20 at 15:23
  • I have added full intent filter if it helps. – Yogesh Devgun Jul 27 '20 at 15:26
  • Alot of searching! This is the one that worked, thank you! – Uch Jun 15 '23 at 15:51
0

This works:

yarn react-native run-android --main-activity .ui.SplashActivity

Must add a 'dot'

Dheeraj Avvari
  • 304
  • 2
  • 13