英文:
Converting Expo Classic's Release Channel to EAS
问题
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 samegetEnvConst
function above and replacedreleaseChannel
withchannel
. Thechannel
doesn't seem to be working. I use the following command for publishingeas build -p android --profile staging
Theeas.json
contains 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
env
ineas.json
. But thisexport const apiUrl = process.env.API_URL
doesn't seem to get the values vianpm start
. Haven't tested it ineas build
because 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.
英文:
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 samegetEnvConst
function above and replacedreleaseChannel
withchannel
. Thechannel
doesn't seem to be working. I use the following command for publishingeas build -p android --profile staging
Theeas.json
contains 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
env
ineas.json
. But thisexport const apiUrl = process.env.API_URL
doesn't seem to get the values vianpm start
. Haven't tested it ineas build
because 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.
答案1
得分: 0
以下是翻译好的部分:
- "This SO answer was the one that solved my problem.":这个 SO 答案解决了我的问题。
- "It said that I need to add a
branch
first then link mychannel
to it using this command:":它说我需要先添加一个branch
,然后使用以下命令将我的channel
链接到它: - "What tripped me before was whenever I run
eas build -p android --profile staging
it doesn't say any warning or error and just completes successfully.":之前让我困惑的是,每当我运行eas build -p android --profile staging
时,它既不显示警告也不显示错误,只是顺利完成。 - "This gives me a false idea that my profile's
channel
should take effect.":这让我错误地认为我的配置文件的channel
应该生效。 - "After creating the
branch
and linking my channel to it, theUpdates.channel
now contains the channel in theeas.json
.":创建了branch
并将我的channel
链接到它后,eas.json
中的Updates.channel
现在包含了该渠道。 - "However, whenever I run
eas update --channel staging --platform android
, theUpdates.channel
is still null.":然而,每当我运行eas update --channel staging --platform android
时,Updates.channel
仍然为空。 - "It seems there's not a direct replacement to
expo publish
andreleaseChannel
the way it used before.":看来没有直接替代expo publish
和之前使用的releaseChannel
的方式。 - "My
eas.json
is still similar from before:":我的eas.json
仍然与以前相似。
希望这些翻译对您有所帮助。
英文:
I was able to proceed with that I wanted to happen.
This SO answer was the one that solved my problem. It said that I need to add a branch
first then link my channel
to it using this command:
eas update --branch staging
eas channel:edit staging --branch staging
What tripped me before was whenever I run eas build -p android --profile staging
it doesn't say any warning or error and just completes successfully. This gives me a false idea that my profile's channel
should take effect. After creating the branch
and linking my channel to it, the Updates.channel
now contains the channel in the eas.json
.
However, whenever I run eas update --channel staging --platform android
, the Updates.channel
is still null. I just ended up commenting/uncommenting the return of the else
when I do eas update
which works for now.
It seems there's not a direct replacement to expo publish
and releaseChannel
the way it used before.
My eas.json
is still similar from before:
{
"cli": {
"version": ">= 3.8.1"
},
"build": {
"development": {
"developmentClient": true,
"distribution": "internal",
"ios": {
"resourceClass": "m-medium"
},
"channel": "dev"
},
"staging": {
"distribution": "internal",
"ios": {
"resourceClass": "m-medium"
},
"channel": "staging"
},
"uat": {
"distribution": "internal",
"ios": {
"resourceClass": "m-medium"
},
"channel": "uat"
},
"production": {
"ios": {
"resourceClass": "m-medium"
},
"channel": "production"
}
},
"submit": {
"production": {}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论