Changing MainActivity entry while integrating React native and android application

huangapple go评论90阅读模式
英文:

Changing MainActivity entry while integrating React native and android application

问题

我正在进行将原生 Android 应用与 React Native 集成的 POC 工作。在按照 React Native 官方文档中关于集成的所有步骤后,我遇到了一个错误:MainActivity.java 不存在。不太确定,但我猜可能是因为 react-native run-android 命令是通过 MainActivity.java 来工作的。然而,在原生 Android 应用中并没有这样的活动文件。根据 AndroidManifest.xml 文件,这似乎是第一个活动:

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

所以为了自定义这个活动文件,我找到了一个命令行选项:

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.

包名/应用ID 是 com.comp.android

有人知道如何解决这个问题吗?或者你们有什么经验可以分享吗?

编辑后的 Intent 过滤器如下:

<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>
英文:

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:

&lt;application
    android:name=&quot;.core.exampleApplication&quot;

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:

&lt;activity
        android:name=&quot;.ui.SplashActivity&quot;
        android:screenOrientation=&quot;portrait&quot;&gt;
        &lt;intent-filter&gt;
            &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
            &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
            &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
        &lt;/intent-filter&gt;

        &lt;meta-data android:name=&quot;android.app.shortcuts&quot;
                   android:resource=&quot;@xml/shortcuts&quot; /&gt; --&gt;
&lt;/activity&gt;

答案1

得分: 2

你应该查看AndroidManifest.xml文件,并搜索包含以下代码的<activity>标签:

<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包的一部分。

编辑:
使用命令yarn react-native run-android --main-activity ui.SplashActivity。抱歉,我现在阅读了react-native-cli的代码,你在这里不需要完整的包名。

英文:

You should look into AndroidManifest.xml and search for &lt;activity&gt; tag which contains this code:

&lt;intent-filter&gt;
    &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
    &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
&lt;/intent-filter&gt;

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

答案2

得分: 0

这个有效:

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

必须添加一个 '点'

英文:

This works:

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

Must add a 'dot'

huangapple
  • 本文由 发表于 2020年7月27日 22:14:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/63117217.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定