Skip to content

Commit 5519de9

Browse files
authored
Fix android example app (#168)
* Fix package version inconsistency with package.json and its lock file * Copied and pasted app/build.gradle from template at facebook/react-native https://github.com/facebook/react-native/blob/v0.63.4/template/android/app/build.gradle * Specify FLIPPER_VERSION for gradle properties * Include debug.keystore so that anyone can build example app * Fix property reference in JS class * Remove onAuthenticate props from Android FingerPrintPopup and present alert instead of it * Present alert on authentication failed * Update applicationId from default value
1 parent 910e563 commit 5519de9

File tree

6 files changed

+231
-6
lines changed

6 files changed

+231
-6
lines changed

examples/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ yarn-error.log
3939
buck-out/
4040
\.buckd/
4141
*.keystore
42+
!debug.keystore
4243

4344
# fastlane
4445
#

examples/android/app/build.gradle

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
apply plugin: "com.android.application"
2+
3+
import com.android.build.OutputFile
4+
5+
/**
6+
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
7+
* and bundleReleaseJsAndAssets).
8+
* These basically call `react-native bundle` with the correct arguments during the Android build
9+
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
10+
* bundle directly from the development server. Below you can see all the possible configurations
11+
* and their defaults. If you decide to add a configuration block, make sure to add it before the
12+
* `apply from: "../../node_modules/react-native/react.gradle"` line.
13+
*
14+
* project.ext.react = [
15+
* // the name of the generated asset file containing your JS bundle
16+
* bundleAssetName: "index.android.bundle",
17+
*
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.
21+
* entryFile: "index.android.js",
22+
*
23+
* // https://reactnative.dev/docs/performance#enable-the-ram-format
24+
* bundleCommand: "ram-bundle",
25+
*
26+
* // whether to bundle JS and assets in debug mode
27+
* bundleInDebug: false,
28+
*
29+
* // whether to bundle JS and assets in release mode
30+
* bundleInRelease: true,
31+
*
32+
* // whether to bundle JS and assets in another build variant (if configured).
33+
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
34+
* // The configuration property can be in the following formats
35+
* // 'bundleIn${productFlavor}${buildType}'
36+
* // 'bundleIn${buildType}'
37+
* // bundleInFreeDebug: true,
38+
* // bundleInPaidRelease: true,
39+
* // bundleInBeta: true,
40+
*
41+
* // whether to disable dev mode in custom build variants (by default only disabled in release)
42+
* // for example: to disable dev mode in the staging build type (if configured)
43+
* devDisabledInStaging: true,
44+
* // The configuration property can be in the following formats
45+
* // 'devDisabledIn${productFlavor}${buildType}'
46+
* // 'devDisabledIn${buildType}'
47+
*
48+
* // the root of your project, i.e. where "package.json" lives
49+
* root: "../../",
50+
*
51+
* // where to put the JS bundle asset in debug mode
52+
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
53+
*
54+
* // where to put the JS bundle asset in release mode
55+
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
56+
*
57+
* // where to put drawable resources / React Native assets, e.g. the ones you use via
58+
* // require('./image.png')), in debug mode
59+
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
60+
*
61+
* // where to put drawable resources / React Native assets, e.g. the ones you use via
62+
* // require('./image.png')), in release mode
63+
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
64+
*
65+
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
66+
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
67+
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
68+
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
69+
* // for example, you might want to remove it from here.
70+
* inputExcludes: ["android/**", "ios/**"],
71+
*
72+
* // override which node gets called and with what additional arguments
73+
* nodeExecutableAndArgs: ["node"],
74+
*
75+
* // supply additional arguments to the packager
76+
* extraPackagerArgs: []
77+
* ]
78+
*/
79+
80+
project.ext.react = [
81+
enableHermes: false, // clean and rebuild if changing
82+
]
83+
84+
apply from: "../../node_modules/react-native/react.gradle"
85+
86+
/**
87+
* Set this to true to create two separate APKs instead of one:
88+
* - An APK that only works on ARM devices
89+
* - An APK that only works on x86 devices
90+
* The advantage is the size of the APK is reduced by about 4MB.
91+
* Upload all the APKs to the Play Store and people will download
92+
* the correct one based on the CPU architecture of their device.
93+
*/
94+
def enableSeparateBuildPerCPUArchitecture = false
95+
96+
/**
97+
* Run Proguard to shrink the Java bytecode in release builds.
98+
*/
99+
def enableProguardInReleaseBuilds = false
100+
101+
/**
102+
* The preferred build flavor of JavaScriptCore.
103+
*
104+
* For example, to use the international variant, you can use:
105+
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
106+
*
107+
* The international variant includes ICU i18n library and necessary data
108+
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
109+
* give correct results when using with locales other than en-US. Note that
110+
* this variant is about 6MiB larger per architecture than default.
111+
*/
112+
def jscFlavor = 'org.webkit:android-jsc:+'
113+
114+
/**
115+
* Whether to enable the Hermes VM.
116+
*
117+
* This should be set on project.ext.react and mirrored here. If it is not set
118+
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
119+
* and the benefits of using Hermes will therefore be sharply reduced.
120+
*/
121+
def enableHermes = project.ext.react.get("enableHermes", false);
122+
123+
android {
124+
compileSdkVersion rootProject.ext.compileSdkVersion
125+
126+
compileOptions {
127+
sourceCompatibility JavaVersion.VERSION_1_8
128+
targetCompatibility JavaVersion.VERSION_1_8
129+
}
130+
131+
defaultConfig {
132+
applicationId "com.example.fingerprintscannerexample"
133+
minSdkVersion rootProject.ext.minSdkVersion
134+
targetSdkVersion rootProject.ext.targetSdkVersion
135+
versionCode 1
136+
versionName "1.0"
137+
}
138+
splits {
139+
abi {
140+
reset()
141+
enable enableSeparateBuildPerCPUArchitecture
142+
universalApk false // If true, also generate a universal APK
143+
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
144+
}
145+
}
146+
signingConfigs {
147+
debug {
148+
storeFile file('debug.keystore')
149+
storePassword 'android'
150+
keyAlias 'androiddebugkey'
151+
keyPassword 'android'
152+
}
153+
}
154+
buildTypes {
155+
debug {
156+
signingConfig signingConfigs.debug
157+
}
158+
release {
159+
// Caution! In production, you need to generate your own keystore file.
160+
// see https://reactnative.dev/docs/signed-apk-android.
161+
signingConfig signingConfigs.debug
162+
minifyEnabled enableProguardInReleaseBuilds
163+
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
164+
}
165+
}
166+
167+
// applicationVariants are e.g. debug, release
168+
applicationVariants.all { variant ->
169+
variant.outputs.each { output ->
170+
// For each separate APK per architecture, set a unique version code as described here:
171+
// https://developer.android.com/studio/build/configure-apk-splits.html
172+
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
173+
def abi = output.getFilter(OutputFile.ABI)
174+
if (abi != null) { // null for the universal-debug, universal-release variants
175+
output.versionCodeOverride =
176+
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
177+
}
178+
179+
}
180+
}
181+
}
182+
183+
dependencies {
184+
implementation fileTree(dir: "libs", include: ["*.jar"])
185+
//noinspection GradleDynamicVersion
186+
implementation "com.facebook.react:react-native:+" // From node_modules
187+
188+
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
189+
190+
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
191+
exclude group:'com.facebook.fbjni'
192+
}
193+
194+
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
195+
exclude group:'com.facebook.flipper'
196+
exclude group:'com.squareup.okhttp3', module:'okhttp'
197+
}
198+
199+
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
200+
exclude group:'com.facebook.flipper'
201+
}
202+
203+
if (enableHermes) {
204+
def hermesPath = "../../node_modules/hermes-engine/android/";
205+
debugImplementation files(hermesPath + "hermes-debug.aar")
206+
releaseImplementation files(hermesPath + "hermes-release.aar")
207+
} else {
208+
implementation jscFlavor
209+
}
210+
}
211+
212+
// Run this once to be able to run the application with BUCK
213+
// puts all compile dependencies into folder libs for BUCK to use
214+
task copyDownloadableDepsToLibs(type: Copy) {
215+
from configurations.compile
216+
into 'libs'
217+
}
218+
219+
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
2.2 KB
Binary file not shown.

