|
|
|
|
11
|
|
11
|
|
12
|
var package = fs.readFileSync(PACKAGE_JSON);
|
12
|
var package = fs.readFileSync(PACKAGE_JSON);
|
13
|
var APP_NAME = package.name;
|
13
|
var APP_NAME = package.name;
|
14
|
-var VERSION = parseFloat(/\d\.\d+(?=\.)/.exec(package.dependencies['react-native']));
|
|
|
15
|
var APPLICATION_MAIN = process.cwd() + '/android/app/src/main/java/com/' + APP_NAME.toLocaleLowerCase() + '/MainApplication.java';
|
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
|
var main = fs.readFileSync(APPLICATION_MAIN);
|
25
|
var main = fs.readFileSync(APPLICATION_MAIN);
|
20
|
main = main.replace('new MainReactPackage()', 'new RNFetchBlobPackage(),\n new MainReactPackage()');
|
26
|
main = main.replace('new MainReactPackage()', 'new RNFetchBlobPackage(),\n new MainReactPackage()');
|
21
|
fs.writeFileSync(APPLICATION_MAIN, main);
|
27
|
fs.writeFileSync(APPLICATION_MAIN, main);
|
|
|
28
|
+ console.log('RNFetchBlob patching MainApplication.java .. ok')
|
22
|
|
29
|
|
23
|
}
|
30
|
}
|
24
|
|
31
|
|
|
|
|
|
28
|
if(err)
|
35
|
if(err)
|
29
|
console.log('failed to locate AndroidManifest.xml file, you may have to add file access permission manually.');
|
36
|
console.log('failed to locate AndroidManifest.xml file, you may have to add file access permission manually.');
|
30
|
else {
|
37
|
else {
|
|
|
38
|
+
|
|
|
39
|
+ console.log('RNFetchBlob patching AndroidManifest.xml .. ');
|
31
|
// append fs permission
|
40
|
// append fs permission
|
32
|
data = String(data).replace(
|
41
|
data = String(data).replace(
|
33
|
'<uses-permission android:name="android.permission.INTERNET" />',
|
42
|
'<uses-permission android:name="android.permission.INTERNET" />',
|
|
|
|
|
39
|
'<category android:name="android.intent.category.LAUNCHER" />\n <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>'
|
48
|
'<category android:name="android.intent.category.LAUNCHER" />\n <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>'
|
40
|
)
|
49
|
)
|
41
|
fs.writeFileSync(MANIFEST_PATH, data);
|
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
|
+}
|