Skip to content

Commit 1a99729

Browse files
committed
Compatibility with the old arch
1 parent 1a5587a commit 1a99729

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

android/build.gradle

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,43 @@ def getVersionOrDefault(String flagName, String defaultVersion) {
2929
rootProject.hasProperty(flagName) ? rootProject.properties[flagName] : defaultVersion
3030
}
3131

32+
def resolveReactNativeDirectory() {
33+
def reactNativeLocation = safeExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
34+
if (reactNativeLocation != null) {
35+
return file(reactNativeLocation)
36+
}
37+
38+
// monorepo workaround
39+
// react-native can be hoisted or in project's own node_modules
40+
def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native")
41+
if (reactNativeFromProjectNodeModules.exists()) {
42+
return reactNativeFromProjectNodeModules
43+
}
44+
45+
def reactNativeFromNodeModulesWithReanimated = file("${projectDir}/../../react-native")
46+
if (reactNativeFromNodeModulesWithReanimated.exists()) {
47+
return reactNativeFromNodeModulesWithReanimated
48+
}
49+
50+
throw new Exception(
51+
"[react-native-async-storage] Unable to resolve react-native location in " +
52+
"node_modules. You should add project extension property (in app/build.gradle) " +
53+
"`REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
54+
)
55+
}
56+
57+
def getReactNativeMinorVersion() {
58+
def REACT_NATIVE_DIR = resolveReactNativeDirectory()
59+
60+
def reactProperties = new Properties()
61+
file("$REACT_NATIVE_DIR/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
62+
63+
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
64+
def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.startsWith("0.0.0-") ? 1000 : REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
65+
66+
return REACT_NATIVE_MINOR_VERSION
67+
}
68+
3269
def isNewArchitectureEnabled() {
3370
// To opt-in for the New Architecture, you can either:
3471
// - Set `newArchEnabled` to true inside the `gradle.properties` file
@@ -128,6 +165,10 @@ android {
128165
} else {
129166
srcDirs += 'src/javaPackage/java'
130167
}
168+
169+
if (!isNewArchitectureEnabled()) {
170+
srcDirs += 'src/paper/java'
171+
}
131172
}
132173
}
133174
}
@@ -174,5 +215,9 @@ dependencies {
174215
}
175216

176217
//noinspection GradleDynamicVersion
177-
implementation 'com.facebook.react:react-native:+' // From node_modules
218+
if (isNewArchitectureEnabled() && getReactNativeMinorVersion() < 71) {
219+
implementation project(":ReactAndroid")
220+
} else {
221+
implementation 'com.facebook.react:react-native:+' // from node_modules
222+
}
178223
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
/**
3+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4+
*
5+
* Do not edit this file as changes may cause incorrect behavior and will be lost
6+
* once the code is regenerated.
7+
*
8+
* @generated by codegen project: GenerateModuleJavaSpec.js
9+
*
10+
* @nolint
11+
*/
12+
13+
package com.reactnativecommunity.asyncstorage;
14+
15+
import com.facebook.proguard.annotations.DoNotStrip;
16+
import com.facebook.react.bridge.Callback;
17+
import com.facebook.react.bridge.ReactApplicationContext;
18+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
19+
import com.facebook.react.bridge.ReactMethod;
20+
import com.facebook.react.bridge.ReactModuleWithSpec;
21+
import com.facebook.react.bridge.ReadableArray;
22+
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
23+
24+
public abstract class NativeAsyncStorageModuleSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
25+
public NativeAsyncStorageModuleSpec(ReactApplicationContext reactContext) {
26+
super(reactContext);
27+
}
28+
29+
@ReactMethod
30+
@DoNotStrip
31+
public abstract void multiGet(ReadableArray keys, Callback callback);
32+
33+
@ReactMethod
34+
@DoNotStrip
35+
public abstract void multiSet(ReadableArray kvPairs, Callback callback);
36+
37+
@ReactMethod
38+
@DoNotStrip
39+
public abstract void multiRemove(ReadableArray keys, Callback callback);
40+
41+
@ReactMethod
42+
@DoNotStrip
43+
public abstract void multiMerge(ReadableArray kvPairs, Callback callback);
44+
45+
@ReactMethod
46+
@DoNotStrip
47+
public abstract void getAllKeys(Callback callback);
48+
49+
@ReactMethod
50+
@DoNotStrip
51+
public abstract void clear(Callback callback);
52+
}

0 commit comments

Comments
 (0)