@@ -112,19 +112,30 @@ class RNAndroid extends Platform.Android implements RNPlatform {
112112 return TestUtil . getProcessOutput ( "adb install -r " + this . getBinaryPath ( projectDirectory ) , { cwd : androidDirectory } ) . then ( ( ) => { return null ; } ) ;
113113 }
114114
115+ /**
116+ * Build function of the test application, the command depends on the OS
117+ */
118+ buildFunction ( androidDirectory : string ) : Q . Promise < void > {
119+ if ( process . platform === "darwin" ) {
120+ return TestUtil . getProcessOutput ( `./gradlew assembleRelease --daemon` , { noLogStdOut : true , cwd : androidDirectory } )
121+ . then ( ( ) => { return null ; } ) ;
122+ } else {
123+ return TestUtil . getProcessOutput ( `gradlew assembleRelease --daemon` , { noLogStdOut : true , cwd : androidDirectory } )
124+ . then ( ( ) => { return null ; } ) ;
125+ }
126+ }
127+
115128 /**
116129 * Builds the binary of the project on this platform.
117130 */
118131 buildApp ( projectDirectory : string ) : Q . Promise < void > {
119132 // In order to run on Android without the package manager, we must create a release APK and then sign it with the debug certificate.
120133 const androidDirectory : string = path . join ( projectDirectory , TestConfig . TestAppName , "android" ) ;
121- const apkPath = this . getBinaryPath ( projectDirectory ) ;
122- if ( process . platform === "darwin" ) {
123- return TestUtil . getProcessOutput ( `./gradlew assembleRelease --daemon` , { cwd : androidDirectory } )
124- . then ( ( ) => { return null ; } ) ;
125- } else {
126- return TestUtil . getProcessOutput ( `gradlew assembleRelease --daemon` , { cwd : androidDirectory } )
127- . then ( ( ) => { return null ; } ) ;
134+ // If the build fails for the first time, try rebuild app again
135+ try {
136+ return this . buildFunction ( androidDirectory ) ;
137+ } catch {
138+ return this . buildFunction ( androidDirectory ) ;
128139 }
129140 }
130141}
0 commit comments