diff --git a/app/build.gradle b/app/build.gradle index e4e6c2444c..07ee53347a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -18,7 +18,9 @@ apply from: "$rootDir/versioning.gradle" def apikeyPropertiesFile = rootProject.file("apikeys.properties") def apikeyProperties = new Properties() -apikeyProperties.load(new FileInputStream(apikeyPropertiesFile)) +if (apikeyPropertiesFile.exists()) { + apikeyProperties.load(new FileInputStream(apikeyPropertiesFile)) +} def useReleaseKeystore = rootProject.file("scripts/release/app-release.jks").exists() @@ -97,7 +99,7 @@ android { shrinkResources true debuggable false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - buildConfigField("String", "AMPLITUDE_KEY", apikeyProperties['amplitude.release']) + buildConfigField("String", "AMPLITUDE_KEY", apikeyProperties['amplitude.release'] ?: "MISSING_AMPLITUDE_RELEASE_KEY") if (useReleaseKeystore) { signingConfig signingConfigs.release } else { @@ -108,7 +110,7 @@ android { debug { applicationIdSuffix ".dev" debuggable true - buildConfigField("String", "AMPLITUDE_KEY", apikeyProperties['amplitude.debug']) + buildConfigField("String", "AMPLITUDE_KEY", apikeyProperties['amplitude.debug'] ?: "MISSING_AMPLITUDE_DEBUG_KEY") //signingConfig signingConfigs.debug firebaseAppDistribution { artifactType = "AAB" @@ -142,7 +144,7 @@ android { // Configures multiple APKs based on ABI. abi { // Enables building multiple APKs per ABI. - enable project.hasProperty("enableAbiSplits") && project.getProperty("enableAbiSplits").toBoolean() + enable true reset() include "armeabi-v7a", "arm64-v8a" universalApk true diff --git a/build.gradle b/build.gradle index 2f95f8e9b9..b4ca18d40d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,6 @@ +import javax.inject.Inject import com.android.build.gradle.LibraryPlugin +import org.gradle.api.tasks.* import org.jetbrains.kotlin.gradle.plugin.KotlinAndroidPluginWrapper buildscript { @@ -14,13 +16,17 @@ buildscript { def githubProperties = new Properties() def githubPropertiesFile = file("$rootDir${File.separator}github.properties") - githubProperties.load(new FileInputStream(githubPropertiesFile)) + if (githubPropertiesFile.exists()) { + githubProperties.load(new FileInputStream(githubPropertiesFile)) + } def apiKeysProperties = new Properties() def apiKeysPropertiesFile = file("$rootDir${File.separator}apikeys.properties") - apiKeysProperties.load(new FileInputStream(apiKeysPropertiesFile)) + if (apiKeysPropertiesFile.exists()) { + apiKeysProperties.load(new FileInputStream(apiKeysPropertiesFile)) + } - ext.sentryApiKey = apiKeysProperties["sentry_dsn"] + ext.sentryApiKey = apiKeysProperties["sentry_dsn"] ?: "MISSING_SENTRY_DSN_KEY" repositories { mavenLocal() @@ -108,14 +114,71 @@ task clean(type: Delete) { delete rootProject.buildDir } -tasks.register("installGitHooks") { - setGroup("Build Setup") - setDescription("Install local repository git hooks") - exec { - commandLine 'sh', '-c', 'git config core.hooksPath .githooks' +abstract class InstallGitHooksTask extends DefaultTask { + + private ExecOperations execOps + + @Inject + InstallGitHooksTask(ExecOperations execOperations) { + this.execOps = execOperations + } + + java.lang.String getGroup() { + return "Build Setup"; + } + + java.lang.String getDescription() { + return "Install local repository git hooks"; + } + + @Internal + boolean isPosh7Available() { + try { + logger.debug('checking posh7'); + ByteArrayOutputStream stdout = new ByteArrayOutputStream() + ExecResult result = execOps.exec { + commandLine 'cmd', '/c', 'where', 'pwsh.exe' + standardOutput = stdout + } + logger.info('where stdout = ' + stdout.toString() ); + logger.info('where exit = ' + result.exitValue); + return result.exitValue == 0; + } catch (Exception e) { + logger.error('checking posh7 error ' + e.getMessage()); + return false + } + } + + @TaskAction + void action() { + OperatingSystem os = org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.currentOperatingSystem; + String shell = 'sh' + String commandFlag = '-c' + + if (os.isWindows()) { + logger.lifecycle('Running on Windows.') + + if (isPosh7Available()) { + shell = 'pwsh.exe' + logger.lifecycle('Using pwsh.exe') + } else { + shell = 'powershell.exe' + commandFlag = '-Command' + logger.lifecycle('pwsh.exe not found. Falling back to powershell.exe') + } + } + + ByteArrayOutputStream stdout = new ByteArrayOutputStream() + ExecResult result = execOps.exec { + commandLine shell, commandFlag, 'git config core.hooksPath .githooks' + standardOutput = stdout + } + logger.info('githooks stdout = ' + stdout.toString() ); } } +tasks.register("installGitHooks", InstallGitHooksTask) + var initialTaskNames = getProject().getGradle().getStartParameter().getTaskNames() getProject().getGradle().getStartParameter().setTaskNames( initialTaskNames + Collections.singletonList("installGitHooks")) \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index fba4d1f600..ad42ab1735 100644 --- a/settings.gradle +++ b/settings.gradle @@ -19,7 +19,9 @@ dependencyResolutionManagement { */ def githubProperties = new Properties() def githubPropertiesFile = file("$rootDir${File.separator}github.properties") - githubProperties.load(new FileInputStream(githubPropertiesFile)) + if (githubPropertiesFile.exists()) { + githubProperties.load(new FileInputStream(githubPropertiesFile)) + } repositories { mavenLocal()