1
- const {
2
- withAppBuildGradle,
3
- } = require ( "@expo/config-plugins/build/plugins/android-plugins.js" ) ;
1
+ // withAddLinkOption.js
2
+ const { withDangerousMod } = require ( '@expo/config-plugins' ) ;
3
+ const fs = require ( 'fs' ) ;
4
+ const path = require ( 'path' ) ;
4
5
5
- const withNDKBuildId = ( config ) => {
6
- return withAppBuildGradle ( config , ( gradleConfig ) => {
7
- if ( typeof gradleConfig . modResults . contents === "string" ) {
8
- gradleConfig . modResults . contents =
9
- gradleConfig . modResults . contents . replace (
10
- "defaultConfig {" ,
11
- `defaultConfig {
12
- externalNativeBuild {
13
- cmake {
14
- path "CMakeLists.txt"
15
- }
16
- }
17
- ` ,
6
+ const withAddLinkOption = ( config ) => {
7
+ return withDangerousMod ( config , [
8
+ 'android' ,
9
+ async ( config ) => {
10
+ const packages = [ 'react-native-screens' , 'expo-modules-core' ] ;
11
+ for ( const pkg of packages ) {
12
+ const cmakeFilePath = path . join (
13
+ config . modRequest . projectRoot ,
14
+ 'node_modules' ,
15
+ pkg ,
16
+ 'android' ,
17
+ 'CMakeLists.txt'
18
18
) ;
19
- }
20
- return gradleConfig ;
21
- } ) ;
19
+ if ( fs . existsSync ( cmakeFilePath ) ) {
20
+ let contents = fs . readFileSync ( cmakeFilePath , 'utf8' ) ;
21
+ // Insert the linker option after the first line if not already present.
22
+ if ( ! contents . includes ( 'LINKER:--build-id=none' ) ) {
23
+ const lines = contents . split ( '\n' ) ;
24
+ lines . splice ( 1 , 0 , 'add_link_options("LINKER:--build-id=none")' ) ;
25
+ contents = lines . join ( '\n' ) ;
26
+ fs . writeFileSync ( cmakeFilePath , contents , 'utf8' ) ;
27
+ }
28
+ }
29
+ }
30
+ return config ;
31
+ } ,
32
+ ] ) ;
22
33
} ;
23
34
24
- module . exports = withNDKBuildId ;
35
+ module . exports = withAddLinkOption ;
0 commit comments