Skip to content

Commit 92367ce

Browse files
authored
Merge pull request #64 from talsec/fix-expo-r8
Fix expo r8
2 parents c8c03b1 + 88ea5f2 commit 92367ce

File tree

11 files changed

+174
-12
lines changed

11 files changed

+174
-12
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jsconfig.json
1111

1212
# Xcode
1313
#
14-
build/
14+
**/ios/**/build/
1515
*.pbxuser
1616
!default.pbxuser
1717
*.mode1v3
@@ -39,6 +39,7 @@ project.xcworkspace
3939
.settings
4040
local.properties
4141
android.iml
42+
**/android/**/build
4243

4344
# Cocoapods
4445
#

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jsconfig.json
1818

1919
# Xcode
2020
#
21-
build/
21+
**/ios/**/build/
2222
*.pbxuser
2323
!default.pbxuser
2424
*.mode1v3
@@ -46,6 +46,7 @@ project.xcworkspace
4646
.settings
4747
local.properties
4848
android.iml
49+
**/android/**/build
4950

5051
# Cocoapods
5152
#

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# freeRASP 3.7.2
2+
3+
- ⚡ Update expo config plugin to fix release build issue in RN 0.73
4+
15
# freeRASP 3.7.1
26

37
### Android

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,16 @@ If you encounter any other issues, you can see the list of solved issues [here](
324324
freeRASP for React Native is bare React Native plugin. When installing freeRASP into a project that uses Expo SDK, there may be extra configuration needed. We provide plugin config that sets the dependencies automatically. It is recommended to use the plugin config. However, manual setup is also possible.
325325

326326
## Plugin config setup
327-
Add the plugin config into your `app.json` and specify the `minSdkVersion` (use at least 23):
327+
Add the plugin config into your `app.json` and specify the `minSdkVersion` (use at least 23).
328+
Additionally, if you are using Expo 50, increase version of R8 above 8.2 with the `R8Version` property [(to support sealed classes on Android)](https://github.com/talsec/Free-RASP-ReactNative/issues/60).
328329
```json
329330
"plugins": [
330331
[
331332
"freerasp-react-native/app.plugin.js",
332333
{
333334
"android": {
334-
"minSdkVersion": "23"
335+
"minSdkVersion": "23",
336+
"R8Version": "8.3.37" // optional for Expo 50
335337
}
336338
}
337339
]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "freerasp-react-native",
3-
"version": "3.7.1",
3+
"version": "3.7.2",
44
"description": "React Native plugin for improving app security and threat monitoring on Android and iOS mobile devices.",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

plugin/build/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { ConfigPlugin } from '@expo/config-plugins';
2+
import { type PluginConfigType } from './pluginConfig';
3+
declare const _default: ConfigPlugin<PluginConfigType>;
4+
export default _default;

plugin/build/index.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
const config_plugins_1 = require("@expo/config-plugins");
4+
const { createBuildGradlePropsConfigPlugin } = config_plugins_1.AndroidConfig.BuildProperties;
5+
const urlFreerasp = 'https://europe-west3-maven.pkg.dev/talsec-artifact-repository/freerasp';
6+
const urlJitpack = 'https://www.jitpack.io';
7+
const setBuildscriptDependency = (buildGradle) => {
8+
// This enables users in bare workflow to comment out the line to prevent freerasp from adding it back.
9+
const mavenFreerasp = buildGradle.includes(urlFreerasp)
10+
? ''
11+
: `maven { url "${urlFreerasp}" }`;
12+
const mavenJitpack = buildGradle.includes(urlJitpack)
13+
? ''
14+
: `maven { url "${urlJitpack}" }`;
15+
// It's ok to have multiple allprojects.repositories, so we create a new one since it's cheaper than tokenizing
16+
// the existing block to find the correct place to insert our dependency.
17+
const combinedGradleMaven = `
18+
allprojects {
19+
repositories {
20+
${mavenFreerasp}
21+
${mavenJitpack}
22+
}
23+
}
24+
`;
25+
return buildGradle + `\n${combinedGradleMaven}\n`;
26+
};
27+
const setAndroidR8 = (buildGradle, version) => {
28+
const combinedGradleMaven = `
29+
buildscript {
30+
dependencies {
31+
classpath("com.android.tools:r8:${version}")
32+
}
33+
}
34+
`;
35+
return buildGradle + `\n${combinedGradleMaven}\n`;
36+
};
37+
/**
38+
* Update `<project>/build.gradle` by adding nexus dependency to buildscript
39+
*/
40+
const withBuildscriptDependency = (expoConfig) => {
41+
return (0, config_plugins_1.withProjectBuildGradle)(expoConfig, (config) => {
42+
if (config.modResults.language === 'groovy') {
43+
config.modResults.contents = setBuildscriptDependency(config.modResults.contents);
44+
}
45+
else {
46+
config_plugins_1.WarningAggregator.addWarningAndroid('freerasp-react-native', `Cannot automatically configure project build.gradle, because it's not groovy`);
47+
}
48+
return config;
49+
});
50+
};
51+
const withAndroidMinSdkVersion = createBuildGradlePropsConfigPlugin([
52+
{
53+
propName: 'android.minSdkVersion',
54+
propValueGetter: (config) => config.android?.minSdkVersion?.toString(),
55+
},
56+
], 'withAndroidMinSdkVersion');
57+
/**
58+
* Update `<project>/build.gradle` by updating the R8 version
59+
*/
60+
const withAndroidR8Version = (expoConfig, props) => {
61+
if (!props.android?.R8Version) {
62+
return expoConfig;
63+
}
64+
return (0, config_plugins_1.withProjectBuildGradle)(expoConfig, (config) => {
65+
if (config.modResults.language === 'groovy') {
66+
config.modResults.contents = setAndroidR8(config.modResults.contents, props.android?.R8Version ?? '+');
67+
}
68+
else {
69+
config_plugins_1.WarningAggregator.addWarningAndroid('freerasp-react-native', `Cannot automatically configure project build.gradle, because it's not groovy`);
70+
}
71+
return config;
72+
});
73+
};
74+
const withRnTalsecApp = (config, props) => {
75+
config = withBuildscriptDependency(config);
76+
config = withAndroidMinSdkVersion(config, props);
77+
config = withAndroidR8Version(config, props);
78+
return config;
79+
};
80+
let pkg = {
81+
name: 'freerasp-react-native',
82+
};
83+
try {
84+
const freeraspPkg = require('freerasp-react-native/package.json');
85+
pkg = freeraspPkg;
86+
}
87+
catch { }
88+
exports.default = (0, config_plugins_1.createRunOncePlugin)(withRnTalsecApp, pkg.name, pkg.version);

