Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EAS Build: Can't use dynamic app name #2273

Open
serhii-lyshchenko opened this issue Mar 11, 2024 · 5 comments
Open

EAS Build: Can't use dynamic app name #2273

serhii-lyshchenko opened this issue Mar 11, 2024 · 5 comments
Labels
eas build needs review Issue is ready to be reviewed by a maintainer

Comments

@serhii-lyshchenko
Copy link

serhii-lyshchenko commented Mar 11, 2024

Build/Submit details page URL

https://expo.dev/accounts/dynamic-name-test/projects/dynamic-name-test/builds/541c5d26-4ed3-4e20-b2a2-735442d26e30

Summary

I want to use dynamic app name for my Expo project. By "dynamic" I mean the name that comes from EAS Secrets. So I've created a Secret called APP_NAME and here is my app.config.js file:

module.exports = {
  "name": process.env.APP_NAME,
  "slug": "dynamic-name-test",
  "owner": "dynamic-name-test",
  "version": "1.0.0",
  "orientation": "portrait",
  "icon": "./assets/icon.png",
  "userInterfaceStyle": "light",
  "splash": {
    "image": "./assets/splash.png",
    "resizeMode": "contain",
    "backgroundColor": "#ffffff"
  },
  "assetBundlePatterns": [
    "**/*"
  ],
  "ios": {
    "supportsTablet": true,
    "bundleIdentifier": "com.dynamic.name.test"
  },
  "android": {
    "adaptiveIcon": {
      "foregroundImage": "./assets/adaptive-icon.png",
      "backgroundColor": "#ffffff"
    },
    "package": "com.dynamic.name.test"
  },
  "web": {
    "favicon": "./assets/favicon.png"
  },
  "extra": {
    "eas": {
      "projectId": "90a76d32-c2b3-4273-a641-b06b07097b60"
    }
  }
}

I successfully submit a build and here is the output of "Read app config" step from Expo dashboard (so it looks like name comes from EAS Secrets):
image

However, I get this error on "Run fastlane" step:
image

I don't have APP_NAME variable being added to my environment locally. And it looks like this "name-from-package-json" comes from package.json file. My package.json file:

{
  "name": "name-from-package-json",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "expo": "~50.0.11",
    "expo-status-bar": "~1.11.1",
    "react": "18.2.0",
    "react-native": "0.73.4",
    "expo-dev-client": "~3.3.9"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0"
  },
  "private": true
}

I expect that such behaviour is either documented or it should use final version of app.config.js file (that includes all env variables from EAS Secrets) rather than my local version of this file (at the moment of call eas build).

Managed or bare?

Managed

Environment

npx expo-env-info:

expo-env-info 1.2.0 environment info:
System:
OS: macOS 14.0
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.19.0 - /opt/homebrew/bin/node
Yarn: 1.22.21 - /opt/homebrew/bin/yarn
npm: 10.2.3 - /opt/homebrew/bin/npm
Watchman: 2023.09.25.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.13.0 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 23.2, iOS 17.2, macOS 14.2, tvOS 17.2, visionOS 1.0, watchOS 10.2
Android SDK:
API Levels: 28, 29, 30, 31, 32, 33
Build Tools: 28.0.3, 29.0.2, 30.0.2, 30.0.3, 31.0.0, 31.0.0, 33.0.0
System Images: android-30 | Google APIs ARM 64 v8a, android-30 | Google APIs Intel x86 Atom, android-31 | Google APIs ARM 64 v8a, android-31 | Google APIs Intel x86 Atom_64, android-32 | Google Play ARM 64 v8a, android-S | Google APIs ARM 64 v8a 2, android-S | Google Play ARM 64 v8a, android-Sv2 | Google APIs ARM 64 v8a
IDEs:
Xcode: 15.2/15C500b - /usr/bin/xcodebuild
npmPackages:
expo: ~50.0.11 => 50.0.11
react: 18.2.0 => 18.2.0
react-native: 0.73.4 => 0.73.4
npmGlobalPackages:
eas-cli: 7.3.0
expo-cli: 5.4.6
Expo Workflow: managed

npx expo-doctor:         

✔ Check Expo config for common issues
✔ Check package.json for common issues
✔ Check native tooling versions
✔ Check dependencies for packages that should not be installed directly
✔ Check for common project setup issues
✔ Check for issues with metro config
✔ Check npm/ yarn versions
✔ Check Expo config (app.json/ app.config.js) schema
✔ Check for legacy global CLI installed locally
✔ Check that native modules do not use incompatible support packages
✔ Check that packages match versions required by installed Expo SDK
✔ Check that native modules use compatible support package versions for installed Expo SDK

Didn't find any issues with the project!

Error output

No response

Reproducible demo or steps to reproduce from a blank project

  1. Create a project in Expo Dashboard.
  2. Create Expo project locally using npx create-expo-app my-app.
  3. Add the app.config.js file, link local project to the project you've just created in Expo dashboard.
  4. Remove hard-coded app name and use some env variable to set you app name, like: process.env.SOME_VARIABLE.
  5. Add a secret to the project in Expo dashboard or using CLI (name of the secret should match env variable that you use for your app name).
  6. Submit a build via eas build.
@serhii-lyshchenko serhii-lyshchenko added the needs review Issue is ready to be reviewed by a maintainer label Mar 11, 2024
@szdziedzic
Copy link
Member

Hey,

I suspect that you get this error because when resolving credentials for your project you don't have APP_NAME env var set locally when running eas build and we use the fallback value from package.json. Secrets are only available during cloud builds and are not accessible in EAS CLI when resolving stuff.

What I think you can do is add APP_NAME to the env section of your eas.json. I don't think that app name is a secret, is it? I would also remove it from secrets.

{
  "build": {
    "production": {
      "env": {
        "APP_NAME": "myappname"
      }
    }
  }
}

@serhii-lyshchenko
Copy link
Author

serhii-lyshchenko commented Mar 18, 2024

@szdziedzic Thanks for the response. I'm on the same page with you.
But there are two questions then:

  1. If I'm developing a multi-tenat app (same codebase, multiple Expo projects and apps in AppStore/PlayStore) - I have to store two unique identifiers (project id and project slug) for each project outside of Expo. And now it turned out that I also need to store app name for each project. I'm curious why having just project id isn't enough (for submitting a build).
  2. I'm also curious why it doesn't work the same way for app identifiers then? Even if I don't have ios.bundleIdentifier and android.package and provide fallback (see the screenshot) - I'm able to submit a build and an identifier will be taken from the EAS Secrets and used for my build.
image

@szdziedzic
Copy link
Member

I'm curious why having just a project ID isn't enough (for submitting a build)

The reason is that the EAS CLI is the place where the resolution of all credentials and other settings for a build. It happens based on the app.json contents and other project configurations (like whether you have ios and android directories in your project, what are the tooling versions installed, and so on). The Xcode build scheme used by the build is resolved based on the name from app.json in CLI and is used during the build process. The name + other stuff need to be correctly defined (if it doesn't match the credentials may not match during the build process, and so on) when running the eas build command, so the CLI can resolve the best build configuration for you.

Additionally, it is allowed to have multiple different sets of credentials per one project, so credentials to the project aren't 1:1 mapping.

I'm also curious why it doesn't work the same way for app identifiers then? Even if I don't have ios.bundleIdentifier and android.package and provide fallback (see the screenshot) - I'm able to submit a build and an identifier will be taken from the EAS Secrets and used for my build.

It's interesting that it even works for you because provisioning profiles are per (Apple) project 🤔 https://docs.expo.dev/app-signing/app-credentials/#provisioning-profiles

However, what I can recommend to you is using the GitHub build trigger for EAS builds. During GH-triggered builds the credentials are resolved on the server side, so you should get correct results using your current setup and it doesn't matter what you have specified for EAS CLI (because it is not used to trigger the build)
https://docs.expo.dev/build/building-from-github/

@szdziedzic
Copy link
Member

Does it make sense to you?

@chimdie
Copy link

chimdie commented May 30, 2024

@szdziedzic Probably unrelated, but how can I manage secrets/environment variables for different profiles(dev, staging and production) remotely? I have configured app.config.ts and eas.json to an extent at least but figured I don't know to deal with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eas build needs review Issue is ready to be reviewed by a maintainer
Projects
None yet
Development

No branches or pull requests

3 participants