reactnativecn / react-native-website

React Native 中文网
https://reactnative.cn
MIT License
216 stars 327 forks source link

同一套代码在两个电脑上打Android包,一个110M,一个145M,拆包看到145M的是jsc引擎,请问是因为什么环境导致的? #676

Closed zhangfuchao closed 1 year ago

zhangfuchao commented 1 year ago

请按以下格式提供问题的相关信息。

问题的具体描述

同一套代码在两个电脑上打Android包,一个110M,一个145M,拆包看到145M的是jsc引擎,请问是因为什么环境导致的? 所有人的电脑上都是110M,只有新配置的打包机上的环境出来的是145M

第一张图是正常的110M的包,第二张图的145M包,每个abi里面都多了一个libjsc.so

image image

REACT NATIVE info 截图

image

### Package

"name": "rocket-chat-reactnative",
"version": "4.28.0",
"private": true,
"scripts": {
    "start": "react-native start",
    "test": "jest",
    "test-update": "jest --updateSnapshot",
    "lint": "eslint . && tsc",
    "prettier-lint": "prettier --write . && yarn lint",
    "ci": "npm run precommit && codecov",
    "ios": "npx react-native run-ios",
    "android": "npx react-native run-android --variant=officialPlayDebug",
    "android-whitelabel": "npx react-native run-android --main-activity chat.rocket.reactnative.MainActivity --variant=experimentalPlayDebug --appId",
    "log-android": "react-native log-android",
    "snyk-protect": "snyk protect",
    "precommit": "lint-staged",
    "generate-source-maps-ios": "react-native bundle --platform ios --dev false --entry-file index.js --bundle-output ios-release.bundle --sourcemap-output ios-release.bundle.map",
    "postinstall": "patch-package && jetify",
    "prepare": "husky install",
    "build-icon-set": "node scripts/build-icon-set.js"
},
"lint-staged": {
    "*.{js,ts,tsx}": [
        "prettier --write",
        "eslint",
        "jest --bail --findRelatedTests"
    ]
},
"dependencies": {
    "@bugsnag/react-native": "^7.10.5",
    "@codler/react-native-keyboard-aware-scroll-view": "^1.0.1",
    "@gorhom/bottom-sheet": "^4",
    "@nozbe/watermelondb": "0.23.0",
    "@react-native-clipboard/clipboard": "^1.8.5",
    "@react-native-community/art": "^1.2.0",
    "@react-native-community/async-storage": "1.12.1",
    "@react-native-community/blur": "^3.6.0",
    "@react-native-community/cameraroll": "4.0.4",
    "@react-native-community/datetimepicker": "3.5.2",
    "@react-native-community/geolocation": "^3.0.3",
    "@react-native-community/hooks": "2.6.0",
    "@react-native-community/masked-view": "0.1.11",
    "@react-native-community/netinfo": "^9.3.0",
    "@react-native-community/picker": "^1.8.1",
    "@react-native-community/slider": "4.2.2",
    "@react-native-cookies/cookies": "6.0.8",
    "@react-native-firebase/analytics": "^7.3.1",
    "@react-native-firebase/app": "^8.2.0",
    "@react-native-firebase/crashlytics": "^8.1.2",
    "@react-navigation/bottom-tabs": "5.11.15",
    "@react-navigation/drawer": "5.12.5",
    "@react-navigation/native": "5.9.4",
    "@react-navigation/stack": "5.14.5",
    "@rocket.chat/message-parser": "0.30.0",
    "@rocket.chat/react-native-fast-image": "^8.2.0",
    "@rocket.chat/sdk": "RocketChat/Rocket.Chat.js.SDK#mobile",
    "@rocket.chat/ui-kit": "^0.31.11",
    "bytebuffer": "^5.0.1",
    "color2k": "1.2.4",
    "commonmark": "git+https://github.com/RocketChat/commonmark.js.git",
    "commonmark-react-renderer": "git+https://github.com/RocketChat/commonmark-react-renderer.git",
    "dequal": "^2.0.2",
    "ejson": "2.2.1",
    "expo-apple-authentication": "3.2.1",
    "expo-av": "9.2.3",
    "expo-file-system": "11.1.3",
    "expo-haptics": "10.1.0",
    "expo-keep-awake": "9.2.0",
    "expo-local-authentication": "11.1.1",
    "expo-video-thumbnails": "5.2.1",
    "expo-web-browser": "9.2.0",
    "hoist-non-react-statics": "3.3.2",
    "i18n-js": "3.8.0",
    "js-base64": "3.6.1",
    "js-sha256": "^0.9.0",
    "lint-staged": "^11.1.0",
    "lodash": "4.17.21",
    "moment": "2.29.1",
    "pretty-bytes": "5.6.0",
    "prop-types": "15.7.2",
    "react": "17.0.1",
    "react-native": "RocketChat/react-native#0.64.2",
    "react-native-animatable": "^1.3.3",
    "react-native-appearance": "0.3.4",
    "react-native-background-timer": "2.4.1",
    "react-native-blob-util": "^0.16.4",
    "react-native-bootsplash": "3.2.4",
    "react-native-config-reader": "^4.1.1",
    "react-native-console-time-polyfill": "1.2.3",
    "react-native-device-info": "8.4.8",
    "react-native-document-picker": "8.1.0",
    "react-native-easy-grid": "^0.2.2",
    "react-native-easy-toast": "^1.2.0",
    "react-native-file-viewer": "^2.1.4",
    "react-native-fs": "^2.20.0",
    "react-native-gesture-handler": "^2.6.0",
    "react-native-image-crop-picker": "file:./private_modules/react-native-image-crop-picker",
    "react-native-image-progress": "^1.1.1",
    "react-native-image-viewing": "^0.2.2",
    "react-native-jitsi-meet": "RocketChat/react-native-jitsi-meet",
    "react-native-keycommands": "2.0.3",
    "react-native-loading-spinner-overlay": "^3.0.1",
    "react-native-localize": "2.1.1",
    "react-native-mime-types": "2.3.0",
    "react-native-mmkv-storage": "0.6.12",
    "react-native-modal": "11.10.0",
    "react-native-modal-dropdown": "^1.0.2",
    "react-native-navigation-bar-color": "2.0.1",
    "react-native-notifications": "file:./private_modules/react-native-notifications",
    "react-native-notifier": "1.6.1",
    "react-native-orientation-locker": "1.1.8",
    "react-native-picker-select": "^8.0.4",
    "react-native-platform-touchable": "1.1.1",
    "react-native-popover-view": "4.0.1",
    "react-native-progress": "^5.0.0",
    "react-native-prompt-android": "^1.1.0",
    "react-native-reanimated": "2.2.2",
    "react-native-render-html": "^6.3.4",
    "react-native-restart": "0.0.22",
    "react-native-safe-area-context": "3.2.0",
    "react-native-screens": "2.9.0",
    "react-native-scrollable-tab-view": "^1.0.0",
    "react-native-simple-crypto": "RocketChat/react-native-simple-crypto#0.5.0",
    "react-native-slowlog": "^1.0.2",
    "react-native-svg": "^12.3.0",
    "react-native-ui-lib": "RocketChat/react-native-ui-lib#minor-improvements",
    "react-native-unimodules": "^0.14.8",
    "react-native-vector-icons": "8.1.0",
    "react-native-webview": "10.3.2",
    "react-redux": "8.0.1",
    "reactotron-react-native": "5.0.0",
    "redux": "4.2.0",
    "redux-immutable-state-invariant": "2.1.0",
    "redux-saga": "1.1.3",
    "remove-markdown": "^0.3.0",
    "reselect": "4.0.0",
    "rn-extensions-share": "RocketChat/rn-extensions-share",
    "rn-root-view": "1.0.3",
    "semver": "7.3.5",
    "ua-parser-js": "^0.7.24",
    "underscore.string": "^3.3.6",
    "url-parse": "1.5.6",
    "use-deep-compare-effect": "1.6.1",
    "xregexp": "5.0.2"
},
"resolutions": {
    "ua-parser-js": "^0.7.24"
},
"devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/eslint-parser": "^7.14.7",
    "@babel/eslint-plugin": "^7.13.0",
    "@babel/plugin-proposal-decorators": "^7.8.3",
    "@babel/plugin-transform-named-capturing-groups-regex": "^7.17.12",
    "@babel/runtime": "^7.12.5",
    "@bugsnag/source-maps": "^2.2.0",
    "@rocket.chat/eslint-config": "^0.4.0",
    "@storybook/addon-storyshots": "5.3.21",
    "@storybook/react-native": "5.3.25",
    "@testing-library/jest-native": "^4.0.4",
    "@testing-library/react-native": "^9.0.0",
    "@types/bytebuffer": "^5.0.43",
    "@types/ejson": "^2.1.3",
    "@types/i18n-js": "^3.8.2",
    "@types/jest": "^26.0.24",
    "@types/lodash": "^4.14.171",
    "@types/react": "^17.0.14",
    "@types/react-native": "0.64.2",
    "@types/react-native-background-timer": "^2.0.0",
    "@types/react-native-config-reader": "^4.1.0",
    "@types/react-native-modal-dropdown": "^1.0.0",
    "@types/react-native-platform-touchable": "^1.1.2",
    "@types/react-native-scrollable-tab-view": "^0.10.2",
    "@types/react-native-vector-icons": "^6.4.10",
    "@types/react-test-renderer": "^17.0.1",
    "@types/semver": "^7.3.9",
    "@types/ua-parser-js": "^0.7.36",
    "@types/url-parse": "^1.4.6",
    "@typescript-eslint/eslint-plugin": "^4.28.3",
    "@typescript-eslint/parser": "^4.28.5",
    "axios": "0.21.1",
    "babel-jest": "^27.0.6",
    "babel-plugin-transform-remove-console": "^6.9.4",
    "codecov": "^3.8.3",
    "detox": "19.7.0",
    "eslint": "^7.31.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-import": "2.22.0",
    "eslint-plugin-jest": "24.7.0",
    "eslint-plugin-jsx-a11y": "6.3.1",
    "eslint-plugin-react": "7.20.3",
    "eslint-plugin-react-hooks": "^4.4.0",
    "eslint-plugin-react-native": "3.8.1",
    "husky": "^6.0.0",
    "identity-obj-proxy": "^3.0.0",
    "jest": "^27.0.6",
    "jest-cli": "^27.0.6",
    "metro-react-native-babel-preset": "^0.64.0",
    "mocha": "9.0.1",
    "otp.js": "1.2.0",
    "patch-package": "6.4.7",
    "prettier": "^2.3.2",
    "react-dom": "17.0.1",
    "react-test-renderer": "17.0.1",
    "reactotron-redux": "3.1.3",
    "reactotron-redux-saga": "4.2.3",
    "typescript": "^4.3.5"
},
"jest": {
    "testPathIgnorePatterns": [
        "e2e",
        "node_modules"
    ],
    "transformIgnorePatterns": [
        "node_modules/(?!(jest-)?@?react-native|@react-native-community|@react-navigation)"
    ],
    "preset": "react-native",
    "coverageDirectory": "./coverage/",
    "collectCoverage": true,
    "moduleNameMapper": {
        ".+\\.(css|styl|less|sass|scss)$": "identity-obj-proxy",
        ".+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js"
    },
    "transform": {
        "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
    },
    "setupFilesAfterEnv": [
        "@testing-library/jest-native/extend-expect",
        "./jest.setup.js"
    ]
},
"snyk": true,
"engines": {
    "node": ">=8.x",
    "npm": ">=4.x"
},
"detox": {
    "runner-config": "e2e/.mocharc.json",
    "specs": "e2e/tests",
    "configurations": {
        "ios.sim.debug": {
            "binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/Rocket.Chat Experimental.app",
            "build": "xcodebuild -workspace ios/RocketChatRN.xcworkspace -scheme RocketChatRN -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
            "type": "ios.simulator",
            "device": {
                "type": "iPhone 11 Pro"
            }
        },
        "ios.sim.release": {
            "binaryPath": "ios/build/Build/Products/Release-iphonesimulator/Rocket.Chat Experimental.app",
            "build": "xcodebuild -workspace ios/RocketChatRN.xcworkspace -scheme RocketChatRN -configuration Release -sdk iphonesimulator -derivedDataPath ios/build",
            "type": "ios.simulator",
            "device": {
                "type": "iPhone 11 Pro"
            },
            "artifacts": {
                "plugins": {
                    "screenshot": {
                        "enabled": true,
                        "shouldTakeAutomaticSnapshots": true,
                        "keepOnlyFailedTestsArtifacts": true,
                        "takeWhen": {
                            "testStart": true,
                            "testDone": true,
                            "appNotReady": true
                        }
                    }
                }
            }
        },
        "android.emu.debug": {
            "device": "Pixel_API_28_AOSP",
            "type": "android.emulator",
            "binaryPath": "android/app/build/outputs/apk/e2ePlay/debug/app-e2e-play-debug.apk",
            "build": "cd android && ./gradlew app:assembleE2ePlayDebug app:assembleE2ePlayDebugAndroidTest -DtestBuildType=debug && cd .."
        },
        "android.emu.release": {
            "device": "Pixel_API_28_AOSP",
            "type": "android.emulator",
            "binaryPath": "android/app/build/outputs/apk/e2ePlay/release/app-e2e-play-release.apk",
            "build": "cd android && ./gradlew app:assembleE2ePlayRelease app:assembleE2ePlayReleaseAndroidTest -DtestBuildType=release && cd .."
        }
    }
}

}

