在集成React本机和Android应用程序时更改MainActivity条目 [英] Changing MainActivity entry while integrating React native and android application

查看:59
本文介绍了在集成React本机和Android应用程序时更改MainActivity条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究POC,以将本机Android应用程序与React Native集成在一起.在按照本机官方文档进行集成的所有步骤之后,我遇到了一个错误MainActivity.java不存在.不确定,但是我猜想它的cosreact-native run-android是通过MainActivity.java运行的.但是在本机android应用中,我们没有任何此类活动文件.从AndroidManifest.xml来看,这是第一个活动:

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"

因此要定制此活动文件,我遇到了cli选项:

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

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

但是会引发此错误:

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.

程序包名称/applicationId为 com.comp.android

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>

推荐答案

您应该查看 AndroidManifest.xml 并搜索包含此代码的< activity> 标记:

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>

确定活动后,运行命令 yarn react-native run-android --main-activity com.comp.android.core.YOUR_ACTIVITY .请注意完整的程序包名称,您的活动可能不属于 .core 程序包.

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.

使用命令 yarn react-native run-android --main-activity ui.SplashActivity .抱歉,现在我阅读了 react-native-cli 代码,您无需在此处输入完整的软件包名称

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

这篇关于在集成React本机和Android应用程序时更改MainActivity条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