Skip to content

Read main activity from manifest not correctly handling activities with "missing" intent nodes #2392

@cameroncharles

Description

@cameroncharles

Environment

Relevant part of react-native config
(name/path of app changed throughout as it doesnt really matter)

"android": {
"sourceDir": "C:.......\android",
"appName": "app",
"packageName": "com.example.myapp",
"applicationId": "com.example.myapp",
"mainActivity": "",
"unstable_reactLegacyComponentNames": []
}

Note the empty "mainActivity"

Description

This PR from late '23 added the ability for the "main" activity to be programatically pulled from the manifest using the intent declarations, rather then assuming it would be called mainActivity and requiring the user to override it with a param if they used something else.

In my project however the main acitivity pull attempt ends up as blank, this results in run-android failing with the following:

  • Error type 3, Error: Activity class {com.example.dev/com.example.myapp} does not exist.

Again note that it does not have .mainActivity, or any activity, at all, as one would expect

Running config in my project also ends up with an empty mainActivity entry in the android project info, see Enironment

I have tracked this down for my project to the fact that for various reasons i have activities declared in the manifest that have intent nodes that do not have action/category nodes within them, for example

        <activity
            ...other stuff
         >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
            </intent-filter>
        </activity>

When the getMainActivity function added in that PR attempts to process my manifest and the above activity in particular it 'extracts' null for the category entry of the intent (Line 55), puts that into an array (Line 66) and then attempts to read props of that (Line 77 i believe), this exception is caught and null is returned resulting in the situations above.

As far as i can tell from documentation its perfectly legitimate to have intents without actions or categories, indeed my app with those intents has been in production for years with no issue, and the getMainActivity code is already, tehcnically, null checking action and category as it can disclude any activities without both as they will never be the "main" activity.

However the null checking doesnt occur until after the "is this an array, if not make it one" step (line 60 and 66) , which in the case of missing action/category nodes puts null into an array, this array is not null-ish thus the null check lets it through.

I can confirm for my project adding a null check on action and category to line 56 allows the function to move past these activities and properly process my manifest and correctly find my MainActivity,

i unfortunately do not have the capicity to see a PR for this fix through thouroghly so thought best i raise this as an issue.

Reproducible Demo

Create a React-Native App with and android activity declaration that has intents but does not have either an action or category node as per my example above.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions