Search code examples
androidreact-nativeexpootaeas

eas update is not working properly for my project


I am using eas build and update in my expo app, followed the docs for the implementation and everything was working fine. But I just tested it yesterday and it is not working now.

But what I realised is that, when I refresh the app 2 times (as mentioned in docs), it doesn't download any new updates but if I do it multiple times (nearly 5 times), though the update works on that particular refresh but the assets (images and icons) are gone.

And if I refresh the app again, then the update is gone and assets are back, like it reverts back to older update (which is actually the build itself).

Right now, i am using app.config.js as well as app.json (i need app.json for google ads as that is not reading the config from app.config.js).

Here are the config files;

app.config.js

import "dotenv/config";

export default {
  expo: {
    backgroundColor: "#1A1A1A",
    owner: "owner",
    name: "name",
    slug: "slug",
    version: "1.0.0",
    assetBundlePatterns: ["**/*"],
    extra: {
      eas: {
        projectId: "<project id>",
      },
      ...
    },
    runtimeVersion: "1.0.1", // changed the runtime version from 1.0.0 to 1.0.1 as i thought this may be the reason
    updates: {
      url: "https://u.expo.dev/<project id>",
    },
    android: {
      ...,
    },
    
  },
};

app.json

{
  "react-native-google-mobile-ads": {
    "android_app_id": "ca-app-pub-****************" // my google ads id
  }
}

androidManifest.xml

<meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="https://u.expo.dev/<project id>"/>
<meta-data android:name="expo.modules.updates.ENABLED" android:value="true"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/>
<meta-data android:name="expo.modules.updates.EXPO_RUNTIME_VERSION" android:value="1.0.1"/>

I think this is the only relevant code to eas and eas updates.

Any help is greatly appretiated.

Thanks


Solution

  • I was using this code to access env variables;

    In my app.config.js, inside the extra object;

    extra: {
       BASE_URL: process.env.BASE_URL
    
    }
    

    This will load the BASE_URL from .env during build.

    Now to access it in my code, I was using;

    import Constants from 'expo-constants'
    
    const baseUrl = Constants.manifest.extra.BASE_URL
    

    The problem lies in Constants.manifest, it gets undefined after we send an update this extra in that case is undefined, breaking the app. And if the app breaks due to an update, eas rolls back to the previous update.

    To fix it, use Constants.expoConfig.extra.BASE_URL.

    One more thing to note is, while sending an update, we also need to upload the env variables with the new update too, which is done like this;

    BASE_URL=https://example.com ANOTHER_VAR=some_value eas update --branch preview --message "some message"