@@ -12,6 +12,44 @@ import Q = require("q");
1212
1313import del = require( "del" ) ;
1414
15+ function ensureAndroidCleartextTraffic ( androidManifestPath : string ) : void {
16+ const androidManifestContents = fs . readFileSync ( androidManifestPath , "utf8" ) ;
17+
18+ if ( androidManifestContents . includes ( "android:usesCleartextTraffic=\"true\"" ) ) {
19+ return ;
20+ }
21+
22+ let nextContents = androidManifestContents ;
23+
24+ if ( androidManifestContents . includes ( "android:usesCleartextTraffic=\"false\"" ) ) {
25+ nextContents = androidManifestContents . replace ( "android:usesCleartextTraffic=\"false\"" , "android:usesCleartextTraffic=\"true\"" ) ;
26+ } else if ( / < a p p l i c a t i o n \b / . test ( androidManifestContents ) ) {
27+ nextContents = androidManifestContents . replace ( / < a p p l i c a t i o n \b / , "<application android:usesCleartextTraffic=\"true\"" ) ;
28+ } else {
29+ throw new Error ( `Could not find <application> tag in AndroidManifest.xml: ${ androidManifestPath } ` ) ;
30+ }
31+
32+ if ( nextContents !== androidManifestContents ) {
33+ fs . writeFileSync ( androidManifestPath , nextContents , "utf8" ) ;
34+ }
35+ }
36+
37+ function installExpoBundleTooling ( projectPath : string ) : Q . Promise < void > {
38+ const packageJsonPath = path . join ( projectPath , "package.json" ) ;
39+ const packageJsonContents = fs . readFileSync ( packageJsonPath , "utf8" ) ;
40+ const packageJson = JSON . parse ( packageJsonContents ) ;
41+ const reactNativeVersion = packageJson . dependencies && packageJson . dependencies [ "react-native" ] ;
42+
43+ if ( ! reactNativeVersion ) {
44+ throw new Error ( `Could not determine react-native version from ${ packageJsonPath } ` ) ;
45+ }
46+
47+ return TestUtil . getProcessOutput (
48+ `npm install --save-dev @react-native/metro-config@${ reactNativeVersion } ` ,
49+ { cwd : projectPath }
50+ ) . then ( ( ) => { return null ; } ) ;
51+ }
52+
1553//////////////////////////////////////////////////////////////////////////////////////////
1654// Create the platforms to run the tests on.
1755
@@ -86,7 +124,7 @@ class RNAndroid extends Platform.Android implements RNPlatform {
86124 // we use hard-coded deployment key and server url in app.json
87125 return Q . Promise < void > ( ( resolve , reject ) => {
88126 TestUtil . replaceString ( androidMainActivityPath , "\"main\"" , `"${ TestConfig . TestAppName } "` ) ;
89- TestUtil . replaceString ( AndroidManifest , "\\${usesCleartextTraffic}" , "true" ) ;
127+ ensureAndroidCleartextTraffic ( AndroidManifest ) ;
90128 resolve ( null ) ;
91129 } ) ;
92130 }
@@ -329,11 +367,17 @@ class RNProjectManager extends ProjectManager {
329367 mkdirp . sync ( projectDirectory ) ;
330368
331369 if ( TestConfig . isExpoApp ) {
332- return TestUtil . getProcessOutput ( `npx create-expo-app@latest ${ appName } --template blank` , { cwd : projectDirectory , timeout : 30 * 60 * 1000 } )
370+ return TestUtil . getProcessOutput ( `npx create-expo-app@latest ${ appName } --template blank@sdk-55 ` , { cwd : projectDirectory , timeout : 30 * 60 * 1000 } )
333371 . then ( ( e ) => { console . log ( `"npx expo init ${ appName } " success. cwd=${ projectDirectory } ` ) ; return e ; } )
334372 . then ( this . copyTemplate . bind ( this , templatePath , projectDirectory ) )
335373 . then < void > ( TestUtil . getProcessOutput . bind ( undefined , TestConfig . thisPluginInstallString , { cwd : path . join ( projectDirectory , TestConfig . TestAppName ) } ) )
374+ . then ( installExpoBundleTooling . bind ( undefined , path . join ( projectDirectory , TestConfig . TestAppName ) ) )
375+ . then < void > ( TestUtil . getProcessOutput . bind ( undefined , "npx expo install expo-build-properties" , { cwd : path . join ( projectDirectory , TestConfig . TestAppName ) } ) )
336376 . then ( TestUtil . getProcessOutput . bind ( undefined , `npx expo prebuild --clean` , { cwd : path . join ( projectDirectory , TestConfig . TestAppName ) } ) )
377+ . then ( ( ) => {
378+ ensureAndroidCleartextTraffic ( path . join ( projectDirectory , TestConfig . TestAppName , "android" , "app" , "src" , "main" , "AndroidManifest.xml" ) ) ;
379+ return null ;
380+ } )
337381 . then ( ( ) => { return null ; } ) ;
338382 } else {
339383 return TestUtil . getProcessOutput ( "npx @react-native-community/cli init " + appName + " --version 0.82.1 --install-pods" , { cwd : projectDirectory , timeout : 30 * 60 * 1000 } )
0 commit comments