I have converted our old mobile app to the latest version of expo. Seeing that a lot of things had been deprecated including expo publish, I'm now integrating the eas build to my workflow
In my code before, I have been using Updates.releaseChannel before for my env specific config. See code below:
export function getEnvConst() {
if (Updates.releaseChannel.startsWith("prod")) {
return { apiUrl: "https://prodUrl.com/" };
} else if (Updates.releaseChannel.startsWith("staging")) {
return { apiUrl: "https://stagingUrl.com/" };
} else if (Updates.releaseChannel.startsWith("uat")) {
return { apiUrl: "https://uatUrl.com/" };
} else {
return { apiUrl: "https://devUrl.com/" };
}
}
and I get to select which channel via the following commands:
expo publish --release-channel prod
expo publish --release-channel uat
expo publish --release-channel staging
This setup allows me to switch ApiUrl base on releaseChannel and at the same time, during development (npm start) the else statement kicks in to run using dev url (since no release channel)
I can't seem to replicate this setup using eas build. What I've tried is to add eas.json and added a bunch of profile and bunch of env. These env doesn't seem to be accessible to the javascript code as well?
What I tried:
- Add profile and used
channel. Literally used the samegetEnvConstfunction above and replacedreleaseChannelwithchannel. Thechanneldoesn't seem to be working. I use the following command for publishingeas build -p android --profile stagingTheeas.jsoncontains the following:
{
"cli": {
"version": ">= 3.8.1"
},
"build": {
"development": {
"developmentClient": true,
"distribution": "internal",
"ios": {
"resourceClass": "m-medium"
},
"channel": "dev",
},
"staging": {
"android": {
"buildType": "apk"
},
"ios": {
"resourceClass": "m-medium"
},
"channel": "staging",
},
"uat": {
"distribution": "internal",
"ios": {
"resourceClass": "m-medium"
},
"channel": "uat",
},
"production": {
"ios": {
"resourceClass": "m-medium"
},
"channel": "production",
}
},
"submit": {
"production": {}
},
}
- Tried adding
envineas.json. But thisexport const apiUrl = process.env.API_URLdoesn't seem to get the values vianpm start. Haven't tested it ineas buildbecause it takes a lot of time to test...
{
"cli": {
"version": ">= 3.8.1"
},
//Remove other sections for brevity
"build": {
"development": {
"developmentClient": true,
"distribution": "internal",
"ios": {
"resourceClass": "m-medium"
},
"channel": "dev",
"env": {
"API_URL": "http://devUrl.com/"
}
},
"production": {
"ios": {
"resourceClass": "m-medium"
},
"channel": "production",
"env": {
"API_URL": "https://prodUrl.com/"
}
}
},
"submit": {
"production": {}
},
"development": {
"client": "local"
},
"env": {
"development": {
"API_URL": "https://devUrl.com/"
}
}
}
Honestly I'm just confused with all of this and it's taking me a lot of time than I want to admit, even after reading the documentation. It seems I'm missing the fundamentals of expo that the document assumes I'm aware of so what it says doesn't connect to me.