### build.gradle

def safeExtGet(prop, fallback) { rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback }

// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { def taskRequests = getGradle().getStartParameter().getTaskRequests().toString().toLowerCase() def isPlay = !taskRequests.contains("foss")

ext {
    buildToolsVersion = "29.0.3"
    minSdkVersion = 23
    compileSdkVersion = 30
    targetSdkVersion = 30
    ndkVersion = "20.1.5948944"
    glideVersion = "4.11.0"
    kotlin_version = "1.4.10"
    supportLibVersion = "28.0.0"
    libre_build = !(isPlay.toBoolean())
    jitsi_url = isPlay ? "https://github.com/RocketChat/jitsi-maven-repository/raw/master/releases" : "https://github.com/RocketChat/jitsi-maven-repository/raw/libre/releases"
    jitsi_version = isPlay ? "3.6.0" : "3.6.0-libre"
}

repositories {
    mavenLocal()
    google()
    jcenter()
    maven {
        url 'https://maven.fabric.io/public'
    }
}

dependencies {
    if (isPlay) {
        classpath 'com.google.gms:google-services:4.2.0'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.0.0'
    }
    classpath 'com.bugsnag:bugsnag-android-gradle-plugin:5.+'
    classpath 'com.android.tools.build:gradle:4.1.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

} allprojects {

configurations.all {
    resolutionStrategy {
        // Remove this override in 0.65+, as a proper fix is included in react-native itself.
        force "com.facebook.react:react-native:0.64.2"
    }
}
repositories {
    mavenLocal()
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url("$rootDir/../node_modules/react-native/android")
    }
    // maven {
    //     // Android JSC is installed from npm
    //     url("$rootDir/../node_modules/jsc-android/dist")
    // }

    maven {
        url "$rootDir/../node_modules/detox/Detox-android"
    }

    maven {
        url jitsi_url
    }

    google()
    jcenter()
    maven { url 'https://maven.google.com' }
    maven { url 'https://www.jitpack.io' }

    maven {
        url 'http://maven.aliyun.com/nexus/content/repositories/releases/'
    }
    maven {
        url 'https://developer.huawei.com/repo/'
    }
    maven {
        url "https://github.com/jitsi/jitsi-maven-repository/raw/master/releases"
    }
}

}

