From fba1934eb4e68e3e9c354a51b5cb40a06ed4ca92 Mon Sep 17 00:00:00 2001 From: MazurDorian Date: Sun, 20 Oct 2024 13:03:07 +0300 Subject: [PATCH] fix: resolve build issues with React Native 0.69-0.71 --- android/build.gradle | 33 ++-- android/gradle.properties | 5 + android/react-native-helpers.gradle | 48 ++++++ yarn.lock | 243 +++++++++++++++++++++++++++- 4 files changed, 312 insertions(+), 17 deletions(-) create mode 100644 android/react-native-helpers.gradle diff --git a/android/build.gradle b/android/build.gradle index 2464e9bf..14000cb2 100755 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,6 +1,6 @@ buildscript { // Buildscript is evaluated before everything else so we can't use safeExtGet - def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : "1.8.0" + def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['RNKeychain_kotlinVersion'] repositories { maven { url "https://plugins.gradle.org/m2/" @@ -22,11 +22,13 @@ def isNewArchitectureEnabled() { return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" } +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply from: "$projectDir/react-native-helpers.gradle" + if (isNewArchitectureEnabled()) { apply plugin: "com.facebook.react" } -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' repositories { google() @@ -38,13 +40,12 @@ android { if (project.android.hasProperty("namespace")) { namespace = "com.oblador.keychain" } - compileSdkVersion safeExtGet('compileSdkVersion', 34) - buildToolsVersion safeExtGet('buildToolsVersion', '33.0.0') + compileSdkVersion safeExtGet('compileSdkVersion', project.properties['RNKeychain_compileSdkVersion']) defaultConfig { - minSdkVersion safeExtGet('minSdkVersion', 23) - compileSdkVersion safeExtGet('compileSdkVersion', 34) - targetSdkVersion safeExtGet('targetSdkVersion', 34) + minSdkVersion safeExtGet('minSdkVersion', project.properties['RNKeychain_minSdkVersion']) + compileSdkVersion safeExtGet('compileSdkVersion', project.properties['RNKeychain_compileSdkVersion']) + targetSdkVersion safeExtGet('targetSdkVersion', project.properties['RNKeychain_targetSdkVersion']) buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() } @@ -56,22 +57,22 @@ android { buildFeatures { buildConfig true } - - lintOptions { - disable "GradleCompatible" - abortOnError false - } } repositories { mavenCentral() } -def kotlin_version = safeExtGet('kotlinVersion', '1.8.0') +def kotlin_version = safeExtGet('kotlinVersion', project.properties['RNKeychain_kotlinVersion']) dependencies { - //noinspection GradleDynamicVersion - implementation "com.facebook.react:react-android:+" + if (project.ext.shouldConsumeReactNativeFromMavenCentral()) { + // noinspection GradleDynamicVersion + implementation 'com.facebook.react:react-android:+' + } else { + // noinspection GradleDynamicVersion + implementation 'com.facebook.react:react-native:+' + } implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" diff --git a/android/gradle.properties b/android/gradle.properties index 8a6dc92d..593e3257 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -7,3 +7,8 @@ org.gradle.daemon=true android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX android.enableJetifier=true + +RNKeychain_kotlinVersion=1.8.0 +RNKeychain_compileSdkVersion=34 +RNKeychain_targetSdkVersion=34 +RNKeychain_minSdkVersion=23 diff --git a/android/react-native-helpers.gradle b/android/react-native-helpers.gradle new file mode 100644 index 00000000..192c622c --- /dev/null +++ b/android/react-native-helpers.gradle @@ -0,0 +1,48 @@ +def safeAppExtGet(prop, fallback) { + def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') } + appProject?.ext?.has(prop) ? appProject.ext.get(prop) : fallback +} + +// Let's detect react-native's directory, it will be used to determine RN's version +// https://github.com/software-mansion/react-native-reanimated/blob/cda4627c3337c33674f05f755b7485165c6caca9/android/build.gradle#L88 +def resolveReactNativeDirectory() { + def reactNativeLocation = safeAppExtGet("REACT_NATIVE_NODE_MODULES_DIR", null) + if (reactNativeLocation != null) { + return file(reactNativeLocation) + } + + // monorepo workaround + // react-native can be hoisted or in project's own node_modules + def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native") + if (reactNativeFromProjectNodeModules.exists()) { + return reactNativeFromProjectNodeModules + } + + def reactNativeFromNodeModules = file("${projectDir}/../../react-native") + if (reactNativeFromNodeModules.exists()) { + return reactNativeFromNodeModules + } + + throw new GradleException( + "${project.name}: unable to resolve react-native location in " + + "node_modules. You should project extension property (in app/build.gradle) " + + "`REACT_NATIVE_NODE_MODULES_DIR` with path to react-native." + ) +} + +// https://github.com/software-mansion/react-native-reanimated/blob/cda4627c3337c33674f05f755b7485165c6caca9/android/build.gradle#L199#L205 +def reactNativeRootDir = resolveReactNativeDirectory() + +def reactProperties = new Properties() +file("$reactNativeRootDir/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) } + +def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME") +def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.startsWith("0.0.0-") ? 1000 : REACT_NATIVE_VERSION.split("\\.")[1].toInteger() + +project.ext.resolveReactNativeDirectory = { -> + return resolveReactNativeDirectory() +} + +project.ext.shouldConsumeReactNativeFromMavenCentral = { -> + return REACT_NATIVE_MINOR_VERSION >= 71 +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index ef6062a3..8fd173a1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4341,6 +4341,13 @@ __metadata: languageName: node linkType: hard +"@react-native/assets-registry@npm:0.74.88": + version: 0.74.88 + resolution: "@react-native/assets-registry@npm:0.74.88" + checksum: 630b3686d6c9037ccb69fab9e6d4bbc5d8c70914c645d867ca65924414dca2f89d6111ac33869e4f12bd73a1d04bb0624a810a71d979ce81ec71de5988a264ec + languageName: node + linkType: hard + "@react-native/babel-plugin-codegen@npm:0.74.87": version: 0.74.87 resolution: "@react-native/babel-plugin-codegen@npm:0.74.87" @@ -4350,6 +4357,15 @@ __metadata: languageName: node linkType: hard +"@react-native/babel-plugin-codegen@npm:0.74.88": + version: 0.74.88 + resolution: "@react-native/babel-plugin-codegen@npm:0.74.88" + dependencies: + "@react-native/codegen": 0.74.88 + checksum: 8818602f0f1805eb9fdb06d7037d8bb9dad811ea59a35b46ae91664eed9693b5c9407e301266761b48a063e45f9317e041dcf93f98795e920219f8b036db891c + languageName: node + linkType: hard + "@react-native/babel-preset@npm:0.74.87, @react-native/babel-preset@npm:^0.74.5": version: 0.74.87 resolution: "@react-native/babel-preset@npm:0.74.87" @@ -4403,6 +4419,59 @@ __metadata: languageName: node linkType: hard +"@react-native/babel-preset@npm:0.74.88": + version: 0.74.88 + resolution: "@react-native/babel-preset@npm:0.74.88" + dependencies: + "@babel/core": ^7.20.0 + "@babel/plugin-proposal-async-generator-functions": ^7.0.0 + "@babel/plugin-proposal-class-properties": ^7.18.0 + "@babel/plugin-proposal-export-default-from": ^7.0.0 + "@babel/plugin-proposal-logical-assignment-operators": ^7.18.0 + "@babel/plugin-proposal-nullish-coalescing-operator": ^7.18.0 + "@babel/plugin-proposal-numeric-separator": ^7.0.0 + "@babel/plugin-proposal-object-rest-spread": ^7.20.0 + "@babel/plugin-proposal-optional-catch-binding": ^7.0.0 + "@babel/plugin-proposal-optional-chaining": ^7.20.0 + "@babel/plugin-syntax-dynamic-import": ^7.8.0 + "@babel/plugin-syntax-export-default-from": ^7.0.0 + "@babel/plugin-syntax-flow": ^7.18.0 + "@babel/plugin-syntax-nullish-coalescing-operator": ^7.0.0 + "@babel/plugin-syntax-optional-chaining": ^7.0.0 + "@babel/plugin-transform-arrow-functions": ^7.0.0 + "@babel/plugin-transform-async-to-generator": ^7.20.0 + "@babel/plugin-transform-block-scoping": ^7.0.0 + "@babel/plugin-transform-classes": ^7.0.0 + "@babel/plugin-transform-computed-properties": ^7.0.0 + "@babel/plugin-transform-destructuring": ^7.20.0 + "@babel/plugin-transform-flow-strip-types": ^7.20.0 + "@babel/plugin-transform-function-name": ^7.0.0 + "@babel/plugin-transform-literals": ^7.0.0 + "@babel/plugin-transform-modules-commonjs": ^7.0.0 + "@babel/plugin-transform-named-capturing-groups-regex": ^7.0.0 + "@babel/plugin-transform-parameters": ^7.0.0 + "@babel/plugin-transform-private-methods": ^7.22.5 + "@babel/plugin-transform-private-property-in-object": ^7.22.11 + "@babel/plugin-transform-react-display-name": ^7.0.0 + "@babel/plugin-transform-react-jsx": ^7.0.0 + "@babel/plugin-transform-react-jsx-self": ^7.0.0 + "@babel/plugin-transform-react-jsx-source": ^7.0.0 + "@babel/plugin-transform-runtime": ^7.0.0 + "@babel/plugin-transform-shorthand-properties": ^7.0.0 + "@babel/plugin-transform-spread": ^7.0.0 + "@babel/plugin-transform-sticky-regex": ^7.0.0 + "@babel/plugin-transform-typescript": ^7.5.0 + "@babel/plugin-transform-unicode-regex": ^7.0.0 + "@babel/template": ^7.0.0 + "@react-native/babel-plugin-codegen": 0.74.88 + babel-plugin-transform-flow-enums: ^0.0.2 + react-refresh: ^0.14.0 + peerDependencies: + "@babel/core": "*" + checksum: eb367ad4a000b865c8de47e8c379f3a118c63c405c75608bcce9ff4d3cb595c08d4f165202bfe161124ca332a44c94cad4eab3a7bd0df20dfef2473d295e6b0e + languageName: node + linkType: hard + "@react-native/codegen@npm:0.74.87": version: 0.74.87 resolution: "@react-native/codegen@npm:0.74.87" @@ -4420,6 +4489,24 @@ __metadata: languageName: node linkType: hard +"@react-native/codegen@npm:0.74.88": + version: 0.74.88 + resolution: "@react-native/codegen@npm:0.74.88" + dependencies: + "@babel/parser": ^7.20.0 + glob: ^7.1.1 + hermes-parser: 0.19.1 + invariant: ^2.2.4 + jscodeshift: ^0.14.0 + mkdirp: ^0.5.1 + nullthrows: ^1.1.1 + yargs: ^17.6.2 + peerDependencies: + "@babel/preset-env": ^7.1.6 + checksum: 564c40b0874f4996919cb7f709918dd56c1a3eaa2533450bc43d47800971e60b8f3b0a5620a987d584b15c0a5622cc5db2da8a43a67a8c14ee17a1ec0c68adac + languageName: node + linkType: hard + "@react-native/community-cli-plugin@npm:0.74.87": version: 0.74.87 resolution: "@react-native/community-cli-plugin@npm:0.74.87" @@ -4440,6 +4527,26 @@ __metadata: languageName: node linkType: hard +"@react-native/community-cli-plugin@npm:0.74.88": + version: 0.74.88 + resolution: "@react-native/community-cli-plugin@npm:0.74.88" + dependencies: + "@react-native-community/cli-server-api": 13.6.9 + "@react-native-community/cli-tools": 13.6.9 + "@react-native/dev-middleware": 0.74.88 + "@react-native/metro-babel-transformer": 0.74.88 + chalk: ^4.0.0 + execa: ^5.1.1 + metro: ^0.80.3 + metro-config: ^0.80.3 + metro-core: ^0.80.3 + node-fetch: ^2.2.0 + querystring: ^0.2.1 + readline: ^1.3.0 + checksum: d430af646b7c1cc349f66fc2a5122e1823e59a2e2a8fc6aaa3fe3590a894cd589334097d8fdbd46dbe05afdb51768a53d1195380488362381cb8da19cff974f7 + languageName: node + linkType: hard + "@react-native/debugger-frontend@npm:0.74.87": version: 0.74.87 resolution: "@react-native/debugger-frontend@npm:0.74.87" @@ -4447,6 +4554,13 @@ __metadata: languageName: node linkType: hard +"@react-native/debugger-frontend@npm:0.74.88": + version: 0.74.88 + resolution: "@react-native/debugger-frontend@npm:0.74.88" + checksum: 0f9f1211739ff31d65ad204a93cbfbe828b44d92aa606221052da4414d9baa6bfae779223fd442ce51b717bcf1bd546b039152b43d4fbb1999522d09a362259a + languageName: node + linkType: hard + "@react-native/dev-middleware@npm:0.74.87": version: 0.74.87 resolution: "@react-native/dev-middleware@npm:0.74.87" @@ -4468,6 +4582,27 @@ __metadata: languageName: node linkType: hard +"@react-native/dev-middleware@npm:0.74.88": + version: 0.74.88 + resolution: "@react-native/dev-middleware@npm:0.74.88" + dependencies: + "@isaacs/ttlcache": ^1.4.1 + "@react-native/debugger-frontend": 0.74.88 + "@rnx-kit/chromium-edge-launcher": ^1.0.0 + chrome-launcher: ^0.15.2 + connect: ^3.6.5 + debug: ^2.2.0 + node-fetch: ^2.2.0 + nullthrows: ^1.1.1 + open: ^7.0.3 + selfsigned: ^2.4.1 + serve-static: ^1.13.1 + temp-dir: ^2.0.0 + ws: ^6.2.2 + checksum: adfb096b4cef9d341f20f92b72b2e05dca5a29693a3e32084152558b4afab6dd69e61daf7cbb55c955c80e1367c1a69bcbe59fca15b334571b9d3142b1aef8a7 + languageName: node + linkType: hard + "@react-native/eslint-config@npm:^0.74.84": version: 0.74.87 resolution: "@react-native/eslint-config@npm:0.74.87" @@ -4506,6 +4641,13 @@ __metadata: languageName: node linkType: hard +"@react-native/gradle-plugin@npm:0.74.88": + version: 0.74.88 + resolution: "@react-native/gradle-plugin@npm:0.74.88" + checksum: 5deca96fa42ffe49dbf2e11daf6da802c71eaec36c07896be4b543477157be6fd9459e58b71c31204d0f060d04302a08efa4de0bfcae63f0975fa0dca55c22ec + languageName: node + linkType: hard + "@react-native/js-polyfills@npm:0.74.87": version: 0.74.87 resolution: "@react-native/js-polyfills@npm:0.74.87" @@ -4513,6 +4655,13 @@ __metadata: languageName: node linkType: hard +"@react-native/js-polyfills@npm:0.74.88": + version: 0.74.88 + resolution: "@react-native/js-polyfills@npm:0.74.88" + checksum: 31b11123070f5eaf3620d6569d42f0e6ab3345a55986b2fcf866cdf1d69d4cf1bd26b5bd1d3f5b27f4b4b5896916d94f204b3c9885ea9c190cf728be856cb456 + languageName: node + linkType: hard + "@react-native/metro-babel-transformer@npm:0.74.87": version: 0.74.87 resolution: "@react-native/metro-babel-transformer@npm:0.74.87" @@ -4527,6 +4676,20 @@ __metadata: languageName: node linkType: hard +"@react-native/metro-babel-transformer@npm:0.74.88": + version: 0.74.88 + resolution: "@react-native/metro-babel-transformer@npm:0.74.88" + dependencies: + "@babel/core": ^7.20.0 + "@react-native/babel-preset": 0.74.88 + hermes-parser: 0.19.1 + nullthrows: ^1.1.1 + peerDependencies: + "@babel/core": "*" + checksum: d1f90ef2257b5fd8d45a77db5842a5df17cc4ee23a08f62854abd246f0c0fd9dbb05def9f074c12d7000972da16f76b579f4a288251684b5153e218a3d86b2cb + languageName: node + linkType: hard + "@react-native/metro-config@npm:^0.74.5": version: 0.74.87 resolution: "@react-native/metro-config@npm:0.74.87" @@ -4546,6 +4709,13 @@ __metadata: languageName: node linkType: hard +"@react-native/normalize-colors@npm:0.74.88": + version: 0.74.88 + resolution: "@react-native/normalize-colors@npm:0.74.88" + checksum: 348d0f1b9802e824843ec58ed90f72af078b81dd576f72c45caa1ed9846ea733b0dab932e431f88ebc40a186e7443875b64e8e2cf8e669a59abef0aedf2d9aa7 + languageName: node + linkType: hard + "@react-native/typescript-config@npm:^0.74.5, @react-native/typescript-config@npm:^0.74.84": version: 0.74.87 resolution: "@react-native/typescript-config@npm:0.74.87" @@ -4570,6 +4740,23 @@ __metadata: languageName: node linkType: hard +"@react-native/virtualized-lists@npm:0.74.88": + version: 0.74.88 + resolution: "@react-native/virtualized-lists@npm:0.74.88" + dependencies: + invariant: ^2.2.4 + nullthrows: ^1.1.1 + peerDependencies: + "@types/react": ^18.2.6 + react: "*" + react-native: "*" + peerDependenciesMeta: + "@types/react": + optional: true + checksum: 09d412ea8f9e8c087bf0c122b8f518b5fc9d186a123b88ba8edf98768dcb920c3f58b6ca0b82dea2837d0817a8fe66d6bed4bc92782cd2da072a70321b06d621 + languageName: node + linkType: hard + "@rnx-kit/chromium-edge-launcher@npm:^1.0.0": version: 1.0.0 resolution: "@rnx-kit/chromium-edge-launcher@npm:1.0.0" @@ -16587,7 +16774,7 @@ __metadata: languageName: node linkType: hard -"react-native@npm:0.74.5, react-native@npm:^0.74.5": +"react-native@npm:0.74.5": version: 0.74.5 resolution: "react-native@npm:0.74.5" dependencies: @@ -16640,6 +16827,60 @@ __metadata: languageName: node linkType: hard +"react-native@npm:^0.74.5": + version: 0.74.6 + resolution: "react-native@npm:0.74.6" + dependencies: + "@jest/create-cache-key-function": ^29.6.3 + "@react-native-community/cli": 13.6.9 + "@react-native-community/cli-platform-android": 13.6.9 + "@react-native-community/cli-platform-ios": 13.6.9 + "@react-native/assets-registry": 0.74.88 + "@react-native/codegen": 0.74.88 + "@react-native/community-cli-plugin": 0.74.88 + "@react-native/gradle-plugin": 0.74.88 + "@react-native/js-polyfills": 0.74.88 + "@react-native/normalize-colors": 0.74.88 + "@react-native/virtualized-lists": 0.74.88 + abort-controller: ^3.0.0 + anser: ^1.4.9 + ansi-regex: ^5.0.0 + base64-js: ^1.5.1 + chalk: ^4.0.0 + event-target-shim: ^5.0.1 + flow-enums-runtime: ^0.0.6 + glob: ^7.1.1 + invariant: ^2.2.4 + jest-environment-node: ^29.6.3 + jsc-android: ^250231.0.0 + memoize-one: ^5.0.0 + metro-runtime: ^0.80.3 + metro-source-map: ^0.80.3 + mkdirp: ^0.5.1 + nullthrows: ^1.1.1 + pretty-format: ^26.5.2 + promise: ^8.3.0 + react-devtools-core: ^5.0.0 + react-refresh: ^0.14.0 + react-shallow-renderer: ^16.15.0 + regenerator-runtime: ^0.13.2 + scheduler: 0.24.0-canary-efb381bbf-20230505 + stacktrace-parser: ^0.1.10 + whatwg-fetch: ^3.0.0 + ws: ^6.2.2 + yargs: ^17.6.2 + peerDependencies: + "@types/react": ^18.2.6 + react: 18.2.0 + peerDependenciesMeta: + "@types/react": + optional: true + bin: + react-native: cli.js + checksum: c7060a5ed005cf313d90f7b81132f0f4f84b7c655dfd17367a9fa42dc2ce0414bfd08566c5ef55552861e1583f650bde1e21b7a05427c873da093d9aa25c48d3 + languageName: node + linkType: hard + "react-refresh@npm:^0.14.0": version: 0.14.2 resolution: "react-refresh@npm:0.14.2"