Skip to content

Commit 77b0ed9

Browse files
author
Kadi Kraman
authored
Chore/upgrade android example rn 0.63 (#361)
* Upgrade Android example to RN0.63 * Remove outdated android instructions from the readme * Update peer dependencies in the readme to >=RN0.60 * Remove test template from the example app
1 parent 9a13ac1 commit 77b0ed9

File tree

16 files changed

+1238
-892
lines changed

16 files changed

+1238
-892
lines changed

Example/AndroidExample/.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
root: true,
3+
extends: '@react-native-community',
4+
};

Example/AndroidExample/.flowconfig

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,20 @@
1111
; Ignore duplicate module providers
1212
; For RN Apps installed via npm, "Libraries" folder is inside
1313
; "node_modules/react-native" but in the source repo it is in the root
14-
.*/Libraries/react-native/React.js
14+
node_modules/react-native/Libraries/react-native/React.js
1515

1616
; Ignore polyfills
17-
.*/Libraries/polyfills/.*
17+
node_modules/react-native/Libraries/polyfills/.*
1818

19-
; Ignore metro
20-
.*/node_modules/metro/.*
19+
; These should not be required directly
20+
; require from fbjs/lib instead: require('fbjs/lib/warning')
21+
node_modules/warning/.*
22+
23+
; Flow doesn't support platforms
24+
.*/Libraries/Utilities/HMRLoadingView.js
25+
26+
[untyped]
27+
.*/node_modules/@react-native-community/cli/.*/.*
2128

2229
[include]
2330

@@ -31,6 +38,10 @@ emoji=true
3138
esproposal.optional_chaining=enable
3239
esproposal.nullish_coalescing=enable
3340

41+
module.file_ext=.js
42+
module.file_ext=.json
43+
module.file_ext=.ios.js
44+
3445
module.system=haste
3546
module.system.haste.use_name_reducers=true
3647
# get basename
@@ -43,27 +54,46 @@ module.system.haste.name_reducers='^\(.*\)\.android$' -> '\1'
4354
module.system.haste.name_reducers='^\(.*\)\.native$' -> '\1'
4455
module.system.haste.paths.blacklist=.*/__tests__/.*
4556
module.system.haste.paths.blacklist=.*/__mocks__/.*
46-
module.system.haste.paths.blacklist=<PROJECT_ROOT>/node_modules/react-native/Libraries/Animated/src/polyfills/.*
4757
module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/Libraries/.*
58+
module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/RNTester/.*
59+
module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/IntegrationTests/.*
60+
module.system.haste.paths.blacklist=<PROJECT_ROOT>/node_modules/react-native/Libraries/react-native/react-native-implementation.js
61+
module.system.haste.paths.blacklist=<PROJECT_ROOT>/node_modules/react-native/Libraries/Animated/src/polyfills/.*
4862

4963
munge_underscores=true
5064

5165
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
5266

53-
module.file_ext=.js
54-
module.file_ext=.jsx
55-
module.file_ext=.json
56-
module.file_ext=.native.js
57-
5867
suppress_type=$FlowIssue
5968
suppress_type=$FlowFixMe
6069
suppress_type=$FlowFixMeProps
6170
suppress_type=$FlowFixMeState
6271

63-
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
64-
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
65-
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
72+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)
73+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+
6674
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
6775

76+
[lints]
77+
sketchy-null-number=warn
78+
sketchy-null-mixed=warn
79+
sketchy-number=warn
80+
untyped-type-import=warn
81+
nonstrict-import=warn
82+
deprecated-type=warn
83+
unsafe-getters-setters=warn
84+
inexact-spread=warn
85+
unnecessary-invariant=warn
86+
signature-verification-failure=warn
87+
deprecated-utility=error
88+
89+
[strict]
90+
deprecated-type
91+
nonstrict-import
92+
sketchy-null
93+
unclear-type
94+
unsafe-getters-setters
95+
untyped-import
96+
untyped-type-import
97+
6898
[version]
69-
^0.92.0
99+
^0.98.0

Example/AndroidExample/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ buck-out/
5454

5555
# Bundle artifact
5656
*.jsbundle
57+
58+
# CocoaPods
59+
/ios/Pods/

Example/AndroidExample/android/app/build.gradle

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import com.android.build.OutputFile
1818
* // the entry file for bundle generation
1919
* entryFile: "index.android.js",
2020
*
21+
* // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
22+
* bundleCommand: "ram-bundle",
23+
*
2124
* // whether to bundle JS and assets in debug mode
2225
* bundleInDebug: false,
2326
*
@@ -73,7 +76,8 @@ import com.android.build.OutputFile
7376
*/
7477

7578
project.ext.react = [
76-
entryFile: "index.js"
79+
entryFile: "index.js",
80+
enableHermes: false, // clean and rebuild if changing
7781
]
7882

7983
apply from: "../../node_modules/react-native/react.gradle"
@@ -93,6 +97,28 @@ def enableSeparateBuildPerCPUArchitecture = false
9397
*/
9498
def enableProguardInReleaseBuilds = false
9599

100+
/**
101+
* The preferred build flavor of JavaScriptCore.
102+
*
103+
* For example, to use the international variant, you can use:
104+
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
105+
*
106+
* The international variant includes ICU i18n library and necessary data
107+
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
108+
* give correct results when using with locales other than en-US. Note that
109+
* this variant is about 6MiB larger per architecture than default.
110+
*/
111+
def jscFlavor = 'org.webkit:android-jsc:+'
112+
113+
/**
114+
* Whether to enable the Hermes VM.
115+
*
116+
* This should be set on project.ext.react and mirrored here. If it is not set
117+
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
118+
* and the benefits of using Hermes will therefore be sharply reduced.
119+
*/
120+
def enableHermes = project.ext.react.get("enableHermes", false);
121+
96122
android {
97123
compileSdkVersion rootProject.ext.compileSdkVersion
98124

@@ -119,8 +145,22 @@ android {
119145
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
120146
}
121147
}
148+
signingConfigs {
149+
debug {
150+
storeFile file('debug.keystore')
151+
storePassword 'android'
152+
keyAlias 'androiddebugkey'
153+
keyPassword 'android'
154+
}
155+
}
122156
buildTypes {
157+
debug {
158+
signingConfig signingConfigs.debug
159+
}
123160
release {
161+
// Caution! In production, you need to generate your own keystore file.
162+
// see https://facebook.github.io/react-native/docs/signed-apk-android.
163+
signingConfig signingConfigs.debug
124164
minifyEnabled enableProguardInReleaseBuilds
125165
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
126166
}
@@ -129,22 +169,38 @@ android {
129169
applicationVariants.all { variant ->
130170
variant.outputs.each { output ->
131171
// For each separate APK per architecture, set a unique version code as described here:
132-
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
133-
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
172+
// https://developer.android.com/studio/build/configure-apk-splits.html
173+
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
134174
def abi = output.getFilter(OutputFile.ABI)
135175
if (abi != null) { // null for the universal-debug, universal-release variants
136176
output.versionCodeOverride =
137177
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
138178
}
179+
139180
}
140181
}
182+
183+
packagingOptions {
184+
pickFirst '**/armeabi-v7a/libc++_shared.so'
185+
pickFirst '**/x86/libc++_shared.so'
186+
pickFirst '**/arm64-v8a/libc++_shared.so'
187+
pickFirst '**/x86_64/libc++_shared.so'
188+
pickFirst '**/x86/libjsc.so'
189+
pickFirst '**/armeabi-v7a/libjsc.so'
190+
}
141191
}
142192

143193
dependencies {
144-
implementation project(':react-native-app-auth')
145194
implementation fileTree(dir: "libs", include: ["*.jar"])
146-
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
147195
implementation "com.facebook.react:react-native:+" // From node_modules
196+
197+
if (enableHermes) {
198+
def hermesPath = "../../node_modules/hermesvm/android/";
199+
debugImplementation files(hermesPath + "hermes-debug.aar")
200+
releaseImplementation files(hermesPath + "hermes-release.aar")
201+
} else {
202+
implementation jscFlavor
203+
}
148204
}
149205

150206
// Run this once to be able to run the application with BUCK
@@ -153,3 +209,5 @@ task copyDownloadableDepsToLibs(type: Copy) {
153209
from configurations.compile
154210
into 'libs'
155211
}
212+
213+
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

Example/AndroidExample/android/app/proguard-rules.pro

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,3 @@
88
# http://developer.android.com/guide/developing/tools/proguard.html
99

1010
# Add any project specific keep options here:
11-
12-
# If your project uses WebView with JS, uncomment the following
13-
# and specify the fully qualified class name to the JavaScript interface
14-
# class:
15-
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16-
# public *;
17-
#}

Example/AndroidExample/android/app/src/main/java/com/rnappauthandroidexample/MainApplication.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package com.rnappauthandroidexample;
22

33
import android.app.Application;
4+
import android.util.Log;
45

6+
import com.facebook.react.PackageList;
7+
import com.facebook.hermes.reactexecutor.HermesExecutorFactory;
8+
import com.facebook.react.bridge.JavaScriptExecutorFactory;
59
import com.facebook.react.ReactApplication;
6-
import com.rnappauth.RNAppAuthPackage;
710
import com.facebook.react.ReactNativeHost;
811
import com.facebook.react.ReactPackage;
9-
import com.facebook.react.shell.MainReactPackage;
1012
import com.facebook.soloader.SoLoader;
1113

12-
import java.util.Arrays;
1314
import java.util.List;
1415

1516
public class MainApplication extends Application implements ReactApplication {
@@ -22,10 +23,11 @@ public boolean getUseDeveloperSupport() {
2223

2324
@Override
2425
protected List<ReactPackage> getPackages() {
25-
return Arrays.<ReactPackage>asList(
26-
new MainReactPackage(),
27-
new RNAppAuthPackage()
28-
);
26+
@SuppressWarnings("UnnecessaryLocalVariable")
27+
List<ReactPackage> packages = new PackageList(this).getPackages();
28+
// Packages that cannot be autolinked yet can be added manually here, for example:
29+
// packages.add(new MyReactNativePackage());
30+
return packages;
2931
}
3032

3133
@Override

Example/AndroidExample/android/app/src/main/res/values/styles.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<!-- Base application theme. -->
44
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
55
<!-- Customize your theme here. -->
6+
<item name="android:textColor">#000000</item>
67
</style>
78

89
</resources>

Example/AndroidExample/android/build.gradle

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ buildscript {
1313
jcenter()
1414
}
1515
dependencies {
16-
classpath('com.android.tools.build:gradle:3.4.1')
16+
classpath("com.android.tools.build:gradle:3.4.1")
1717

1818
// NOTE: Do not place your application dependencies here; they belong
1919
// in the individual module build.gradle files
@@ -23,11 +23,16 @@ buildscript {
2323
allprojects {
2424
repositories {
2525
mavenLocal()
26-
google()
27-
jcenter()
2826
maven {
2927
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
30-
url "$rootDir/../node_modules/react-native/android"
28+
url("$rootDir/../node_modules/react-native/android")
29+
}
30+
maven {
31+
// Android JSC is installed from npm
32+
url("$rootDir/../node_modules/jsc-android/dist")
3133
}
34+
35+
google()
36+
jcenter()
3237
}
3338
}

Example/AndroidExample/android/gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@
1616
# This option should only be used with decoupled projects. More details, visit
1717
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1818
# org.gradle.parallel=true
19+
20+
android.useAndroidX=true
21+
android.enableJetifier=true

Example/AndroidExample/android/keystores/BUCK

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

0 commit comments

Comments
 (0)