Skip to content

Commit c45d4bc

Browse files
authored
Merge pull request #47 from revtel/feat/rn69
Feat/rn69
2 parents 8938bf0 + 3231a7b commit c45d4bc

40 files changed

+7034
-5476
lines changed

.bundle/config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BUNDLE_PATH: "vendor/bundle"
2+
BUNDLE_FORCE_RUBY_PLATFORM: 1

.flowconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ node_modules/warning/.*
1515
; Flow doesn't support platforms
1616
.*/Libraries/Utilities/LoadingView.js
1717

18+
.*/node_modules/resolve/test/resolver/malformed_package_json/package\.json$
19+
1820
[untyped]
1921
.*/node_modules/@react-native-community/cli/.*/.*
2022

@@ -72,4 +74,4 @@ untyped-import
7274
untyped-type-import
7375

7476
[version]
75-
^0.105.0
77+
^0.176.3

.gitignore

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ buck-out/
4848
# For more information about the recommended setup visit:
4949
# https://docs.fastlane.tools/best-practices/source-control/
5050

51-
*/fastlane/report.xml
52-
*/fastlane/Preview.html
53-
*/fastlane/screenshots
51+
**/fastlane/report.xml
52+
**/fastlane/Preview.html
53+
**/fastlane/screenshots
54+
**/fastlane/test_output
5455

5556
# Bundle artifact
5657
*.jsbundle
5758

58-
# CocoaPods
59+
# Ruby / CocoaPods
5960
/ios/Pods/
61+
/vendor/bundle/
6062

6163
# by revtel
6264
.env

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.7.5

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
3+
ruby '2.7.5'
4+
gem 'cocoapods', '~> 1.11', '>= 1.11.2'

android/app/build.gradle

Lines changed: 101 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,12 @@ def jscFlavor = 'org.webkit:android-jsc:+'
121121
def enableHermes = project.ext.react.get("enableHermes", false);
122122

123123
/**
124-
* Architectures to build native code for in debug.
124+
* Architectures to build native code for.
125125
*/
126-
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+
}
127130

