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

Inline requires and RAM format break app #605

Closed
3 tasks
wmonecke opened this issue Jun 14, 2019 · 8 comments
Closed
3 tasks

Inline requires and RAM format break app #605

wmonecke opened this issue Jun 14, 2019 · 8 comments

Comments

@wmonecke
Copy link

wmonecke commented Jun 14, 2019

OS:

  • Windows
  • [x ] MacOS
  • Linux

Platform:

  • iOS
  • [x ] Android

Output of node -v && npm -v && npm ls --prod --depth=0

v8.9.4
6.5.0
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] (github:FrederickEngelhardt/react-native-color-picker#bb5398e478124f02901836c0bb13907b18255dfd)
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

Config:

Sentry.config('https://[email protected]/1466610').install();

build.gradle:

apply plugin: "com.android.application"

import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation
 *   entryFile: "index.android.js",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

project.ext.react = [
    entryFile: "index.js",
    bundleCommand: "ram-bundle",
    extraPackagerArgs: ["--indexed-ram-bundle"]
]

apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-sentry/sentry.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    defaultConfig {
        applicationId "com.moodpixel"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 28
        versionName "2.8"
        multiDexEnabled true
    }
    dexOptions {
        jumboMode true
    }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    // enabling multiDex for minSdkVersion below 20 (current is 16)
    implementation 'com.android.support:multidex:1.0.3'

    // 3rd party
    implementation project(':react-native-fs')
    implementation project(':rn-fetch-blob')
    implementation project(':react-native-video')
    implementation project(':react-native-sentry')
    implementation project(':react-native-device-info')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-localization')
    implementation project(':react-native-splash-screen')
    implementation project(':react-native-google-signin')
    implementation project(':react-native-linear-gradient')
    
    // react-native-firebase
    implementation project(':react-native-firebase')
    implementation "com.google.firebase:firebase-firestore:17.1.5"
    implementation "com.google.android.gms:play-services-base:16.0.1"
    implementation "com.google.firebase:firebase-core:16.0.6"
    implementation "com.google.firebase:firebase-auth:16.1.0"
    implementation "com.google.firebase:firebase-ads:15.0.1"
    implementation "com.google.firebase:firebase-messaging:17.3.4"
    implementation 'me.leolin:ShortcutBadger:1.1.21@aar'

    // react-native-fbsdk
    implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
    implementation project(':react-native-fbsdk')

    // react-native
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply plugin: 'com.google.gms.google-services'

I have the following issue:

When adding inline-requires and RAM format, I am unable to build on Android.

Error:

Running ./gradlew assembleRelease gives the following error:

> Task :app:bundleReleaseJsAndAssets
warning: the transform cache was reset.
error The resource `/Users/waltermonecke/Documents/Code/React-Native2/index.js` was not found.. Run CLI with --verbose flag for more details.

> Task :app:bundleReleaseJsAndAssets FAILED

> Task :app:bundleReleaseJsAndAssets_SentryUpload FAILED
Processing react-native sourcemaps for Sentry upload.
> Analyzing 2 sources
error: No such file or directory (os error 2)

Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output.
Please attach the full debug log to all bug reports.

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:bundleReleaseJsAndAssets'.
> Process 'command 'node'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:bundleReleaseJsAndAssets_SentryUpload'.
> Process 'command 'node_modules/@sentry/cli/bin/sentry-cli'' finished with non-zero exit value 1

It appears that Processing react-native source maps for Sentry upload. is the issue. What am I doing wrong?

@tonyo
Copy link
Contributor

tonyo commented Jun 14, 2019

Please run your build command with debug logging enabled, and provide the output:

SENTRY_LOG_LEVEL=debug ./gradlew assembleRelease

@wmonecke
Copy link
Author

@tonyo

> Task :app:bundleReleaseJsAndAssets_SentryUpload FAILED
  INFO    2019-06-14 16:25:30.865588 +02:00 Loaded config from /Users/waltermonecke/.sentryclirc
  DEBUG   2019-06-14 16:25:30.867144 +02:00 sentry-cli version: 1.43.0, platform: "darwin", architecture: "x86_64"
  INFO    2019-06-14 16:25:30.867171 +02:00 sentry-cli was invoked with the following command line: "/Users/waltermonecke/Documents/Code/React-Native2/moodPixel/node_modules/@sentr
y/cli/sentry-cli" "react-native" "gradle" "--bundle" "/Users/waltermonecke/Documents/Code/React-Native2/moodPixel/android/app/build/generated/assets/react/release/index.android.bun
dle" "--sourcemap" "/Users/waltermonecke/Documents/Code/React-Native2/moodPixel/android/app/build/generated/assets/react/release/index.android.bundle.map" "--release" "com.moodpixe
l-2.8" "--dist" "28"
Processing react-native sourcemaps for Sentry upload.
  INFO    2019-06-14 16:25:30.869963 +02:00   bundle path: /Users/waltermonecke/Documents/Code/React-Native2/moodPixel/android/app/build/generated/assets/react/release/index.android.bundle
  INFO    2019-06-14 16:25:30.869981 +02:00   sourcemap path: /Users/waltermonecke/Documents/Code/React-Native2/moodPixel/android/app/build/generated/assets/react/release/index.android.bundle.map
  DEBUG   2019-06-14 16:25:30.870472 +02:00 Non-file bundle found
> Analyzing 2 sources
  DEBUG   2019-06-14 16:25:30.871197 +02:00 error: running update nagger
  DEBUG   2019-06-14 16:25:30.871249 +02:00 skipping update nagger because session is not attended
error: No such file or directory (os error 2)
  DEBUG   2019-06-14 16:25:30.873035 +02:00 client close; no transport to shut down  (from sentry)

@tonyo
Copy link
Contributor

tonyo commented Jun 14, 2019

@wmonecke
Can you confirm that both those files exist?
/Users/waltermonecke/Documents/Code/React-Native2/moodPixel/android/app/build/generated/assets/react/release/index.android.bundle
and
/Users/waltermonecke/Documents/Code/React-Native2/moodPixel/android/app/build/generated/assets/react/release/index.android.bundle.map

Especially the second file (source map), it looks like sentry-cli can't find it.

@wmonecke
Copy link
Author

wmonecke commented Jun 14, 2019

@tonyo
No, the release folder is empty :/

It works, if I reverse my metro.config.js file to:
(but without the RAM format)

module.exports = {
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: true,
      },
    }),
  },
};

