25

After updating expo it no longer supports building apk files using expo build:android -t apk and instead advices to using eas builds using the command eas build -p android --profile preview but it ended up building an aab instead of the apk. I took a look at the newly added eas.json file which contained:

{
  "cli": {
    "version": ">= 0.52.0"
  },
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal"
    },
    "preview": {
      "distribution": "internal"
    },
    "production": {}
  },
  "submit": {
    "production": {}
  }
}

I read the eas docs and it adviced on changing my eas.json to:

{
  "cli": {
    "version": ">= 0.52.0"
  },
  "build": {
    "preview": {
      "android": {
        "buildType": "apk"
      }
    },
    "preview2": {
      "android": {
        "gradleCommand": ":app:assembleRelease"
      }
    },
    "preview3": {
      "developmentClient": true
    },
    "production": {}
  }
} 

The after running the build command:eas build -p android --profile preview

It build the app correctly as an apk file and installs on android just fine, but on opening it closes itself instantly. After trying to reopen it again closes and now alerts the app crashed.

Is there an error in my eas.json file or am I miss something?

coolDog
  • 476
  • 1
  • 3
  • 11

4 Answers4

22

Change production key in eas.json to this

"production": {
    "android": {
       "buildType": "apk"
    }
}

So now your eas.json like this

{
  "cli": {
    "version": ">= 0.52.0"
  },
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal"
    },
    "preview": {
      "distribution": "internal"
    },
    "production": {
      "android": {
        "buildType": "apk"
      }
    }
  },
  "submit": {
    "production": {}
  }
}

To build into .apk file, you can build using production profile. The command like this eas build --profile production --platform android

MyFRA
  • 366
  • 2
  • 5
16

Here is the detailed instruction: https://docs.expo.dev/build/eas-json/

You need to create eas.json in the project directory as:

{
  "build": {
    "preview": {
      "android": {
        "buildType": "apk"
      }
    },
    "production": {}
  },
  "cli": {
    "version": ">= 0.52.0"
  }
}

Then use the following command:

eas build -p android --profile preview

Regards, Shameel

birgersp
  • 3,909
  • 8
  • 39
  • 79
Shameel Uddin
  • 511
  • 2
  • 10
  • 1
    I keep seeing this copied all over the place. None of you realised that preview/preview2/preview3 are three different configurations, yet you only use the first – birgersp Jul 28 '23 at 18:59
1

The solutions offered in the comments work. My error was brought about by the new SDK version that only supports @react-navigation/native if you have react-native-screens and react-native-safe-area-context installed.

For anyone who finds themselves here use:

npm install @react-navigation/native

expo install react-native-screens react-native-safe-area-context

And then edit eas.json as the other answers recommend. I hope it works for you

coolDog
  • 476
  • 1
  • 3
  • 11
0

I also encounter some problem when upgrading my app to EAS build, the reason is because i m using a value from expo-constant and it return a null, so it crashes my app. The new SDK moved the value that i need to expo-device.
My sentry also cause a problem, it will cause instant crash when the app opened. Try removing it temporarily and see if your app will open