128131
android {
129132
ndkVersion rootProject.ext.ndkVersion
@@ -136,13 +139,80 @@ android {
136139
targetSdkVersion rootProject.ext.targetSdkVersion
137140
versionCode 30
138141
versionName "0.0.30"
142+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
143+
if (isNewArchitectureEnabled()) {
144+
// We configure the NDK build only if you decide to opt-in for the New Architecture.
145+
externalNativeBuild {
146+
ndkBuild {
147+
arguments "APP_PLATFORM=android-21",
148+
"APP_STL=c++_shared",
149+
"NDK_TOOLCHAIN_VERSION=clang",
150+
"GENERATED_SRC_DIR=$buildDir/generated/source",
151+
"PROJECT_BUILD_DIR=$buildDir",
152+
"REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
153+
"REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
154+
"NODE_MODULES_DIR=$rootDir/../node_modules"
155+
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
156+
cppFlags "-std=c++17"
157+
// Make sure this target name is the same you specify inside the
158+
// src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
159+
targets "rndiffapp_appmodules"
160+
}
161+
}
162+
if (!enableSeparateBuildPerCPUArchitecture) {
163+
ndk {
164+
abiFilters (*reactNativeArchitectures())
165+
}
166+
}
167+
}
168+
}
169+
170+
if (isNewArchitectureEnabled()) {
171+
// We configure the NDK build only if you decide to opt-in for the New Architecture.
172+
externalNativeBuild {
173+
ndkBuild {
174+
path "$projectDir/src/main/jni/Android.mk"
175+
}
176+
}
177+
def reactAndroidProjectDir = project(':ReactAndroid').projectDir
178+
def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) {
179+
dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck")
180+
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
181+
into("$buildDir/react-ndk/exported")
182+
}
183+
def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) {
184+
dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck")
185+
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
186+
into("$buildDir/react-ndk/exported")
187+
}
188+
afterEvaluate {
189+
// If you wish to add a custom TurboModule or component locally,
190+
// you should uncomment this line.
191+
// preBuild.dependsOn("generateCodegenArtifactsFromSchema")
192+
preDebugBuild.dependsOn(packageReactNdkDebugLibs)
193+
preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)
194+
// Due to a bug inside AGP, we have to explicitly set a dependency
195+
// between configureNdkBuild* tasks and the preBuild tasks.
196+
// This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
197+
configureNdkBuildRelease.dependsOn(preReleaseBuild)
198+
configureNdkBuildDebug.dependsOn(preDebugBuild)
199+
reactNativeArchitectures().each { architecture ->
200+
tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure {
201+
dependsOn("preDebugBuild")
202+
}
203+
tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure {
204+
dependsOn("preReleaseBuild")
205+
}
206+
}
207+
}
139208
}
209+
140210
splits {
141211
abi {
142212
reset()
143213
enable enableSeparateBuildPerCPUArchitecture
144214
universalApk false // If true, also generate a universal APK
145-
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
215+
include (*reactNativeArchitectures())
146216
}
147217
}
148218
signingConfigs {
@@ -164,11 +234,6 @@ android {
164234
buildTypes {
165235
debug {
166236
signingConfig signingConfigs.debug
167-
if (nativeArchitectures) {
168-
ndk {
169-
abiFilters nativeArchitectures.split(',')
170-
}
171-
}
172237
}
173238
release {
174239
// Caution! In production, you need to generate your own keystore file.
@@ -217,14 +282,31 @@ dependencies {
217282
}
218283

219284
if (enableHermes) {
220-
def hermesPath = "../../node_modules/hermes-engine/android/";
221-
debugImplementation files(hermesPath + "hermes-debug.aar")
222-
releaseImplementation files(hermesPath + "hermes-release.aar")
285+
//noinspection GradleDynamicVersion
286+
implementation("com.facebook.react:hermes-engine:+") { // From node_modules
287+
exclude group:'com.facebook.fbjni'
288+
}
223289
} else {
224290
implementation jscFlavor
225291
}
226292
}
227293

294+
if (isNewArchitectureEnabled()) {
295+
// If new architecture is enabled, we let you build RN from source
296+
// Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
297+
// This will be applied to all the imported transtitive dependency.
298+
configurations.all {
299+
resolutionStrategy.dependencySubstitution {
300+
substitute(module("com.facebook.react:react-native"))
301+
.using(project(":ReactAndroid"))
302+
.because("On New Architecture we're building React Native from source")
303+
substitute(module("com.facebook.react:hermes-engine"))
304+
.using(project(":ReactAndroid:hermes-engine"))
305+
.because("On New Architecture we're building Hermes from source")
306+
}
307+
}
308+
}
309+
228310
// Run this once to be able to run the application with BUCK
229311
// puts all compile dependencies into folder libs for BUCK to use
230312
task copyDownloadableDepsToLibs(type: Copy) {
@@ -234,4 +316,12 @@ task copyDownloadableDepsToLibs(type: Copy) {
234316

235317
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
236318

319+
def isNewArchitectureEnabled() {
320+
// To opt-in for the New Architecture, you can either:
321+
// - Set `newArchEnabled` to true inside the `gradle.properties` file
322+
// - Invoke gradle with `-newArchEnabled=true`
323+
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
324+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
325+
}
326+
237327
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

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>

android/app/src/debug/java/com/nfcopenreader/ReactNativeFlipper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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;
@@ -51,7 +52,7 @@ public void apply(OkHttpClient.Builder builder) {
5152
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
5253
if (reactContext == null) {
5354
reactInstanceManager.addReactInstanceEventListener(
54-
new ReactInstanceManager.ReactInstanceEventListener() {
55+
new ReactInstanceEventListener() {
5556
@Override
5657
public void onReactContextInitialized(ReactContext reactContext) {
5758
reactInstanceManager.removeReactInstanceEventListener(this);

android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
android:label="@string/app_name"
1616
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
1717
android:launchMode="singleTask"
18-
android:windowSoftInputMode="adjustResize">
18+
android:windowSoftInputMode="adjustResize"
19+
android:exported="true">
1920
<intent-filter>
2021
<action android:name="android.intent.action.MAIN" />
2122
<category android:name="android.intent.category.LAUNCHER" />

android/app/src/main/java/com/washow/nfcopenrewriter/MainActivity.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.washow.nfcopenrewriter;
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,35 @@ public class MainActivity extends ReactActivity {
1214
protected String getMainComponentName() {
1315
return "NfcOpenReader";
1416
}
17+
18+
/**
19+
* Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and
20+
* you can specify the renderer you wish to use - the new renderer (Fabric) or the old renderer
21+
* (Paper).
22+
*/
23+
@Override
24+
protected ReactActivityDelegate createReactActivityDelegate() {
25+
return new MainActivityDelegate(this, getMainComponentName());
26+
}
27+
28+
public static class MainActivityDelegate extends ReactActivityDelegate {
29+
public MainActivityDelegate(ReactActivity activity, String mainComponentName) {
30+
super(activity, mainComponentName);
31+
}
32+
33+
@Override
34+
protected ReactRootView createRootView() {
35+
ReactRootView reactRootView = new ReactRootView(getContext());
36+
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
37+
reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED);
38+
return reactRootView;
39+
}
40+
41+
@Override
42+
protected boolean isConcurrentRootEnabled() {
43+
// If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18).
44+
// More on this on https://reactjs.org/blog/2022/03/29/react-v18.html
45+
return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
46+
}
47+
}
1548
}

0 commit comments

Comments
 (0)