examples/android/gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919

2020
android.useAndroidX=true
2121
android.enableJetifier=true
22+
23+
# Version of flipper SDK to use with React Native
24+
FLIPPER_VERSION=0.54.0

examples/src/FingerprintPopup.component.android.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class BiometricPopup extends Component {
3232
}
3333

3434
componentDidMount() {
35-
if (requiresLegacyAuthentication()) {
36-
authLegacy();
35+
if (this.requiresLegacyAuthentication()) {
36+
this.authLegacy();
3737
} else {
38-
authCurrent();
38+
this.authCurrent();
3939
}
4040
}
4141

@@ -51,7 +51,10 @@ class BiometricPopup extends Component {
5151
FingerprintScanner
5252
.authenticate({ description: this.props.description || 'Log in with Biometrics' })
5353
.then(() => {
54-
this.props.onAuthenticate();
54+
Alert.alert('Fingerprint Authentication', 'Authenticated successfully');
55+
})
56+
.catch((error) => {
57+
Alert.alert('Fingerprint Authentication', error.message);
5558
});
5659
}
5760

@@ -122,7 +125,6 @@ class BiometricPopup extends Component {
122125

123126
BiometricPopup.propTypes = {
124127
description: PropTypes.string,
125-
onAuthenticate: PropTypes.func.isRequired,
126128
handlePopupDismissedLegacy: PropTypes.func,
127129
style: ViewPropTypes.style,
128130
};

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)