Skip to content

Commit 121078d

Browse files
committed
WIP React Native 0.62 supports in Android, restructured package.json
1 parent 60d4782 commit 121078d

File tree

11 files changed

+201
-54
lines changed

11 files changed

+201
-54
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,8 @@ buck-out/
4949

5050
my-release-key.keystore
5151
StaticServerExample/my-release-key.keystore
52+
53+
# Android
54+
.project
55+
.settings/
56+
android/.project

StaticServerExample/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ buck-out/
5656
*.jsbundle
5757

5858
# CocoaPods
59-
/ios/Pods/
59+
/ios/Pods/

StaticServerExample/App.js

+29-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ import {
1414
NativeModules
1515
} from 'react-native';
1616

17+
// requires react-native-webview, see: https://github.com/uuidjs/uuid#getrandomvalues-not-supported
18+
import 'react-native-get-random-values';
19+
import { v4 as uuidv4 } from 'uuid';
1720
import StaticServer from 'react-native-static-server';
1821
import RNFetchBlob from "rn-fetch-blob";
1922
import { WebView } from 'react-native-webview';
2023

2124
type Props = {};
2225
export default class App extends Component<Props> {
23-
26+
2427
constructor(opts) {
2528
super();
2629

@@ -29,7 +32,7 @@ export default class App extends Component<Props> {
2932
}
3033
}
3134

32-
componentWillMount() {
35+
async componentWillMount() {
3336
this.port = this.props.port || 3030;
3437
this.root = this.props.root || "www/";
3538
this.file = this.props.file || 'index.html';
@@ -42,14 +45,17 @@ export default class App extends Component<Props> {
4245
let dest = path + this.file;
4346

4447
// Add the directory
45-
RNFetchBlob.fs.mkdir(path, { NSURLIsExcludedFromBackupKey: true });
46-
48+
try {
49+
await RNFetchBlob.fs.mkdir(path, { NSURLIsExcludedFromBackupKey: true });
50+
} catch (e) {
51+
console.log(`directory is created ${path}`)
52+
}
4753
// Fetch the file
4854
let added;
4955

5056
if (uri.indexOf("file://") > -1) {
5157
// Copy file in release
52-
added = RNFetchBlob.fs.exists(dest).then((e) => {
58+
added = RNFetchBlob.fs.exists(dest).then((e) => {
5359
if (!e) {
5460
return RNFetchBlob.fs.cp(uri, dest);
5561
}
@@ -66,7 +72,6 @@ export default class App extends Component<Props> {
6672
})
6773
}
6874

69-
7075
added.then(() => {
7176
// Create a StaticServer at port 3030
7277
this.server = new StaticServer(this.port, this.root, {localOnly: true});
@@ -75,7 +80,24 @@ export default class App extends Component<Props> {
7580
this.setState({origin});
7681
});
7782
}).catch((err) => {
78-
console.error(err);
83+
console.log(err);
84+
RNFetchBlob.fs.exists(dest).then((e) => {
85+
if (e) {
86+
console.log('start')
87+
this.server = new StaticServer(this.port, this.root, {localOnly: true});
88+
89+
this.server.start().then((origin) => {
90+
console.log(origin)
91+
this.setState({origin});
92+
}).catch((e) => {
93+
console.log(e);
94+
});
95+
} else {
96+
console.error("File doesn't exist")
97+
}
98+
}).catch((e) => {
99+
console.log(e)
100+
})
79101
})
80102

81103
}
2.2 KB
Binary file not shown.

StaticServerExample/ios/Podfile.lock

+7-1
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ PODS:
236236
- React-cxxreact (= 0.62.2)
237237
- React-jsi (= 0.62.2)
238238
- React-jsinspector (0.62.2)
239+
- react-native-get-random-values (1.3.1):
240+
- React
239241
- react-native-static-server (0.4.2):
240242
- GCDWebServer
241243
- React
@@ -342,6 +344,7 @@ DEPENDENCIES:
342344
- React-jsi (from `../node_modules/react-native/ReactCommon/jsi`)
343345
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
344346
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
347+
- react-native-get-random-values (from `../node_modules/react-native-get-random-values`)
345348
- react-native-static-server (from `../..`)
346349
- react-native-webview (from `../node_modules/react-native-webview`)
347350
- React-RCTActionSheet (from `../node_modules/react-native/Libraries/ActionSheetIOS`)
@@ -403,6 +406,8 @@ EXTERNAL SOURCES:
403406
:path: "../node_modules/react-native/ReactCommon/jsiexecutor"
404407
React-jsinspector:
405408
:path: "../node_modules/react-native/ReactCommon/jsinspector"
409+
react-native-get-random-values:
410+
:path: "../node_modules/react-native-get-random-values"
406411
react-native-static-server:
407412
:path: "../.."
408413
react-native-webview:
@@ -459,7 +464,8 @@ SPEC CHECKSUMS:
459464
React-jsi: b6dc94a6a12ff98e8877287a0b7620d365201161
460465
React-jsiexecutor: 1540d1c01bb493ae3124ed83351b1b6a155db7da
461466
React-jsinspector: 512e560d0e985d0e8c479a54a4e5c147a9c83493
462-
react-native-static-server: cb7cf53a76cc6edf7319a4dc0b3ac0f43080eb3a
467+
react-native-get-random-values: 148a42f97f2ce180a52d219144e83c278d4fe24b
468+
react-native-static-server: bfd0c56efa27d951f6ec5c2b74759e2d8155538e
463469
react-native-webview: 9fb615251c147d1b94157b31fa0ea9c68b234c04
464470
React-RCTActionSheet: f41ea8a811aac770e0cc6e0ad6b270c644ea8b7c
465471
React-RCTAnimation: 49ab98b1c1ff4445148b72a3d61554138565bad0

StaticServerExample/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dependencies": {
1313
"react": "16.11.0",
1414
"react-native": "0.62.2",
15+
"react-native-get-random-values": "^1.3.1",
1516
"react-native-static-server": "link:../",
1617
"react-native-webview": "^9.2.1",
1718
"rn-fetch-blob": "^0.12.0"

StaticServerExample/yarn.lock

+12
Original file line numberDiff line numberDiff line change
@@ -2745,6 +2745,11 @@ fancy-log@^1.3.2:
27452745
parse-node-version "^1.0.0"
27462746
time-stamp "^1.0.0"
27472747

2748+
fast-base64-decode@^1.0.0:
2749+
version "1.0.0"
2750+
resolved "https://registry.yarnpkg.com/fast-base64-decode/-/fast-base64-decode-1.0.0.tgz#b434a0dd7d92b12b43f26819300d2dafb83ee418"
2751+
integrity sha512-qwaScUgUGBYeDNRnbc/KyllVU88Jk1pRHPStuF/lO7B0/RTRLj7U0lkdTAutlBblY08rwZDff6tNU9cjv6j//Q==
2752+
27482753
fast-deep-equal@^2.0.1:
27492754
version "2.0.1"
27502755
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
@@ -5335,6 +5340,13 @@ react-is@^16.8.1, react-is@^16.8.4:
53355340
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16"
53365341
integrity sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA==
53375342

5343+
react-native-get-random-values@^1.3.1:
5344+
version "1.3.1"
5345+
resolved "https://registry.yarnpkg.com/react-native-get-random-values/-/react-native-get-random-values-1.3.1.tgz#f5e0dce92ed0ba3aad7a41df7bca712ccd840e46"
5346+
integrity sha512-+oli7JzmIGR75KZM2phjFUCBJwv7YEXuGRBq2M1pMqgQOqEUdZRK7qxC8w2luEANPAQ5plykOZiKwN7Aay9HZA==
5347+
dependencies:
5348+
fast-base64-decode "^1.0.0"
5349+
53385350
"react-native-static-server@link:..":
53395351
version "0.0.0"
53405352
uid ""

android/build.gradle

+129-32
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,151 @@
1-
buildscript {
2-
repositories {
3-
jcenter()
4-
}
1+
// android/build.gradle
52

6-
dependencies {
7-
// Matches the RN Hello World template
8-
// https://github.com/facebook/react-native/blob/1e8f3b11027fe0a7514b4fc97d0798d3c64bc895/local-cli/templates/HelloWorld/android/build.gradle#L8
9-
classpath 'com.android.tools.build:gradle:2.2.3'
10-
}
3+
// based on:
4+
//
5+
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle
6+
// original location:
7+
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle
8+
//
9+
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle
10+
// original location:
11+
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle
12+
13+
def DEFAULT_COMPILE_SDK_VERSION = 28
14+
def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3'
15+
def DEFAULT_MIN_SDK_VERSION = 16
16+
def DEFAULT_TARGET_SDK_VERSION = 28
17+
18+
def safeExtGet(prop, fallback) {
19+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
1120
}
1221

1322
apply plugin: 'com.android.library'
1423
apply plugin: 'maven'
1524

16-
def safeExtGet(prop, fallback) {
17-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
25+
buildscript {
26+
// The Android Gradle plugin is only required when opening the android folder stand-alone.
27+
// This avoids unnecessary downloads and potential conflicts when the library is included as a
28+
// module dependency in an application project.
29+
// ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies
30+
if (project == rootProject) {
31+
repositories {
32+
google()
33+
jcenter()
34+
}
35+
dependencies {
36+
classpath 'com.android.tools.build:gradle:3.4.1'
37+
}
38+
}
1839
}
1940

20-
def DEFAULT_COMPILE_SDK_VERSION = 27
21-
def DEFAULT_BUILD_TOOLS_VERSION = "27.0.3"
22-
def DEFAULT_MIN_SDK_VERSION = 16
23-
def DEFAULT_TARGET_SDK_VERSION = 27
41+
apply plugin: 'com.android.library'
42+
apply plugin: 'maven'
2443

2544
android {
26-
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
27-
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
28-
29-
defaultConfig {
30-
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
31-
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
32-
versionCode 1
33-
versionName "1.0"
34-
}
35-
lintOptions {
36-
abortOnError false
37-
}
45+
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
46+
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
47+
defaultConfig {
48+
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
49+
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
50+
versionCode 1
51+
versionName "1.0"
52+
}
53+
lintOptions {
54+
abortOnError false
55+
}
3856
}
3957

4058
repositories {
59+
// ref: https://www.baeldung.com/maven-local-repository
60+
mavenLocal()
4161
maven {
4262
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
43-
// Matches the RN Hello World template
44-
// https://github.com/facebook/react-native/blob/1e8f3b11027fe0a7514b4fc97d0798d3c64bc895/local-cli/templates/HelloWorld/android/build.gradle#L21
45-
url "$projectDir/../node_modules/react-native/android"
63+
url "$rootDir/../node_modules/react-native/android"
4664
}
47-
mavenCentral()
65+
maven {
66+
// Android JSC is installed from npm
67+
url "$rootDir/../node_modules/jsc-android/dist"
68+
}
69+
google()
70+
jcenter()
4871
}
4972

5073
dependencies {
51-
implementation 'com.facebook.react:react-native:+'
74+
//noinspection GradleDynamicVersion
75+
implementation 'com.facebook.react:react-native:+' // From node_modules
5276
implementation 'org.nanohttpd:nanohttpd:2.3.1'
5377
implementation 'org.nanohttpd:nanohttpd-webserver:2.3.1'
5478
}
79+
80+
def configureReactNativePom(def pom) {
81+
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)
82+
83+
pom.project {
84+
name packageJson.title
85+
artifactId packageJson.name
86+
version = packageJson.version
87+
group = "com.futurepress.staticserver"
88+
description packageJson.description
89+
url packageJson.repository.baseUrl
90+
91+
licenses {
92+
license {
93+
name packageJson.license
94+
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
95+
distribution 'repo'
96+
}
97+
}
98+
99+
developers {
100+
developer {
101+
id packageJson.author.username
102+
name packageJson.author.name
103+
}
104+
}
105+
}
106+
}
107+
108+
afterEvaluate { project ->
109+
// some Gradle build hooks ref:
110+
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
111+
task androidJavadoc(type: Javadoc) {
112+
source = android.sourceSets.main.java.srcDirs
113+
classpath += files(android.bootClasspath)
114+
classpath += files(project.getConfigurations().getByName('compile').asList())
115+
include '**/*.java'
116+
}
117+
118+
task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
119+
classifier = 'javadoc'
120+
from androidJavadoc.destinationDir
121+
}
122+
123+
task androidSourcesJar(type: Jar) {
124+
classifier = 'sources'
125+
from android.sourceSets.main.java.srcDirs
126+
include '**/*.java'
127+
}
128+
129+
android.libraryVariants.all { variant ->
130+
def name = variant.name.capitalize()
131+
def javaCompileTask = variant.javaCompileProvider.get()
132+
133+
task "jar${name}"(type: Jar, dependsOn: javaCompileTask) {
134+
from javaCompileTask.destinationDir
135+
}
136+
}
137+
138+
artifacts {
139+
archives androidSourcesJar
140+
archives androidJavadocJar
141+
}
142+
143+
task installArchives(type: Upload) {
144+
configuration = configurations.archives
145+
repositories.mavenDeployer {
146+
// Deploy to react-native-event-bridge/maven, ready to publish to npm
147+
repository url: "file://${projectDir}/../android/maven"
148+
configureReactNativePom pom
149+
}
150+
}
151+
}

android/src/main/java/com/futurepress/staticserver/FPStaticServerPackage.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11

22
package com.futurepress.staticserver;
33

4-
import java.util.*;
4+
import java.util.Arrays;
5+
import java.util.Collections;
6+
import java.util.List;
57

68
import com.facebook.react.ReactPackage;
79
import com.facebook.react.bridge.NativeModule;
810
import com.facebook.react.bridge.ReactApplicationContext;
911
import com.facebook.react.uimanager.ViewManager;
1012
import com.facebook.react.bridge.JavaScriptModule;
1113
public class FPStaticServerPackage implements ReactPackage {
12-
14+
@Override
1315
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
14-
List<NativeModule> modules = new ArrayList<>();
15-
modules.add(new FPStaticServerModule(reactContext));
16-
return modules;
17-
}
18-
19-
// Deprecated RN 0.47
20-
public List<Class<? extends JavaScriptModule>> createJSModules() {
21-
return Collections.emptyList();
16+
return Arrays.<NativeModule>asList(new FPStaticServerModule(reactContext));
2217
}
2318

2419
@Override

0 commit comments

Comments
 (0)