1export default `// Build integration with EAS
2
3import java.nio.file.Paths
4
5android {
6  signingConfigs {
7    release {
8      // This is necessary to avoid needing the user to define a release signing config manually
9      // If no release config is defined, and this is not present, build for assembleRelease will crash
10    }
11  }
12
13  buildTypes {
14    release {
15      // This is necessary to avoid needing the user to define a release build type manually
16    }
17  }
18}
19
20def isEasBuildConfigured = false
21
22tasks.whenTaskAdded {
23  def debug = gradle.startParameter.taskNames.any { it.toLowerCase().contains('debug') }
24
25  if (debug) {
26    return
27  }
28
29  // We only need to configure EAS build once
30  if (isEasBuildConfigured) {
31    return
32  }
33
34  isEasBuildConfigured = true;
35
36  android.signingConfigs.release {
37    def credentialsJson = rootProject.file("../credentials.json");
38
39    if (credentialsJson.exists()) {
40      if (storeFile && !System.getenv("EAS_BUILD")) {
41        println("Path to release keystore file is already set, ignoring 'credentials.json'")
42      } else {
43        try {
44          def credentials = new groovy.json.JsonSlurper().parse(credentialsJson)
45          def keystorePath = Paths.get(credentials.android.keystore.keystorePath);
46          def storeFilePath = keystorePath.isAbsolute()
47            ? keystorePath
48            : rootProject.file("..").toPath().resolve(keystorePath);
49
50          storeFile storeFilePath.toFile()
51          storePassword credentials.android.keystore.keystorePassword
52          keyAlias credentials.android.keystore.keyAlias
53          if (credentials.android.keystore.containsKey("keyPassword")) {
54            keyPassword credentials.android.keystore.keyPassword
55          } else {
56            // key password is required by Gradle, but PKCS keystores don't have one
57            // using the keystore password seems to satisfy the requirement
58            keyPassword credentials.android.keystore.keystorePassword
59          }
60        } catch (Exception e) {
61          println("An error occurred while parsing 'credentials.json': " + e.message)
62        }
63      }
64    } else {
65      if (storeFile == null) {
66        println("Couldn't find a 'credentials.json' file, skipping release keystore configuration")
67      }
68    }
69  }
70
71  android.buildTypes.release {
72    signingConfig android.signingConfigs.release
73  }
74}
75`;
76