-
Notifications
You must be signed in to change notification settings - Fork 0
/
postinstall.py
70 lines (56 loc) · 2.06 KB
/
postinstall.py
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
#!/usr/bin/env python3
import os
import textwrap
def file_dir():
return os.path.dirname(os.path.realpath(__file__))
def read_file(filename):
'''
Reads the specified file.
:param filename: The file to read
:return: The content of the specified file
'''
if os.path.exists(filename):
with open(filename, "r") as file:
return file.read()
else:
raise IOError("file {} not found.".format(filename))
def write_file(filename, text):
'''
Writes the specified text to the specified file.
:param filename: The file to write to
:param text: The text to write
'''
with open(filename, "w") as file:
file.write(text)
def fix_android_assets():
print("Fixing android error with duplicate assets: https://github.com/facebook/react-native/issues/22234")
gradle_file_path = "{}/node_modules/react-native/react.gradle".format(file_dir())
code_snippet = textwrap.indent("""\
// Added by post_install
// Fix for: https://github.com/facebook/react-native/issues/22234
doLast {
def moveFunc = { resSuffix ->
File originalDir = file("$buildDir/generated/res/react/release/drawable-${resSuffix}");
if (originalDir.exists()) {
File destDir = file("$buildDir/../src/main/res/drawable-${resSuffix}");
ant.move(file: originalDir, tofile: destDir);
}
}
moveFunc.curry("ldpi").call()
moveFunc.curry("mdpi").call()
moveFunc.curry("hdpi").call()
moveFunc.curry("xhdpi").call()
moveFunc.curry("xxhdpi").call()
moveFunc.curry("xxxhdpi").call()
}
""", "")
text = read_file(gradle_file_path)
start = text.find("doFirst", 0)
end = text.find("}", start)
end = text.find("\n", end) + 1
text = text[:end] + code_snippet + text[end:]
write_file(gradle_file_path, text)
def main():
fix_android_assets()
if __name__ == "__main__":
main()