Tomas
Tomas

Reputation: 129

React Native Expo create apk

I have created some apps with React Native using Expo but this is my first time trying to build the app to update it to Play Store and App Store, first of all, I would like to make an apk to try with my devices on android which I think will be easier than iOS.

This is my package.json

{
  "name": "todolist",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web",
    "eject": "expo eject"
   },
  "dependencies": {
    "@react-native-async-storage/async-storage": "1.18.2",
    "expo": "^49.0.0",
    "expo-status-bar": "~1.6.0",
    "expo-updates": "~0.18.19",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-native": "0.72.6",
    "react-native-web": "~0.19.6",
    "expo-splash-screen": "~0.20.5"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "expo-cli": "^6.3.10"
  },
  "private": true
}

I have watched a lot of videos, read tons of webs and tutorials, but I CAN NOT create an apk, I tryed this command: npx react-native bundle --platform android --dev false --entry-file App.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res And it works, but when I try ./gradlew assembleDebug it doesn't, giving to me all of this. (I know pictures of code is not a good idea, but this is too big)

enter image description here

I created an eas.json file with the next code:

{
"build": {
    "preview": {
        "android": {
            "buildType": "apk"
        }
    },
    "preview2": {
        "android": {
            "gradleCommand": ":app:assembleRelease"
        }
    },
    "preview3": {
        "developmentClient": true
    },
    "production": {}
}
}

I logged in to my expo account and when I run the next code: eas build -p android --profile preview it gives me the next error: āœ– Build failed šŸ¤– Android build failed: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.

If I'm honest, I do not know what to do next, I am completely block, could anyone please help?

PD: If you need to see more code, just let me know what file do you need.

Upvotes: 2

Views: 2678

Answers (3)

Rimon
Rimon

Reputation: 1

$ npx create-expo-app test -t expo-template-blank-typescript

Upvotes: 0

Younes Ammari
Younes Ammari

Reputation: 31

use npx expo prebuild to generate android folder go inside that folder and run:

  • ./gradlew assembleRelease: to create .apk.
  • ./gradlew bundleRelease: to create .aab.

Upvotes: 3

Gabriel Barth
Gabriel Barth

Reputation: 311

According what you are telling us, you have an bare workflow expo project. In this case, I would suggest you two ways to get this done.

The first one is generating the Android App Bundle file (.aab). This is the Android publishing format compatible with Google Play. Run this command for this:

npx react-native build-android --mode=release

The output will be placed in android folder: /android/app/build/outputs/bundle/release/app-release.aab

The another one is generating the APK. So you can run these commands for this:

./gradlew clean //just for cleaning build folder

./gradlew assembleRelease //for generating the apk

The output will be placed in android folder: android/app/build/outputs/apk/release/app-release.apk

Upvotes: 2

Related Questions