简体   繁体   中英

How do I resolve 'You need to have MainApplication in your project' in React native run-android

I ejected from expo, and trying react-native run-android, I'm getting this error;

FAILURE: Build failed with an exception.

* Where:
Script 'C:\Users\simil\OneDrive\Documents\Codes\react-native\expo\doc\node_modules\react-native-unimodules\gradle.groovy' line: 81

* What went wrong:
A problem occurred evaluating project ':app'.
> You need to have MainApplication in your project

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 14s

This is my MainActivity path

MyApp \\android\\app\\src\\main\\java\\com\\com.example.eg\\MainActivity.java

I faced this problem on my project too, reason was, I ejected from expo, reversed the eject and changed the bundleid . After that I ejected again.

This created 2 different MainApplication.java under app/src/main/java .

To fix it I removed the one with the old bundleid folder.

Also having trouble with this. I'm on Windows 10 and just ejected from expo sdk 37 . Its a problem of the react-native-unimodules package.

Seems like findMainJavaApp in line 77 of gradle.groovy doesn't find the full path of the MainApplication.java (or MainApplication.kt )

rootProject.getProjectDir().getPath() gets only to the android project dir… and not down to the app.src…com.XXX where your MainApplication is.

For a quick fix replace the rootProject.getProjectDir().getPath() in lines 77 and 78 with the absolute path of the parent directory of your projects MainApplication.java (or .kt) file.

I'll try to post an issue about this in unimodules Github ASAC.

It happened to me the same when I ejected the Expo project from ExpoKit to a BareFlow react-native project. If you check in your java src path, you will find 2 MainApplication.java, one version is your real MainApplication in your correct package, the other one helps ExpoKit to do its stuff.

During the ejection, for unknown reason, the ExpoKit package com.host.exp should be removed but it is not. I backed it up, or removed it, and then adjusted some eventual dependencies left in your package like the DEBUG variable.

The problem should go away

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM