I'm integration React Native with an existing android project. When I run the project(react-native-cli run-android --no-packager), there is an error: Activity class MainActivity does not exist. However, my android project should start with an activity named HomeActivity instead of MainActivity. Sorry for my bad English. The error for a rookie is very difficult. Thank you!
(write your answer here)
Yes
(Write your answer here.)
Yes
Environment:
OS: macOS High Sierra 10.13.3
Node: 9.3.0
Yarn: 1.3.2
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: 3.0 AI-171.4443003
Packages: (wanted => installed)
react: 16.0.0 => 16.0.0
react-native: 0.51.0 => 0.51.0
(Write your steps here:)
1.init a react native project with react-native init yourprojectname
2.run npm install
3.go to folder /yourprojectname/android/app/src/main/java/com/yourprojectname/
4.rename MainActivity.java to HomeActivity.java
5.open HomeActivity.java, change class name from MainActivity to HomeActivity
6.go to folder /yourprojectname/android/app/src/main
7.open AndroidManifest.xml, change activity from MainActivity to HomeActivity
8.run react-native run-android
(Write what you thought would happen.)
app install to android device
(Write what happened. Add screenshots!)
an error will jump out
error: Activity class MainActivity does not exist.

(Paste the link to an example project and exact instructions to reproduce the issue.)
https://drive.google.com/file/d/1L1mMgb-IV185v52HznFNqLINwvlGIPsf/view?usp=sharing
it's a zip file, please extract it.
From your zip file, I don't know why your applicationId is com.test, but your package name is com.testwithoutmainactivity, if you did this. Also you changed the default activity entry for react-native-cli to search, so if you want to start the app, you can't use the default command line, you need run this react-native run-android --appId com.test --main-activity HomeActivity. You'd better use same setting cuz there is no difference between customize and default, or you need to have some android native knowledge.
Thank you very much!! That solve my problem.@dogbutcat
ApplicationId is consistent with the package name, or delete it.
android/app/build.gradle
defaultConfig {
applicationId "xxx"
}
I also meet the question,but my applicationId is right.
Solve a problem by changing a mobile phone。
this is why ? who can tell me .
@dccmmtop I met the exact same error in flutter (NOT react native). Some devices have this error and some don't. I found this issue by google. I think it's something to do with gradle. That's why different frameworks have the same error. The reason why? no idea yet.
@wukakuki if you use emulator, try Cold boot
For my case I was running react-native run-android and it would fail IF a valid emulator or device was not found. The reason for the failure is because the install function fails. So even if the build is successful, which it was in my case, the result will be "BUILD FAILURE" which is misleading since the build itself was successful.
I am back , I resolve the problem ,hahaha.
adb uninstall "package name"
Most helpful comment
I am back , I resolve the problem ,hahaha.
adb uninstall "package name"