from

// const modulePaths = require('./packager/modulePaths');
// const resolve = require('path').resolve;
// const fs = require('fs');

// // Update the following line if the root folder of your app is somewhere else.
// const ROOT_FOLDER = resolve(__dirname, '..');

// const config = {
//   transformer: {
//     getTransformOptions: () => {
//       const moduleMap = {};
//       modulePaths.forEach(path => {
//         if (fs.existsSync(path)) {
//           moduleMap[resolve(path)] = true;
//         }
//       });
//       return {
//         preloadedModules: moduleMap,
//         transform: { inlineRequires: { blacklist: moduleMap } },
//       };
//     },
//   },
//   projectRoot:ROOT_FOLDER,
// };

// module.exports = config;

On iOS I am getting this error when building:

File /Users/waltermonecke/Library/Developer/Xcode/DerivedData/moodPixel-ajoyscixyrdigdfuscjixbqjltzi/Build/Intermediates.noindex/ArchiveIntermediates/moodPixel/BuildProductsPath/Release-iphoneos/moodPixel.app/main.jsbundle does not exist. This must be a bug with
+ echo 'React Native, please report it here: https://github.com/facebook/react-native/issues'

@tonyo
Copy link
Contributor

tonyo commented Jun 14, 2019

Ok, then something wrong is happening even before that step. This might be the problem:

> Task :app:bundleReleaseJsAndAssets
warning: the transform cache was reset.
error The resource `/Users/waltermonecke/Documents/Code/React-Native2/index.js` was not found.. Run CLI with --verbose flag for more details.

@wmonecke
Copy link
Author

wmonecke commented Jun 14, 2019

@tonyo
I figured it out: const ROOT_FOLDER = resolve(__dirname, '..');
has to be
const ROOT_FOLDER = resolve(__dirname, '.');

When updating to RN 0.59 index.js and metro.config.js are on the same level.

Also, app crashed after successful build with extraPackagerArgs: ["--indexed-ram-bundle"] so I had to remove it and it worked!

Thank you for your help!

@tonyo
Copy link
Contributor

tonyo commented Jun 14, 2019

Great!

Also, app crashed after successful build with extraPackagerArgs: ["--indexed-ram-bundle"]

It's probably this: facebook/react-native#24967

@tonyo tonyo closed this as completed Jun 14, 2019
@skizzo
Copy link

skizzo commented Jul 29, 2019

Oh man, how long until we can properly use this feature? @tonyo, can you create an Android release with your config that doesn't instantly crash on launch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants