Getting Error "Your project must have an Android package set in app.json" despite that fact that I have an android package set in app.json

Viewed 9426

I'm building a react native project using expo. I'm on windows, so I enable WSL and install ubuntu from the microsoft store. Next I run expo build:android. I get the following error,

Your project must have an Android package set in app.json.

So I looked at expos tutorial page and it says to add,

"android": {
    "package": "com.yourcompany.yourappname"
}

I add that to the app.json file and I get the same error. I don't have the slightest idea as to why the error wont go away, because I've looked at the tutorial page and at my code, and I clearly have all the required fields.

This is the tutorial page I've been looking at : https://docs.expo.io/versions/latest/distribution/building-standalone-apps/

Anyways, this is my app.json file,

{
  "expo": {
    "name": "First React App",
    "slug": "FirstReactNativeApp",
    "privacy": "public",
    "sdkVersion": "35.0.0",
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "ios": {
      "bundleIdentifier": "com.yourcompany.yourappname",
      "supportsTablet": true,
    },
    "android": {
      "package": "com.yourcompany.yourappname",
    },
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
  }
}
6 Answers

For anyone coming to this page, add the following to your app.json.

"android": {
  "package": "com.yourcompany.yourappname",
  "versionCode": 1
}

I just arrived here after experiencing the same problem. Turns out my app.config.js wasn't passing on configuration from app.json.

I fixed it by changing:

export default {
  extra: {
    [...]
  },
};

to:

export default ({config}) => {
  return Object.assign(config,
    {
      extra: {
        [...]
      }
    });
};

This Worked for me, you can try this

{
  "expo": {
    "name": "kd-guess-number",
    "slug": "kd-guess-number",
    "sdkVersion": "37.0.0",
    "privacy": "public",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "supportsTablet": true
    },
    "description": "",

    "android": {
      "package": "com.yourcompany.yourappname",
      "versionCode": 1
    }

  }
}

You should add this at the end (See above my code for reference)

"android": {
      "package": "com.yourcompany.yourappname",
      "versionCode": 1
    }

I know I might be late for the this, but I found the issue at least for myself was because the Expo create-react-native-app might build the app.json different from what it actually wanted (I might be wrong). I created a new expo app and compare the two. I found that the structure of the json changed and android should be nested inside expo like the following. BTW, this is my first answer in stackoverflow.

Correct:

{
 "expo": {
   "name": "youappname",
   "android": {
     "package": "com.web.app",
     "versionCode": 1
   }
 }
}

In my case I had declared the "android" property at the top level within app.json. Rather, it should've been listed within the "expo" property as a sub-key. Duh!

//you have to update it in /android/app/build.gradle

Related