subprojects { subproject -> afterEvaluate { if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) { android { compileSdkVersion 30 buildToolsVersion "29.0.3" defaultConfig { targetSdkVersion 30 } variantFilter { variant -> def names = variant.flavors*.name if (names.contains("reactNative59")) { setIgnore(true) } } } } } }

### 打包流程

cd android && ./gradlew assembleRelease

sunnylqm commented 1 year ago

你什么信息也没提供,让人猜什么?

zhangfuchao commented 1 year ago

你什么信息也没提供,让人猜什么?

不好意思,上面更新了两张图,代码都是一样的。

sunnylqm commented 1 year ago

请描述完整的环境/版本信息(不然你让人猜什么呢?)

zhangfuchao commented 1 year ago

请描述完整的环境/版本信息(不然你让人猜什么呢?)

  • 请在命令行的项目目录中运行npx react-native info命令,并将其输出结果粘贴到这里。
  • package.json 的内容粘贴到这里。
  • app/build.gradle 中可能有关的配置描述一下
  • 打包的流程描述一下

已完成信息提交,麻烦给看下吧。配置几乎和其他电脑一样,除了这台都是110M

sunnylqm commented 1 year ago

没看到 app/build.gradle 但我假定你是要使用hermes引擎吧,可能有些旧版本rn打包时候不能正确排除未使用的引擎 在 app/build.gradle 里加入以下强行排除jsc

+    packagingOptions {
+        // Make sure libjsc.so does not packed in APK
+        exclude "**/libjsc.so"
+    }
zhangfuchao commented 1 year ago

没看到 app/build.gradle 但我假定你是要使用hermes引擎吧,可能有些旧版本rn打包时候不能正确排除未使用的引擎 在 app/build.gradle 里加入以下强行排除jsc

+    packagingOptions {
+        // Make sure libjsc.so does not packed in APK
+        exclude "**/libjsc.so"
+    }

十分感谢,加了以后可以了