plugin/build/pluginConfig.d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Interface representing base build properties configuration.
3+
*/
4+
export interface PluginConfigType {
5+
/**
6+
* Interface representing available configuration for Android native build properties.
7+
* @platform android
8+
*/
9+
android?: PluginConfigTypeAndroid;
10+
}
11+
/**
12+
* Interface representing available configuration for Android native build properties.
13+
* @platform android
14+
*/
15+
export interface PluginConfigTypeAndroid {
16+
/**
17+
* Override the default `minSdkVersion` version number in **build.gradle**.
18+
* */
19+
minSdkVersion?: number;
20+
R8Version?: string;
21+
}

plugin/build/pluginConfig.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });

plugin/src/index.ts

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ import {
55
createRunOncePlugin,
66
withProjectBuildGradle,
77
} from '@expo/config-plugins';
8-
9-
// @ts-ignore
10-
import { PluginConfigType } from './pluginConfig';
8+
import { type ExpoConfig } from '@expo/config-types';
9+
import { type PluginConfigType } from './pluginConfig';
1110

1211
const { createBuildGradlePropsConfigPlugin } = AndroidConfig.BuildProperties;
1312

1413
const urlFreerasp =
1514
'https://europe-west3-maven.pkg.dev/talsec-artifact-repository/freerasp';
1615
const urlJitpack = 'https://www.jitpack.io';
1716

18-
export const setBuildscriptDependency = (buildGradle: string) => {
17+
const setBuildscriptDependency = (buildGradle: string) => {
1918
// This enables users in bare workflow to comment out the line to prevent freerasp from adding it back.
2019

2120
const mavenFreerasp = buildGradle.includes(urlFreerasp)
@@ -39,11 +38,23 @@ export const setBuildscriptDependency = (buildGradle: string) => {
3938
return buildGradle + `\n${combinedGradleMaven}\n`;
4039
};
4140

41+
const setAndroidR8 = (buildGradle: string, version: string) => {
42+
const combinedGradleMaven = `
43+
buildscript {
44+
dependencies {
45+
classpath("com.android.tools:r8:${version}")
46+
}
47+
}
48+
`;
49+
50+
return buildGradle + `\n${combinedGradleMaven}\n`;
51+
};
52+
4253
/**
4354
* Update `<project>/build.gradle` by adding nexus dependency to buildscript
4455
*/
45-
export const withBuildscriptDependency: ConfigPlugin = (config) => {
46-
return withProjectBuildGradle(config, (config) => {
56+
const withBuildscriptDependency: ConfigPlugin = (expoConfig) => {
57+
return withProjectBuildGradle(expoConfig, (config) => {
4758
if (config.modResults.language === 'groovy') {
4859
config.modResults.contents = setBuildscriptDependency(
4960
config.modResults.contents
@@ -58,7 +69,7 @@ export const withBuildscriptDependency: ConfigPlugin = (config) => {
5869
});
5970
};
6071

61-
export const withAndroidMinSdkVersion =
72+
const withAndroidMinSdkVersion =
6273
createBuildGradlePropsConfigPlugin<PluginConfigType>(
6374
[
6475
{
@@ -69,9 +80,36 @@ export const withAndroidMinSdkVersion =
6980
'withAndroidMinSdkVersion'
7081
);
7182

83+
/**
84+
* Update `<project>/build.gradle` by updating the R8 version
85+
*/
86+
const withAndroidR8Version: ConfigPlugin<PluginConfigType> = (
87+
expoConfig: ExpoConfig,
88+
props: PluginConfigType
89+
) => {
90+
if (!props.android?.R8Version) {
91+
return expoConfig;
92+
}
93+
return withProjectBuildGradle(expoConfig, (config) => {
94+
if (config.modResults.language === 'groovy') {
95+
config.modResults.contents = setAndroidR8(
96+
config.modResults.contents,
97+
props.android?.R8Version ?? '+'
98+
);
99+
} else {
100+
WarningAggregator.addWarningAndroid(
101+
'freerasp-react-native',
102+
`Cannot automatically configure project build.gradle, because it's not groovy`
103+
);
104+
}
105+
return config;
106+
});
107+
};
108+
72109
const withRnTalsecApp: ConfigPlugin<PluginConfigType> = (config, props) => {
73110
config = withBuildscriptDependency(config);
74111
config = withAndroidMinSdkVersion(config, props);
112+
config = withAndroidR8Version(config, props);
75113
return config;
76114
};
77115

plugin/src/pluginConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ export interface PluginConfigTypeAndroid {
1818
* Override the default `minSdkVersion` version number in **build.gradle**.
1919
* */
2020
minSdkVersion?: number;
21+
R8Version?: string;
2122
}

0 commit comments

Comments
 (0)