Skip to content

Commit 985177c

Browse files
authored
chore: bump example to 0.68.1 (#212)
* chore: bump example Android code to react-native 0.68.1 * chore: bump example iOS code to react-native 0.68.1
1 parent 4002809 commit 985177c

31 files changed

+1401
-603
lines changed

example/android/.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</natures>
1717
<filteredResources>
1818
<filter>
19-
<id>1634995125997</id>
19+
<id>0</id>
2020
<name></name>
2121
<type>30</type>
2222
<matcher>

example/android/app/build.gradle

Lines changed: 101 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
apply plugin: "com.android.application"
22

33
import com.android.build.OutputFile
4+
import org.apache.tools.ant.taskdefs.condition.Os
45

56
/**
67
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
@@ -120,9 +121,12 @@ def jscFlavor = 'org.webkit:android-jsc:+'
120121
def enableHermes = project.ext.react.get("enableHermes", false);
121122

122123
/**
123-
* Architectures to build native code for in debug.
124+
* Architectures to build native code for.
124125
*/
125-
def nativeArchitectures = project.getProperties().get("reactNativeDebugArchitectures")
126+
def reactNativeArchitectures() {
127+
def value = project.getProperties().get("reactNativeArchitectures")
128+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
129+
}
126130

127131
android {
128132
ndkVersion rootProject.ext.ndkVersion
@@ -140,6 +144,79 @@ android {
140144
targetSdkVersion rootProject.ext.targetSdkVersion
141145
versionCode 1
142146
versionName "1.0"
147+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
148+
149+
if (isNewArchitectureEnabled()) {
150+
// We configure the NDK build only if you decide to opt-in for the New Architecture.
151+
externalNativeBuild {
152+
ndkBuild {
153+
arguments "APP_PLATFORM=android-21",
154+
"APP_STL=c++_shared",
155+
"NDK_TOOLCHAIN_VERSION=clang",
156+
"GENERATED_SRC_DIR=$buildDir/generated/source",
157+
"PROJECT_BUILD_DIR=$buildDir",
158+
"REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
159+
"REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build"
160+
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
161+
cppFlags "-std=c++17"
162+
// Make sure this target name is the same you specify inside the
163+
// src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
164+
targets "blob_courier_example_appmodules"
165+
166+
// Fix for windows limit on number of character in file paths and in command lines
167+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
168+
arguments "NDK_OUT=${rootProject.projectDir.getParent()}\\.cxx",
169+
"NDK_APP_SHORT_COMMANDS=true"
170+
}
171+
}
172+
}
173+
if (!enableSeparateBuildPerCPUArchitecture) {
174+
ndk {
175+
abiFilters (*reactNativeArchitectures())
176+
}
177+
}
178+
}
179+
}
180+
181+
if (isNewArchitectureEnabled()) {
182+
// We configure the NDK build only if you decide to opt-in for the New Architecture.
183+
externalNativeBuild {
184+
ndkBuild {
185+
path "$projectDir/src/main/jni/Android.mk"
186+
}
187+
}
188+
def reactAndroidProjectDir = project(':ReactAndroid').projectDir
189+
def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) {
190+
dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck")
191+
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
192+
into("$buildDir/react-ndk/exported")
193+
}
194+
def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) {
195+
dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck")
196+
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
197+
into("$buildDir/react-ndk/exported")
198+
}
199+
afterEvaluate {
200+
// If you wish to add a custom TurboModule or component locally,
201+
// you should uncomment this line.
202+
// preBuild.dependsOn("generateCodegenArtifactsFromSchema")
203+
preDebugBuild.dependsOn(packageReactNdkDebugLibs)
204+
preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)
205+
206+
// Due to a bug inside AGP, we have to explicitly set a dependency
207+
// between configureNdkBuild* tasks and the preBuild tasks.
208+
// This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
209+
configureNdkBuildRelease.dependsOn(preReleaseBuild)
210+
configureNdkBuildDebug.dependsOn(preDebugBuild)
211+
reactNativeArchitectures().each { architecture ->
212+
tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure {
213+
dependsOn("preDebugBuild")
214+
}
215+
tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure {
216+
dependsOn("preReleaseBuild")
217+
}
218+
}
219+
}
143220
}
144221

