EAS Build (android bare) fails "You need to have MainApplication in your project"

EDIT!! - > I’ve found the source to this issue, so if mods want to archive this/would like me to remove it, feel free. Leaving it here incase anyone wants a quick laugh at my pain :joy:

Hey everyone!

In the process of getting set up with EAS. I’ve got my iOS app building successfully, but I’m running into an issue while building Android:

[stderr] A problem occurred evaluating project ':app'.
[stderr] > You need to have MainApplication in your project

I’ve seen this issue before, but only locally (which I fixed a month or so ago). Most of what you’ll find when googling is either that people actually DON’T have a MainApllication.java file (was my issue before lol), or they have multiple. Neither of these are the case for me locally. Running a quick `find . -name “MainApplication*” shows that my MainApplication.java is the only one.

This error is stemming from the build.groovy file inside of react-native-unimodules. The actual piece that breaks is:

def findMainJavaApp = new FileNameFinder().getFileNames(rootProject.getProjectDir().getPath(), '**/MainApplication.java', '')
  def findMainKtApp = new FileNameFinder().getFileNames(rootProject.getProjectDir().getPath(), '**/MainApplication.kt', '')
  if (findMainJavaApp.size() != 1 && findMainKtApp.size() != 1) {
    throw new GradleException("You need to have MainApplication in your project")

So my suspicion is that either somehow, inside of the eas build, its generating an extra MainApplication.java, OR rootProject.getProjectDir().getPath() isnt giving the correct path in the build environment. Because I’m not building this locally, I’m unable to really debug this any further…

Some other potentially useful notes:

  • Able to run gradlew commands locally, i.e. gradlew clean, without issue locally
  • App builds locally on an emulator without issue
  • Have been able to create a production build with my own keystore etc successfully locally, but am now letting expo handle my credentials
  • I’m on SDK ~40.0.0
  • I’ve updated my eas-cli to latest
  • My eas.json file currently has the default configuration
  • Im using the bare workflow, previously manage, ejected a month or two ago

Anyone have any ideas here?? Think I’ve just about run out of things to try haha. Any help is appreciated!!

Ah okay, so interesting update, I just cloned what was actually uploaded to expo using the directions found in this post: /Users/expo/project/build/package.json is missing - #2 by notbrent

It looks like there is no “java/…” . inside of android/app/src/main, all that exists is the AndroidManifest.xml file and the “res” directory.

As goes for the questions asked in the linked thread, this is NOT a monorepo, and im not using yarn workspaces.

One thing however from a project structure standpoint which may be useful is that my package name uses a .build domain.By that I mean, our website is www.skillspace.build, thus out package name is “build.skillspace.mobile”.

Whenever I originally ejected, it DID NOT create a android/app/src/main/java/build/skillspace/mobile directory as it should have. I had to manually create this directory. I was thinking that it may have something to do with the fact that my package name had “build” in it, and wasnt just “com.skillspace”, but hadnt needed to dig in any further after I just created this directory and files myself.I suspect whatever was the issue then, may well be the issue here.

Also not sure if this helps, but my app (i.e. expo.name in app.json) is simply “MobileApp”, and there are things in my project, specifically rootProject.name inside of settings.gradle and android:value= for the “expo.modules.updates.EXPO_UPDATE_URL” meta-data tag in AndroidManifest , which are set to “MobileApp”/“@skillspace/MobileApp”

Hah…HAHA…ha… Well… My suspicions around the “.build” domain issue were correct. Feel free to archive this question if you’d like, since i’ve found the culprit, but I’ll give a quick outline incase anyone wants a quick laugh.

Did NOT thinking about the fact that, of COURSE, build/ directories are included in the gitignore files. This piece of my application locally were never being pushed up into source control in the first place. Guess I didn’t think about it as I wasn’t thinking about the fact that EAS, of course, must clone the project from somewhere…

If this isn’t a niche problem, not sure what is. Suppose it’s what I get for using an obscure TLD :laughing: Anyhow, hope someone can get some joy from my pain :+1:

thanks for the follow up! that’s a funny quirk :slight_smile: glad you were able to resolve it

1 Like