Skip to content

Commit 8a4f653

Browse files
author
Fran Montiel
authored
Merge pull request #48 from bugfender/feature/upgrade
Feature/upgrade
2 parents 6148edb + 349da41 commit 8a4f653

39 files changed

Lines changed: 8865 additions & 4954 deletions

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16.15
1+
16.17

example/android/app/build.gradle

Lines changed: 124 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import com.android.build.OutputFile
1515
* // the name of the generated asset file containing your JS bundle
1616
* bundleAssetName: "index.android.bundle",
1717
*
18-
* // the entry file for bundle generation
18+
* // the entry file for bundle generation. If none specified and
19+
* // "index.android.js" exists, it will be used. Otherwise "index.js" is
20+
* // default. Can be overridden with ENTRY_FILE environment variable.
1921
* entryFile: "index.android.js",
2022
*
2123
* // https://reactnative.dev/docs/performance#enable-the-ram-format
@@ -37,7 +39,7 @@ import com.android.build.OutputFile
3739
* // bundleInBeta: true,
3840
*
3941
* // whether to disable dev mode in custom build variants (by default only disabled in release)
40-
* // for RnBugfenderExample: to disable dev mode in the staging build type (if configured)
42+
* // for example: to disable dev mode in the staging build type (if configured)
4143
* devDisabledInStaging: true,
4244
* // The configuration property can be in the following formats
4345
* // 'devDisabledIn${productFlavor}${buildType}'
@@ -64,7 +66,7 @@ import com.android.build.OutputFile
6466
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
6567
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
6668
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
67-
* // for RnBugfenderExample, you might want to remove it from here.
69+
* // for example, you might want to remove it from here.
6870
* inputExcludes: ["android/**", "ios/**"],
6971
*
7072
* // override which node gets called and with what additional arguments
@@ -77,7 +79,6 @@ import com.android.build.OutputFile
7779

7880
project.ext.react = [
7981
enableHermes: false, // clean and rebuild if changing
80-
entryFile: "index.tsx",
8182
]
8283

8384
apply from: "../../node_modules/react-native/react.gradle"
@@ -100,7 +101,7 @@ def enableProguardInReleaseBuilds = false
100101
/**
101102
* The preferred build flavor of JavaScriptCore.
102103
*
103-
* For RnBugfenderExample, to use the international variant, you can use:
104+
* For example, to use the international variant, you can use:
104105
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
105106
*
106107
* The international variant includes ICU i18n library and necessary data
@@ -113,33 +114,107 @@ def jscFlavor = 'org.webkit:android-jsc:+'
113114
/**
114115
* Whether to enable the Hermes VM.
115116
*
116-
* This should be set on project.ext.react and mirrored here. If it is not set
117+
* This should be set on project.ext.react and that value will be read here. If it is not set
117118
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
118119
* and the benefits of using Hermes will therefore be sharply reduced.
119120
*/
120121
def enableHermes = project.ext.react.get("enableHermes", false);
121122