145222
lintOptions {
@@ -152,7 +229,7 @@ android {
152229
reset()
153230
enable enableSeparateBuildPerCPUArchitecture
154231
universalApk false // If true, also generate a universal APK
155-
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
232+
include (*reactNativeArchitectures())
156233
}
157234
}
158235
signingConfigs {
@@ -166,11 +243,6 @@ android {
166243
buildTypes {
167244
debug {
168245
signingConfig signingConfigs.debug
169-
if (nativeArchitectures) {
170-
ndk {
171-
abiFilters nativeArchitectures.split(',')
172-
}
173-
}
174246
}
175247
release {
176248
// Caution! In production, you need to generate your own keystore file.
@@ -202,6 +274,7 @@ dependencyLocking {
202274

203275
dependencies {
204276
implementation fileTree(dir: "libs", include: ["*.jar"])
277+
205278
//noinspection GradleDynamicVersion
206279
implementation "com.facebook.react:react-native:+" // From node_modules
207280

@@ -228,6 +301,18 @@ dependencies {
228301
implementation project(':blob_courier')
229302
}
230303

304+
if (isNewArchitectureEnabled()) {
305+
// If new architecture is enabled, we let you build RN from source
306+
// Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
307+
// This will be applied to all the imported transtitive dependency.
308+
configurations.all {
309+
resolutionStrategy.dependencySubstitution {
310+
substitute(module("com.facebook.react:react-native"))
311+
.using(project(":ReactAndroid")).because("On New Architecture we're building React Native from source")
312+
}
313+
}
314+
}
315+
231316
// Run this once to be able to run the application with BUCK
232317
// puts all compile dependencies into folder libs for BUCK to use
233318
task copyDownloadableDepsToLibs(type: Copy) {
@@ -236,3 +321,11 @@ task copyDownloadableDepsToLibs(type: Copy) {
236321
}
237322

238323
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
324+
325+
def isNewArchitectureEnabled() {
326+
// To opt-in for the New Architecture, you can either:
327+
// - Set `newArchEnabled` to true inside the `gradle.properties` file
328+
// - Invoke gradle with `-newArchEnabled=true`
329+
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
330+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
331+
}

example/android/app/src/debug/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
android:usesCleartextTraffic="true"
99
tools:targetApi="28"
1010
tools:ignore="GoogleAppIndexingWarning">
11-
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
11+
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false" />
1212
</application>
1313
</manifest>

example/android/app/src/debug/java/io/deckers/blob_courier_example/ReactNativeFlipper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) Facebook, Inc. and its affiliates.
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
33
*
44
* <p>This source code is licensed under the MPL-2.0 license found in the LICENSE file in the root
55
* directory of this source tree.
@@ -19,6 +19,7 @@
1919
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin;
2020
import com.facebook.flipper.plugins.react.ReactFlipperPlugin;
2121
import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin;
22+
import com.facebook.react.ReactInstanceEventListener;
2223
import com.facebook.react.ReactInstanceManager;
2324
import com.facebook.react.bridge.ReactContext;
2425
import com.facebook.react.modules.network.NetworkingModule;
@@ -48,7 +49,7 @@ public void apply(OkHttpClient.Builder builder) {
4849
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
4950
if (reactContext == null) {
5051
reactInstanceManager.addReactInstanceEventListener(
51-
new ReactInstanceManager.ReactInstanceEventListener() {
52+
new ReactInstanceEventListener() {
5253
@Override
5354
public void onReactContextInitialized(ReactContext reactContext) {
5455
reactInstanceManager.removeReactInstanceEventListener(this);

example/android/app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
<activity
1616
android:name=".MainActivity"
1717
android:label="@string/app_name"
18-
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
18+
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
1919
android:launchMode="singleTask"
20-
android:windowSoftInputMode="adjustResize">
20+
android:windowSoftInputMode="adjustResize"
21+
android:exported="true">
2122
<intent-filter>
2223
<action android:name="android.intent.action.MAIN" />
2324
<category android:name="android.intent.category.LAUNCHER" />

example/android/app/src/main/java/io/deckers/blob_courier_example/MainActivity.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.deckers.blob_courier_example;
22

33
import com.facebook.react.ReactActivity;
4+
import com.facebook.react.ReactActivityDelegate;
5+
import com.facebook.react.ReactRootView;
46

57
public class MainActivity extends ReactActivity {
68

@@ -12,4 +14,27 @@ public class MainActivity extends ReactActivity {
1214
protected String getMainComponentName() {
1315
return "BlobCourierExample";
1416
}
17+
18+
/**
19+
* Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and
20+
* you can specify the rendered you wish to use (Fabric or the older renderer).
21+
*/
22+
@Override
23+
protected ReactActivityDelegate createReactActivityDelegate() {
24+
return new MainActivityDelegate(this, getMainComponentName());
25+
}
26+
27+
public static class MainActivityDelegate extends ReactActivityDelegate {
28+
public MainActivityDelegate(ReactActivity activity, String mainComponentName) {
29+
super(activity, mainComponentName);
30+
}
31+
32+
@Override
33+
protected ReactRootView createRootView() {
34+
ReactRootView reactRootView = new ReactRootView(getContext());
35+
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
36+
reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED);
37+
return reactRootView;
38+
}
39+
}
1540
}

example/android/app/src/main/java/io/deckers/blob_courier_example/MainApplication.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
import com.facebook.react.ReactApplication;
77
import com.facebook.react.ReactNativeHost;
88
import com.facebook.react.ReactPackage;
9+
import com.facebook.react.config.ReactFeatureFlags;
910
import com.facebook.react.ReactInstanceManager;
1011
import com.facebook.soloader.SoLoader;
12+
import io.deckers.blob_courier_example.newarchitecture.MainApplicationReactNativeHost;
1113
import java.lang.reflect.InvocationTargetException;
1214
import java.util.List;
1315

@@ -39,14 +41,23 @@ protected String getJSMainModuleName() {
3941
}
4042
};
4143

44+
private final ReactNativeHost mNewArchitectureNativeHost =
45+
new MainApplicationReactNativeHost(this);
46+
4247
@Override
4348
public ReactNativeHost getReactNativeHost() {
44-
return mReactNativeHost;
49+
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
50+
return mNewArchitectureNativeHost;
51+
} else {
52+
return mReactNativeHost;
53+
}
4554
}
4655

4756
@Override
4857
public void onCreate() {
4958
super.onCreate();
59+
// If you opted-in for the New Architecture, we enable the TurboModule system
60+
ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
5061
SoLoader.init(this, /* native exopackage */ false);
5162
initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); // Remove this line if you don't want Flipper enabled
5263
}

0 commit comments

Comments
 (0)