-
Notifications
You must be signed in to change notification settings - Fork 91
/
withProguardGradle.ts
41 lines (37 loc) · 1.55 KB
/
withProguardGradle.ts
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
import { ConfigPlugin, withAppBuildGradle } from "expo/config-plugins";
/**
* [Step 7](https://github.com/wix/Detox/blob/master/docs/Introduction.Android.md#7-proguard-minification-obfuscation). Add Proguard (Minification, Obfuscation) to the app/build.gradle.
*
* 1. Add `androidTestImplementation` to the app/build.gradle
* 2. Add `testInstrumentationRunner` to the app/build.gradle
* @param config
*/
const withProguardGradle: ConfigPlugin = (config) => {
return withAppBuildGradle(config, (config) => {
if (config.modResults.language === "groovy") {
config.modResults.contents = addDetoxProguardRules(
config.modResults.contents,
);
} else {
throw new Error(
"Cannot add Detox maven gradle because the project build.gradle is not groovy",
);
}
return config;
});
};
export function addDetoxProguardRules(buildGradle: string): string {
const pattern = /detox\/proguard-rules-app\.pro/g;
if (buildGradle.match(pattern)) {
return buildGradle;
}
return buildGradle.replace(
/proguardFiles getDefaultProguardFile\("proguard-android.txt"\),\s?"proguard-rules.pro"/,
`proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
// Detox-specific additions to pro-guard
def detoxProguardRulesPath = new File(["node", "--print", "require.resolve('detox/package.json')"].execute(null, rootDir).text.trim(), "../android/detox/proguard-rules-app.pro")
proguardFile(detoxProguardRulesPath)
`,
);
}
export default withProguardGradle;