-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FIX-RN-productFlavors.js
70 lines (59 loc) · 2.08 KB
/
FIX-RN-productFlavors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* @author 9christian9
* @description This script file must be in the react native root project
* <br> This script work only with RN 0.67.x and Android Gradle Plugin 7.2 - 7.3
*/
const {readFile, writeFile} = require('fs');
const reactNative = "./node_modules/react-native/react.gradle";
const workaround = `
def currentAssetsCopyTask = tasks.create(
name: "copy\${targetName}BundledJs",
type: Copy) {
group = "react"
description = "copy bundled JS into \${targetName}."
from(jsBundleDir)
if (config."jsBundleDir\${targetName}") {
into(file(config."jsBundleDir\${targetName}"))
} else {
into ("$buildDir/intermediates")
if (isAndroidLibrary) {
into ("library_assets/$\{variant.name}/out")
} else {
into ("assets/\${targetPath}")
// Workaround for Android Gradle Plugin 3.2+ new asset directory
into ("merged_assets/\${variant.name}/merge\${targetName}Assets/out")
// Workaround for Android Gradle Plugin 3.4+ new asset directory
into ("merged_assets/\${variant.name}/out")
// Workaround for Android Gradle Plugin 7.2 - 7.3 and React-Native 0.67.x - Assets directory by christian
into("$buildDir/intermediates/assets/\${variant.name}")
}
}
dependsOn(variant.mergeAssetsProvider.get())
enabled(currentBundleTask.enabled)
dependsOn(currentBundleTask)
}
`;
readFile(reactNative, 'utf-8', function (err, contents) {
if (err) {
console.log(err);
return;
}
if(!contents.includes(workaround)){
contents = contents.split("\n");
contents.splice(288, 38);
contents[288] = [workaround];
contents = contents.join("\n");
writeFile(reactNative, contents, 'utf-8', function (err) {
if (err) {
console.log(err);
return;
}else{
console.log('File react.gradle changed correctly');
return;
}
});
}else{
console.log('Fix already present');
return;
}
});