|
@@ -11,14 +11,21 @@ if (!hasNecessaryFile) {
|
11
|
11
|
|
12
|
12
|
var package = fs.readFileSync(PACKAGE_JSON);
|
13
|
13
|
var APP_NAME = package.name;
|
14
|
|
-var VERSION = parseFloat(/\d\.\d+(?=\.)/.exec(package.dependencies['react-native']));
|
15
|
14
|
var APPLICATION_MAIN = process.cwd() + '/android/app/src/main/java/com/' + APP_NAME.toLocaleLowerCase() + '/MainApplication.java';
|
16
|
15
|
|
17
|
|
-if(VERSION >= 0.29) {
|
|
16
|
+if(!fs.existsSync('APPLICATION_MAIN')) {
|
|
17
|
+ throw 'RNFetchBlob could not found link Android automatically, MainApplication.java not found in path : ' + APPLICATION_MAIN
|
|
18
|
+}
|
18
|
19
|
|
|
20
|
+var VERSION = checkVersion();
|
|
21
|
+console.log('RNFetchBlob detected app version .. ' + VERSION);
|
|
22
|
+
|
|
23
|
+if(VERSION >= 0.29) {
|
|
24
|
+ console.log('RNFetchBlob patching MainApplication.java .. ');
|
19
|
25
|
var main = fs.readFileSync(APPLICATION_MAIN);
|
20
|
26
|
main = main.replace('new MainReactPackage()', 'new RNFetchBlobPackage(),\n new MainReactPackage()');
|
21
|
27
|
fs.writeFileSync(APPLICATION_MAIN, main);
|
|
28
|
+ console.log('RNFetchBlob patching MainApplication.java .. ok')
|
22
|
29
|
|
23
|
30
|
}
|
24
|
31
|
|
|
@@ -28,6 +35,8 @@ fs.readFile(MANIFEST_PATH, function(err, data) {
|
28
|
35
|
if(err)
|
29
|
36
|
console.log('failed to locate AndroidManifest.xml file, you may have to add file access permission manually.');
|
30
|
37
|
else {
|
|
38
|
+
|
|
39
|
+ console.log('RNFetchBlob patching AndroidManifest.xml .. ');
|
31
|
40
|
// append fs permission
|
32
|
41
|
data = String(data).replace(
|
33
|
42
|
'<uses-permission android:name="android.permission.INTERNET" />',
|
|
@@ -39,7 +48,13 @@ fs.readFile(MANIFEST_PATH, function(err, data) {
|
39
|
48
|
'<category android:name="android.intent.category.LAUNCHER" />\n <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>'
|
40
|
49
|
)
|
41
|
50
|
fs.writeFileSync(MANIFEST_PATH, data);
|
|
51
|
+ console.log('RNFetchBlob patching AndroidManifest.xml .. ok');
|
42
|
52
|
|
43
|
53
|
}
|
44
|
54
|
|
45
|
55
|
})
|
|
56
|
+
|
|
57
|
+function checkVersion() {
|
|
58
|
+ console.log('RNFetchBlob checking app version ..');
|
|
59
|
+ return parseFloat(/\d\.\d+(?=\.)/.exec(package.dependencies['react-native']));
|
|
60
|
+}
|