英文:
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:
<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
得分: 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 <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
答案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'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论