From 98d5b05d70ca64c9686642a152a07adca4d857a8 Mon Sep 17 00:00:00 2001 From: Oscar Bazaldua <511911+oscb@users.noreply.github.com> Date: Mon, 12 Feb 2024 13:53:51 -0800 Subject: [PATCH] fix: update gradle files for 0.73 support (#917) * fix: update gradle files for 0.73 support Current lib should just work with 0.73 but taking preliminary steps to keep up to date based on the work specified [here](https://github.com/react-native-community/discussions-and-proposals/issues/671) And in particular on the revised outputs of [create-react-native-library CLI](https://github.com/callstack/react-native-builder-bob/blob/fc8744092501ba00fd11bdb69e1ecb46fbb63c0f/packages/create-react-native-library/templates/native-common/android/build.gradle) - Updated build.gradle and gradle.properties to match new CLI outputs - Added new AndroidManifest.xml without namespace - Added namespace in build.gradle only if Gradle 7.3+ * fix: refactor deep compare - Refactor deepCompare as a utility from the core. We might want to add this feature in `identify` in the future. - Refactor to pass Typescript linter - Refactor to fix gaps with previous implementation: `old` might have more properties than `new` - Added tests --- packages/core/android/build.gradle | 133 +++++++---------- packages/core/android/gradle.properties | 7 +- .../android/src/main/AndroidManifestNew.xml | 3 + packages/core/src/__tests__/util.test.ts | 99 ++++++++++++- packages/core/src/index.ts | 1 + packages/core/src/util.ts | 40 +++++- .../android/build.gradle | 135 +++++++----------- .../android/gradle.properties | 4 +- .../android/src/main/AndroidManifestNew.xml | 3 + .../plugins/plugin-braze/src/BrazePlugin.tsx | 27 +--- packages/sovran/android/build.gradle | 132 +++++++---------- packages/sovran/android/gradle.properties | 6 +- .../android/src/main/AndroidManifestNew.xml | 3 + 13 files changed, 307 insertions(+), 286 deletions(-) create mode 100644 packages/core/android/src/main/AndroidManifestNew.xml create mode 100644 packages/plugins/plugin-advertising-id/android/src/main/AndroidManifestNew.xml create mode 100644 packages/sovran/android/src/main/AndroidManifestNew.xml diff --git a/packages/core/android/build.gradle b/packages/core/android/build.gradle index 75fadc911..4b81adea5 100644 --- a/packages/core/android/build.gradle +++ b/packages/core/android/build.gradle @@ -1,40 +1,63 @@ buildscript { // Buildscript is evaluated before everything else so we can't use getExtOrDefault - def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['AnalyticsReactNative_kotlinVersion'] + def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["AnalyticsReactNative_kotlinVersion"] repositories { google() - jcenter() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.1' + classpath "com.android.tools.build:gradle:7.2.1" // noinspection DifferentKotlinGradleVersion classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' +def isNewArchitectureEnabled() { + return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true" +} + +apply plugin: "com.android.library" +apply plugin: "kotlin-android" +if (isNewArchitectureEnabled()) { + apply plugin: "com.facebook.react" +} def getExtOrDefault(name) { - return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['AnalyticsReactNative_' + name] + return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["AnalyticsReactNative_" + name] } def getExtOrIntegerDefault(name) { - return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['AnalyticsReactNative_' + name]).toInteger() + return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["AnalyticsReactNative_" + name]).toInteger() +} + +def supportsNamespace() { + def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.') + def major = parsed[0].toInteger() + def minor = parsed[1].toInteger() + + // Namespace support was added in 7.3.0 + return (major == 7 && minor >= 3) || major >= 8 } android { - compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') - buildToolsVersion getExtOrDefault('buildToolsVersion') + if (supportsNamespace()) { + namespace "com.segmentanalyticsreactnative" + + sourceSets { + main { + manifest.srcFile "src/main/AndroidManifestNew.xml" + } + } + } + + compileSdkVersion getExtOrIntegerDefault("compileSdkVersion") + defaultConfig { - minSdkVersion 21 - targetSdkVersion getExtOrIntegerDefault('targetSdkVersion') - compileSdkVersion = getExtOrIntegerDefault('compileSdkVersion') - versionCode 1 - versionName "1.0" + minSdkVersion getExtOrIntegerDefault("minSdkVersion") + targetSdkVersion getExtOrIntegerDefault("targetSdkVersion") } @@ -43,9 +66,11 @@ android { minifyEnabled false } } + lintOptions { - disable 'GradleCompatible' + disable "GradleCompatible" } + compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 @@ -54,80 +79,18 @@ android { repositories { mavenCentral() - jcenter() google() - - def found = false - def defaultDir = null - def androidSourcesName = 'React Native sources' - - if (rootProject.ext.has('reactNativeAndroidRoot')) { - defaultDir = rootProject.ext.get('reactNativeAndroidRoot') - } else { - defaultDir = new File( - projectDir, - '/../../../node_modules/react-native/android' - ) - } - - if (defaultDir.exists()) { - maven { - url defaultDir.toString() - name androidSourcesName - } - - logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}") - found = true - } else { - def parentDir = rootProject.projectDir - - 1.upto(5, { - if (found) return true - parentDir = parentDir.parentFile - - def androidSourcesDir = new File( - parentDir, - 'node_modules/react-native' - ) - - def androidPrebuiltBinaryDir = new File( - parentDir, - 'node_modules/react-native/android' - ) - - if (androidPrebuiltBinaryDir.exists()) { - maven { - url androidPrebuiltBinaryDir.toString() - name androidSourcesName - } - - logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}") - found = true - } else if (androidSourcesDir.exists()) { - maven { - url androidSourcesDir.toString() - name androidSourcesName - } - - logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}") - found = true - } - }) - } - - if (!found) { - throw new GradleException( - "${project.name}: unable to locate React Native android sources. " + - "Ensure you have you installed React Native as a dependency in your project and try again." - ) - } } -def kotlin_version = getExtOrDefault('kotlinVersion') +def kotlin_version = getExtOrDefault("kotlinVersion") dependencies { - // noinspection GradleDynamicVersion - api 'com.facebook.react:react-native:+' + // For < 0.71, this will be from the local maven repo + // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin + //noinspection GradleDynamicVersion + implementation "com.facebook.react:react-native:+" implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation project(path: ':segment_sovran-react-native') + // Requires sovran for communication + implementation project(path: ':segment_sovran-react-native') } + diff --git a/packages/core/android/gradle.properties b/packages/core/android/gradle.properties index 88d70a4cb..7d6b16733 100644 --- a/packages/core/android/gradle.properties +++ b/packages/core/android/gradle.properties @@ -1,4 +1,5 @@ AnalyticsReactNative_kotlinVersion=1.7.0 -AnalyticsReactNative_compileSdkVersion=29 -AnalyticsReactNative_buildToolsVersion=29.0.2 -AnalyticsReactNative_targetSdkVersion=29 \ No newline at end of file +AnalyticsReactNative_minSdkVersion=21 +AnalyticsReactNative_targetSdkVersion=31 +AnalyticsReactNative_compileSdkVersion=31 +AnalyticsReactNative_ndkversion=21.4.7075529 diff --git a/packages/core/android/src/main/AndroidManifestNew.xml b/packages/core/android/src/main/AndroidManifestNew.xml new file mode 100644 index 000000000..1b844704b --- /dev/null +++ b/packages/core/android/src/main/AndroidManifestNew.xml @@ -0,0 +1,3 @@ + + + diff --git a/packages/core/src/__tests__/util.test.ts b/packages/core/src/__tests__/util.test.ts index 0a29e0041..5b34d391d 100644 --- a/packages/core/src/__tests__/util.test.ts +++ b/packages/core/src/__tests__/util.test.ts @@ -1,4 +1,5 @@ -import { chunk, allSettled } from '../util'; +import { UserTraits } from '../types'; +import { chunk, allSettled, deepCompare } from '../util'; describe('#chunk', () => { it('handles empty array', () => { @@ -62,3 +63,99 @@ describe('allSettled', () => { ]); }); }); + +describe('deepCompare', () => { + const base: UserTraits = { + age: 30, + address: { + city: 'San Francisco', + country: 'USA', + }, + company: { + name: 'Twilio', + }, + deepNested: { + level1: { + level2: { + level3: true, + }, + }, + }, + }; + + it('shallow compare, same object should return true', () => { + const a: UserTraits = { ...base }; + const b: UserTraits = a; + expect(deepCompare(a, b)).toBe(true); + }); + + it('deep compare, object copy should return true', () => { + const a: UserTraits = { ...base }; + const b: UserTraits = { ...base }; + expect(deepCompare(a, b)).toBe(true); + }); + + it('deep compare, different key objects should return false', () => { + const a: UserTraits = { ...base }; + const b: UserTraits = { + age: 20, + deepNested: { + level1: { + level2: { + level3: false, + }, + }, + }, + }; + expect(deepCompare(a, b)).toBe(false); + }); + + it('deep compare, modified objects should return false', () => { + const a: UserTraits = { ...base }; + const b: UserTraits = { + ...base, + age: 20, + deepNested: { + level1: { + level2: { + level3: false, + }, + }, + }, + }; + expect(deepCompare(a, b)).toBe(false); + }); + + it('deep compare, different nested objects should return false', () => { + const a: UserTraits = { ...base }; + const b: UserTraits = { + ...base, + age: 20, + deepNested: { + level1: { + level2: { + level3: true, + }, + anotherLevel2: { + level3: true, + }, + }, + }, + }; + expect(deepCompare(a, b)).toBe(false); + }); + + it('deep compare, mistmatching nested object type should return false', () => { + const a: UserTraits = { ...base }; + const b: UserTraits = { + ...base, + age: 20, + deepNested: { + level1: { + level2: 1, + }, + }, + }; + expect(deepCompare(a, b)).toBe(false); + }); +}); diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 31d588902..363fb7f0e 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -11,6 +11,7 @@ export { isDate, objectToString, unknownToString, + deepCompare, } from './util'; export { SegmentClient } from './analytics'; export { SegmentDestination } from './plugins/SegmentDestination'; diff --git a/packages/core/src/util.ts b/packages/core/src/util.ts index 277632c06..ae229abba 100644 --- a/packages/core/src/util.ts +++ b/packages/core/src/util.ts @@ -9,7 +9,7 @@ const sizeOf = (obj: unknown): number => { export const warnMissingNativeModule = () => { const MISSING_NATIVE_MODULE_WARNING = - `The package 'analytics-react-native' can't access a custom native module. Make sure: \n\n` + + "The package 'analytics-react-native' can't access a custom native module. Make sure: \n\n" + Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo managed workflow\n'; @@ -18,7 +18,9 @@ export const warnMissingNativeModule = () => { export const getNativeModule = (moduleName: string) => { const module = (NativeModules[moduleName] as NativeModule) ?? undefined; - if (module === undefined) warnMissingNativeModule(); + if (module === undefined) { + warnMissingNativeModule(); + } return module; }; @@ -143,7 +145,6 @@ export function isDate(value: unknown): value is Date { export function objectToString(value: object, json = true): string | undefined { // If the object has a custom toString we well use that if (value.toString !== Object.prototype.toString) { - // eslint-disable-next-line @typescript-eslint/no-base-to-string return value.toString(); } if (json) { @@ -198,3 +199,36 @@ export const isObject = (value: unknown): value is Record => value !== undefined && typeof value === 'object' && !Array.isArray(value); + +/** + * Utility to deeply compare 2 objects + * @param a unknown object + * @param b unknown object + * @returns true if both objects have the same keys and values + */ +export function deepCompare(a: T, b: T): boolean { + // Shallow compare first, just in case + if (a === b) { + return true; + } + + // If not objects then compare values directly + if (!isObject(a) || !isObject(b)) { + return a === b; + } + + const keysA = Object.keys(a); + const keysB = Object.keys(b); + + if (keysA.length !== keysB.length) { + return false; + } + + for (const key of keysA) { + if (!keysB.includes(key) || !deepCompare(a[key], b[key])) { + return false; + } + } + + return true; +} diff --git a/packages/plugins/plugin-advertising-id/android/build.gradle b/packages/plugins/plugin-advertising-id/android/build.gradle index 764117d10..705a6f6f0 100644 --- a/packages/plugins/plugin-advertising-id/android/build.gradle +++ b/packages/plugins/plugin-advertising-id/android/build.gradle @@ -1,49 +1,76 @@ buildscript { // Buildscript is evaluated before everything else so we can't use getExtOrDefault - def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['AnalyticsReactNativePluginAdvertisingId_kotlinVersion'] + def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["AnalyticsReactNative_kotlinVersion"] repositories { google() - jcenter() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.1' + classpath "com.android.tools.build:gradle:7.2.1" // noinspection DifferentKotlinGradleVersion classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' +def isNewArchitectureEnabled() { + return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true" +} + +apply plugin: "com.android.library" +apply plugin: "kotlin-android" + +if (isNewArchitectureEnabled()) { + apply plugin: "com.facebook.react" +} def getExtOrDefault(name) { - return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['AnalyticsReactNativePluginAdvertisingId_' + name] + return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["AnalyticsReactNativePluginAdvertisingId_" + name] } def getExtOrIntegerDefault(name) { - return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['AnalyticsReactNativePluginAdvertisingId_' + name]).toInteger() + return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["AnalyticsReactNativePluginAdvertisingId_" + name]).toInteger() +} + +def supportsNamespace() { + def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.') + def major = parsed[0].toInteger() + def minor = parsed[1].toInteger() + + // Namespace support was added in 7.3.0 + return (major == 7 && minor >= 3) || major >= 8 } android { - compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') + if (supportsNamespace()) { + namespace "com.analyticsreactnativepluginadvertisingid" + + sourceSets { + main { + manifest.srcFile "src/main/AndroidManifestNew.xml" + } + } + } + + compileSdkVersion getExtOrIntegerDefault("compileSdkVersion") + defaultConfig { - minSdkVersion 19 - targetSdkVersion getExtOrIntegerDefault('targetSdkVersion') - versionCode 1 - versionName "1.0" - + minSdkVersion getExtOrIntegerDefault("minSdkVersion") + targetSdkVersion getExtOrIntegerDefault("targetSdkVersion") + } - + buildTypes { release { minifyEnabled false } } + lintOptions { - disable 'GradleCompatible' + disable "GradleCompatible" } - + compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 @@ -52,80 +79,18 @@ android { repositories { mavenCentral() - jcenter() google() - - def found = false - def defaultDir = null - def androidSourcesName = 'React Native sources' - - if (rootProject.ext.has('reactNativeAndroidRoot')) { - defaultDir = rootProject.ext.get('reactNativeAndroidRoot') - } else { - defaultDir = new File( - projectDir, - '/../../../node_modules/react-native/android' - ) - } - - if (defaultDir.exists()) { - maven { - url defaultDir.toString() - name androidSourcesName - } - - logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}") - found = true - } else { - def parentDir = rootProject.projectDir - - 1.upto(5, { - if (found) return true - parentDir = parentDir.parentFile - - def androidSourcesDir = new File( - parentDir, - 'node_modules/react-native' - ) - - def androidPrebuiltBinaryDir = new File( - parentDir, - 'node_modules/react-native/android' - ) - - if (androidPrebuiltBinaryDir.exists()) { - maven { - url androidPrebuiltBinaryDir.toString() - name androidSourcesName - } - - logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}") - found = true - } else if (androidSourcesDir.exists()) { - maven { - url androidSourcesDir.toString() - name androidSourcesName - } - - logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}") - found = true - } - }) - } - - if (!found) { - throw new GradleException( - "${project.name}: unable to locate React Native android sources. " + - "Ensure you have you installed React Native as a dependency in your project and try again." - ) - } } -def kotlin_version = getExtOrDefault('kotlinVersion') +def kotlin_version = getExtOrDefault("kotlinVersion") dependencies { - // noinspection GradleDynamicVersion - api 'com.facebook.react:react-native:+' + // For < 0.71, this will be from the local maven repo + // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin + //noinspection GradleDynamicVersion + implementation "com.facebook.react:react-native:+" implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + // Required for AdvertisingID implementation "com.google.android.gms:play-services-ads-identifier:18.0.1" } + diff --git a/packages/plugins/plugin-advertising-id/android/gradle.properties b/packages/plugins/plugin-advertising-id/android/gradle.properties index 3b4c82bf2..1056c98cc 100644 --- a/packages/plugins/plugin-advertising-id/android/gradle.properties +++ b/packages/plugins/plugin-advertising-id/android/gradle.properties @@ -1,3 +1,5 @@ AnalyticsReactNativePluginAdvertisingId_kotlinVersion=1.7.0 -AnalyticsReactNativePluginAdvertisingId_compileSdkVersion=31 +AnalyticsReactNativePluginAdvertisingId_minSdkVersion=21 AnalyticsReactNativePluginAdvertisingId_targetSdkVersion=31 +AnalyticsReactNativePluginAdvertisingId_compileSdkVersion=31 +AnalyticsReactNativePluginAdvertisingId_ndkversion=21.4.7075529 diff --git a/packages/plugins/plugin-advertising-id/android/src/main/AndroidManifestNew.xml b/packages/plugins/plugin-advertising-id/android/src/main/AndroidManifestNew.xml new file mode 100644 index 000000000..0a0938ae3 --- /dev/null +++ b/packages/plugins/plugin-advertising-id/android/src/main/AndroidManifestNew.xml @@ -0,0 +1,3 @@ + + + diff --git a/packages/plugins/plugin-braze/src/BrazePlugin.tsx b/packages/plugins/plugin-braze/src/BrazePlugin.tsx index 9e0e674cf..315dd315a 100644 --- a/packages/plugins/plugin-braze/src/BrazePlugin.tsx +++ b/packages/plugins/plugin-braze/src/BrazePlugin.tsx @@ -15,6 +15,7 @@ import { JsonMap, SegmentBrazeSettings, unknownToString, + deepCompare, } from '@segment/analytics-react-native'; import Braze, { GenderTypes, MonthsAsNumber } from '@braze/react-native-sdk'; import flush from './methods/flush'; @@ -83,31 +84,13 @@ export class BrazePlugin extends DestinationPlugin { return undefined; }; - private compareObjects(oldTraits: any, newTraits: any): boolean { - for (let key in newTraits) { - if (newTraits.hasOwnProperty(key)) { - if (typeof newTraits[key] === 'object' && !Array.isArray(newTraits[key])) { - if (!this.compareObjects(oldTraits[key], newTraits[key])) { - return false; - } - } else if (Array.isArray(newTraits[key])) { - for (let i = 0; i < newTraits[key].length; i++) { - if (!this.compareObjects(oldTraits[key][i], newTraits[key][i])) { - return false; - } - } - } else if (oldTraits[key] !== newTraits[key]) { - return false; - } - } - } - return true; - } - identify(event: IdentifyEventType) { //check to see if anything has changed. //if it hasn't changed don't send event - let identical = typeof this.lastSeenTraits?.traits === 'undefined' ? false : this.compareObjects(this.lastSeenTraits?.traits, event.traits); + const identical = + this.lastSeenTraits?.traits === undefined + ? false + : deepCompare(this.lastSeenTraits.traits, event.traits); if ( this.lastSeenTraits?.userId === event.userId && diff --git a/packages/sovran/android/build.gradle b/packages/sovran/android/build.gradle index 9e259b3ee..c90221f69 100644 --- a/packages/sovran/android/build.gradle +++ b/packages/sovran/android/build.gradle @@ -1,49 +1,76 @@ buildscript { // Buildscript is evaluated before everything else so we can't use getExtOrDefault - def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['Sovran_kotlinVersion'] + def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["AnalyticsReactNative_kotlinVersion"] repositories { google() mavenCentral() - jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' + classpath "com.android.tools.build:gradle:7.2.1" // noinspection DifferentKotlinGradleVersion classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' +def isNewArchitectureEnabled() { + return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true" +} + +apply plugin: "com.android.library" +apply plugin: "kotlin-android" + +if (isNewArchitectureEnabled()) { + apply plugin: "com.facebook.react" +} def getExtOrDefault(name) { - return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Sovran_' + name] + return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Sovran_" + name] } def getExtOrIntegerDefault(name) { - return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['Sovran_' + name]).toInteger() + return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Sovran_" + name]).toInteger() +} + +def supportsNamespace() { + def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.') + def major = parsed[0].toInteger() + def minor = parsed[1].toInteger() + + // Namespace support was added in 7.3.0 + return (major == 7 && minor >= 3) || major >= 8 } android { - compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') + if (supportsNamespace()) { + namespace "com.sovranreactnative" + + sourceSets { + main { + manifest.srcFile "src/main/AndroidManifestNew.xml" + } + } + } + + compileSdkVersion getExtOrIntegerDefault("compileSdkVersion") + defaultConfig { - minSdkVersion 21 - targetSdkVersion getExtOrIntegerDefault('targetSdkVersion') - versionCode 1 - versionName "1.0" - + minSdkVersion getExtOrIntegerDefault("minSdkVersion") + targetSdkVersion getExtOrIntegerDefault("targetSdkVersion") + } - + buildTypes { release { minifyEnabled false } } + lintOptions { - disable 'GradleCompatible' + disable "GradleCompatible" } + compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 @@ -52,79 +79,16 @@ android { repositories { mavenCentral() - jcenter() google() - - def found = false - def defaultDir = null - def androidSourcesName = 'React Native sources' - - if (rootProject.ext.has('reactNativeAndroidRoot')) { - defaultDir = rootProject.ext.get('reactNativeAndroidRoot') - } else { - defaultDir = new File( - projectDir, - '/../../../node_modules/react-native/android' - ) - } - - if (defaultDir.exists()) { - maven { - url defaultDir.toString() - name androidSourcesName - } - - logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}") - found = true - } else { - def parentDir = rootProject.projectDir - - 1.upto(5, { - if (found) return true - parentDir = parentDir.parentFile - - def androidSourcesDir = new File( - parentDir, - 'node_modules/react-native' - ) - - def androidPrebuiltBinaryDir = new File( - parentDir, - 'node_modules/react-native/android' - ) - - if (androidPrebuiltBinaryDir.exists()) { - maven { - url androidPrebuiltBinaryDir.toString() - name androidSourcesName - } - - logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}") - found = true - } else if (androidSourcesDir.exists()) { - maven { - url androidSourcesDir.toString() - name androidSourcesName - } - - logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}") - found = true - } - }) - } - - if (!found) { - throw new GradleException( - "${project.name}: unable to locate React Native android sources. " + - "Ensure you have you installed React Native as a dependency in your project and try again." - ) - } } -def kotlin_version = getExtOrDefault('kotlinVersion') +def kotlin_version = getExtOrDefault("kotlinVersion") dependencies { - // noinspection GradleDynamicVersion - api 'com.facebook.react:react-native:+' + // For < 0.71, this will be from the local maven repo + // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin + //noinspection GradleDynamicVersion + implementation "com.facebook.react:react-native:+" implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" } + diff --git a/packages/sovran/android/gradle.properties b/packages/sovran/android/gradle.properties index ef0fc4f8d..fbc2fffa0 100644 --- a/packages/sovran/android/gradle.properties +++ b/packages/sovran/android/gradle.properties @@ -1,3 +1,5 @@ Sovran_kotlinVersion=1.7.0 -Sovran_compileSdkVersion=29 -Sovran_targetSdkVersion=29 +Sovran_minSdkVersion=21 +Sovran_targetSdkVersion=31 +Sovran_compileSdkVersion=31 +Sovran_ndkversion=21.4.7075529 diff --git a/packages/sovran/android/src/main/AndroidManifestNew.xml b/packages/sovran/android/src/main/AndroidManifestNew.xml new file mode 100644 index 000000000..0a0938ae3 --- /dev/null +++ b/packages/sovran/android/src/main/AndroidManifestNew.xml @@ -0,0 +1,3 @@ + + +