본문 바로가기
React Native

eas build 시 build number 수동으로 관리하기 / eas build number 다운그레이드 하기

by 어느새벽 2025. 12. 8.
반응형

빌드할때 빌드 넘버를 version 따로 설정한 파일로 수동 관리하려고 했는데 자꾸 자동 업데이트 돼서 번호가 제각각이었다.

내가 설정한 빌드 넘버가 15라면 android 는 16, ios는 14 이렇게 ㅋㅋㅋㅋㅋ 휴 .....

일단 급한대로 무지성으로 업데이트 했다가 이제는 도저히 회피하면 안될 것 같아서 정리하려 한다.

 

일단 버전 업데이트 하는 로직이 있는 파일이다. 프로젝트 최상단 루트에 만든다.

//version-manager.js

const fs = require("fs");
const argv = process.argv ?? [];
const versionInfo = require("./versionInfo");

function incrementVersion() {
  versionInfo.VERSION = versionInfo.VERSION.replace(/(\d+.\d+.\d+)/g, (match, version) => {
    const versionParts = version.split(".");
    const newVersion = versionParts
      .map((part, index) => {
        if (index === versionParts.length - 1) {
          return parseInt(part, 10) + 1;
        }

        return part;
      })
      .join(".");

    return newVersion;
  });
}

function incrementRuntimeVersion() {
  versionInfo.RUNTIME_VERSION = versionInfo.RUNTIME_VERSION.replace(/(\d+.\d+.\d+)/g, (match, version) => {
    const versionParts = version.split(".");
    const newVersion = versionParts
      .map((part, index) => {
        if (index === versionParts.length - 1) {
          return parseInt(part, 10) + 1;
        }

        return part;
      })
      .join(".");

    return newVersion;
  });
}

function incrementBuildNumber() {
  versionInfo.BUILD_NUMBER = versionInfo.BUILD_NUMBER + 1;
}

if (argv.length === 0 || argv.includes("--a") || argv.includes("--all")) {
  incrementVersion();
  incrementRuntimeVersion();
  incrementBuildNumber();
} else if (argv.includes("--v") || argv.includes("--version")) {
  incrementVersion();
} else if (argv.includes("--r") || argv.includes("--runtime-version")) {
  incrementRuntimeVersion();
} else if (argv.includes("--b") || argv.includes("--build-number")) {
  incrementBuildNumber();
}

const versionInfoFilePath = "./versionInfo.json";

fs.readFile(versionInfoFilePath, "utf8", (err, versionInfoData) => {
  if (err) {
    console.error(err);

    return;
  }
  fs.writeFile(versionInfoFilePath, JSON.stringify(versionInfo, null, 2), "utf8", (_err) => {
    if (_err) {
      console.error(_err);

      return;
    }
    console.log("Version info incremented successfully!");
  });
});

//본인의 프로젝트의 ios는 xcode 파일 이름과 맞춰야한다.
const iosProjectFilePath = "./ios/설정된프로젝트이름.xcodeproj/project.pbxproj";

fs.readFile(iosProjectFilePath, "utf8", (err, data) => {
  if (err) {
    console.error(err);

    return;
  }

  const versionRegex = /MARKETING_VERSION = (\d+.\d+.\d+);/g;
  const buildNumber = /CURRENT_PROJECT_VERSION = (\d+);/g;
  const updatedData = data
    .replace(versionRegex, `MARKETING_VERSION = ${versionInfo.VERSION};`)
    .replace(buildNumber, `CURRENT_PROJECT_VERSION = ${versionInfo.BUILD_NUMBER};`);

  fs.writeFile(iosProjectFilePath, updatedData, "utf8", (_err) => {
    if (_err) {
      console.error(_err);

      return;
    }
    console.log("Project version incremented successfully!");
  });
});

const androidFilePath = "./android/app/build.gradle";

fs.readFile(androidFilePath, "utf8", (err, androidData) => {
  if (err) {
    console.error(err);

    return;
  }

  const versionRegex = /versionName "(\d+.\d+.\d+)"/g;
  const buildNumber = /versionCode (\d+)/g;
  const updatedAndroidData = androidData
    .replace(versionRegex, `versionName "${versionInfo.VERSION}"`)
    .replace(buildNumber, `versionCode ${versionInfo.BUILD_NUMBER}`);

  fs.writeFile(androidFilePath, updatedAndroidData, "utf8", (_err) => {
    if (_err) {
      console.error(_err);

      return;
    }
    console.log("Android version incremented successfully!");
  });
});

 

똑같이 최상단 루트에 versionInfo.json 파일을 만든다.

{
  "VERSION": "1.0.9",
  "RUNTIME_VERSION": "1.0.9",
  "BUILD_NUMBER": 16
}

 

이후 app.config.js나 app.json 파일에 명시된 version들을 versionInfo.json에 가져와서 넣어주면 된다.
이렇게 지정해둔 버전을 안드로이드와 ios에 각각 반영하게 하려면 eas.json 설정을 아래와 같이 해줘야 한다.

// eas.json
{
  "cli": {
    "version": ">= 16.19.3",
    "appVersionSource": "local"  // remote → local로 변경
  },
  "build": {
    "production": {
      "autoIncrement": false,  // true → false로 변경 (선택사항)
      "channel": "production"
    }
  }
}


이렇게 설정하고 빌드해보면 빌드넘버가 내가 지정한 버전으로 반영됨을 알 수 있다.

 

참고로 expo 사이트에서 Builds 목록에서 빌드를 지운다고 해서 프로젝트의 빌드넘버도 바뀌는 것이 아니다. 

프로젝트의 파일로는 현재 빌드 정보를 알 수가 없는데 아래 명령어를 사용하면 된다.

// 빌드 넘버 확인하는 명령어
eas build:version:get --platform android
eas build:version:get --platform ios

// 특정 버전으로 수동 설정
eas build:version:set --platform android
eas build:version:set --platform ios

 

반응형