123+
/**
124+
* Architectures to build native code for.
125+
*/
126+
def reactNativeArchitectures() {
127+
def value = project.getProperties().get("reactNativeArchitectures")
128+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
129+
}
130+
122131
android {
123-
compileSdkVersion rootProject.ext.compileSdkVersion
132+
ndkVersion rootProject.ext.ndkVersion
124133

125-
compileOptions {
126-
sourceCompatibility JavaVersion.VERSION_1_8
127-
targetCompatibility JavaVersion.VERSION_1_8
128-
}
134+
compileSdkVersion rootProject.ext.compileSdkVersion
129135

130136
defaultConfig {
131-
applicationId "com.example.bugfenderrnbugfender"
137+
applicationId "com.example"
132138
minSdkVersion rootProject.ext.minSdkVersion
133139
targetSdkVersion rootProject.ext.targetSdkVersion
134140
versionCode 1
135141
versionName "1.0"
142+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
143+
144+
if (isNewArchitectureEnabled()) {
145+
// We configure the NDK build only if you decide to opt-in for the New Architecture.
146+
externalNativeBuild {
147+
ndkBuild {
148+
arguments "APP_PLATFORM=android-21",
149+
"APP_STL=c++_shared",
150+
"NDK_TOOLCHAIN_VERSION=clang",
151+
"GENERATED_SRC_DIR=$buildDir/generated/source",
152+
"PROJECT_BUILD_DIR=$buildDir",
153+
"REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
154+
"REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
155+
"NODE_MODULES_DIR=$rootDir/../node_modules"
156+
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
157+
cppFlags "-std=c++17"
158+
// Make sure this target name is the same you specify inside the
159+
// src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
160+
targets "example_appmodules"
161+
}
162+
}
163+
if (!enableSeparateBuildPerCPUArchitecture) {
164+
ndk {
165+
abiFilters (*reactNativeArchitectures())
166+
}
167+
}
168+
}
136169
}
170+
171+
if (isNewArchitectureEnabled()) {
172+
// We configure the NDK build only if you decide to opt-in for the New Architecture.
173+
externalNativeBuild {
174+
ndkBuild {
175+
path "$projectDir/src/main/jni/Android.mk"
176+
}
177+
}
178+
def reactAndroidProjectDir = project(':ReactAndroid').projectDir
179+
def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) {
180+
dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck")
181+
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
182+
into("$buildDir/react-ndk/exported")
183+
}
184+
def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) {
185+
dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck")
186+
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
187+
into("$buildDir/react-ndk/exported")
188+
}
189+
afterEvaluate {
190+
// If you wish to add a custom TurboModule or component locally,
191+
// you should uncomment this line.
192+
// preBuild.dependsOn("generateCodegenArtifactsFromSchema")
193+
preDebugBuild.dependsOn(packageReactNdkDebugLibs)
194+
preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)
195+
196+
// Due to a bug inside AGP, we have to explicitly set a dependency
197+
// between configureNdkBuild* tasks and the preBuild tasks.
198+
// This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
199+
configureNdkBuildRelease.dependsOn(preReleaseBuild)
200+
configureNdkBuildDebug.dependsOn(preDebugBuild)
201+
reactNativeArchitectures().each { architecture ->
202+
tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure {
203+
dependsOn("preDebugBuild")
204+
}
205+
tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure {
206+
dependsOn("preReleaseBuild")
207+
}
208+
}
209+
}
210+
}
211+
137212
splits {
138213
abi {
139214
reset()
140215
enable enableSeparateBuildPerCPUArchitecture
141216
universalApk false // If true, also generate a universal APK
142-
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
217+
include (*reactNativeArchitectures())
143218
}
144219
}
145220
signingConfigs {
@@ -162,16 +237,18 @@ android {
162237
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
163238
}
164239
}
240+
165241
// applicationVariants are e.g. debug, release
166242
applicationVariants.all { variant ->
167243
variant.outputs.each { output ->
168244
// For each separate APK per architecture, set a unique version code as described here:
169245
// https://developer.android.com/studio/build/configure-apk-splits.html
246+
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
170247
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
171248
def abi = output.getFilter(OutputFile.ABI)
172249
if (abi != null) { // null for the universal-debug, universal-release variants
173250
output.versionCodeOverride =
174-
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
251+
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
175252
}
176253

177254
}
@@ -180,38 +257,64 @@ android {
180257

181258
dependencies {
182259
implementation fileTree(dir: "libs", include: ["*.jar"])
260+
183261
//noinspection GradleDynamicVersion
184262
implementation "com.facebook.react:react-native:+" // From node_modules
185263

186-
187264
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
265+
188266
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
189-
exclude group:'com.facebook.fbjni'
267+
exclude group:'com.facebook.fbjni'
190268
}
269+
191270
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
192271
exclude group:'com.facebook.flipper'
193272
exclude group:'com.squareup.okhttp3', module:'okhttp'
194273
}
274+
195275
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
196276
exclude group:'com.facebook.flipper'
197277
}
198278

199279
if (enableHermes) {
200-
def hermesPath = "../../node_modules/hermes-engine/android/";
201-
debugImplementation files(hermesPath + "hermes-debug.aar")
202-
releaseImplementation files(hermesPath + "hermes-release.aar")
280+
//noinspection GradleDynamicVersion
281+
implementation("com.facebook.react:hermes-engine:+") { // From node_modules
282+
exclude group:'com.facebook.fbjni'
283+
}
203284
} else {
204285
implementation jscFlavor
205286
}
287+
}
206288

207-
implementation project(':bugfenderrnbugfender')
289+
if (isNewArchitectureEnabled()) {
290+
// If new architecture is enabled, we let you build RN from source
291+
// Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
292+
// This will be applied to all the imported transtitive dependency.
293+
configurations.all {
294+
resolutionStrategy.dependencySubstitution {
295+
substitute(module("com.facebook.react:react-native"))
296+
.using(project(":ReactAndroid"))
297+
.because("On New Architecture we're building React Native from source")
298+
substitute(module("com.facebook.react:hermes-engine"))
299+
.using(project(":ReactAndroid:hermes-engine"))
300+
.because("On New Architecture we're building Hermes from source")
301+
}
302+
}
208303
}
209304

210305
// Run this once to be able to run the application with BUCK
211306
// puts all compile dependencies into folder libs for BUCK to use
212307
task copyDownloadableDepsToLibs(type: Copy) {
213-
from configurations.compile
308+
from configurations.implementation
214309
into 'libs'
215310
}
216311

217312
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
313+
314+
def isNewArchitectureEnabled() {
315+
// To opt-in for the New Architecture, you can either:
316+
// - Set `newArchEnabled` to true inside the `gradle.properties` file
317+
// - Invoke gradle with `-newArchEnabled=true`
318+
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
319+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
320+
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@
44

55
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
66

7-
<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
7+
<application
8+
android:usesCleartextTraffic="true"
9+
tools:targetApi="28"
10+
tools:ignore="GoogleAppIndexingWarning">
11+
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false" />
12+
</application>
813
</manifest>

example/android/app/src/debug/java/com/example/bugfenderrnbugfender/ReactNativeFlipper.java

Lines changed: 0 additions & 69 deletions
This file was deleted.

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.example.bugfenderrnbugfender">
2+
package="com.example">
33

44
<uses-permission android:name="android.permission.INTERNET" />
55

@@ -13,15 +13,14 @@
1313
<activity
1414
android:name=".MainActivity"
1515
android:label="@string/app_name"
16-
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
16+
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|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" />
2223
</intent-filter>
2324
</activity>
24-
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
2525
</application>
26-
2726
</manifest>

example/android/app/src/main/java/com/example/bugfenderrnbugfender/MainActivity.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)