Tuesday, 10 September 2019

React Native Build script not generating different flavour apks

I inherited this build script for both android and ios to generate apks and .ipas.

So this executes first and you can look below to follow along with the corresponding code:

nps is executing `build` : nps android.build && nps ios.build && nps finish
nps is executing `android.build` : node node_modules/rimraf/bin.js dist/*.apk && babel-node scripts/android/build.js
########################### Starting Android Builds ###########################
starting gradle assembleDevRelease with flag - versionName=1.0.0-1 -PversionCode=1

Next, we get this:

######################## Dev Android Build Successful! ########################
============================= Copying APK to Dist =============================

but when its time to copy the apk over to dist/ folder, it would crash with the following error:

events.js:174
      throw er; // Unhandled 'error' event
      ^

Error [ERR_STREAM_WRITE_AFTER_END]: write after end
    at writeAfterEnd (_stream_writable.js:248:12)
    at WriteStream.Writable.write (_stream_writable.js:296:5)
    at Object.logHeader (/Users/danale/Projects/NFIBEngage/scripts/build.js:72:14)
    at copyArtifactsToDist (/Users/danale/Projects/NFIBEngage/scripts/android/build.js:13:10)
    at /Users/danale/Projects/NFIBEngage/scripts/android/build.js:128:7
    at /Users/danale/Projects/NFIBEngage/node_modules/async/internal/once.js:12:16
    at replenish (/Users/danale/Projects/NFIBEngage/node_modules/async/internal/eachOfLimit.js:59:25)
    at iterateeCallback (/Users/danale/Projects/NFIBEngage/node_modules/async/internal/eachOfLimit.js:49:17)
    at /Users/danale/Projects/NFIBEngage/node_modules/async/internal/onlyOnce.js:12:16
    at /Users/danale/Projects/NFIBEngage/scripts/android/build.js:116:9
Emitted 'error' event at:
    at errorOrDestroy (internal/streams/destroy.js:107:12)
    at writeAfterEnd (_stream_writable.js:250:3)
    at WriteStream.Writable.write (_stream_writable.js:296:5)
    [... lines matching original stack trace ...]
    at /Users/danale/Projects/NFIBEngage/node_modules/async/internal/onlyOnce.js:12:16

I was able to resolve that error by commenting out the following line of code:

const engaInfo = `ENGAGE_VERSION=${fullAppVersion}`;
  const engaEndpoint = `ENGAGE_ENDPOINT=${f.endpoint}`;
  const engaCenter = `APPCENTER_KEY=${f.appcenterKey}`;
  const engaPlatform = "APPCENTER_PLATFORM=android";
  //prettier-ignore
  const prepare = `${engaEndpoint} ${engaCenter} ${engaInfo} ${engaPlatform} npm run setup`;
  const cd = `cd ${androidDirectory}`;
  //prettier-ignore
  const releaseCmd = `./gradlew assemble${f.flavour}Release -PversionName=${fullAppVersion} -PversionCode=${versionCode} && cd ..`;

  exec(`${prepare} && ${cd} && ${releaseCmd}`, err => {
    if (err) {
      return callback(err);
    }

    logger.logHeader(`${f.flavour} Android Build Successful!`, {
      repeatChar: "#"
    });
    // logger.close();
    callback(null);
  });
},

However, the apk it generates to the dist/ folder is engal-undefined.apk. I am unclear on why this script is now generating undefined as opposed to the names of the build flavours for the different apks.

The expected behavior is that it would generate engal-dev.apk, engal-qa.apk, engal-ua.apk and so on.



from React Native Build script not generating different flavour apks

No comments:

Post a Comment