From eb550f680ef7988f538ffd4148ca8539a0c6b986 Mon Sep 17 00:00:00 2001 From: Carter Jernigan Date: Tue, 4 Jan 2022 08:41:05 -0500 Subject: [PATCH] [#166] Included build for SDK development Note that the SDK master branch contains breaking API changes, which the Secant app hasn't yet been updated to support, so enabling an included build will have compile failures. --- app/build.gradle.kts | 2 +- .../build.gradle.kts | 0 .../settings.gradle.kts | 2 -- .../src/main/kotlin/.editorconfig | 0 .../zcash.android-build-conventions.gradle.kts | 0 .../zcash.dependency-conventions.gradle.kts | 0 ...n-multiplatform-build-conventions.gradle.kts | 2 +- ...-multiplatform-jacoco-conventions.gradle.kts | 0 .../kotlin/zcash.ktlint-conventions.gradle.kts | 0 docs/Setup.md | 17 ++++++++++++++++- gradle.properties | 5 ++++- preference-impl-android-lib/build.gradle.kts | 2 +- sdk-ext-lib/build.gradle.kts | 2 +- settings.gradle.kts | 13 ++++++++++++- ui-lib/build.gradle.kts | 2 +- 15 files changed, 37 insertions(+), 10 deletions(-) rename {build-conventions => build-convention}/build.gradle.kts (100%) rename {build-conventions => build-convention}/settings.gradle.kts (96%) rename {build-conventions => build-convention}/src/main/kotlin/.editorconfig (100%) rename {build-conventions => build-convention}/src/main/kotlin/zcash.android-build-conventions.gradle.kts (100%) rename {build-conventions => build-convention}/src/main/kotlin/zcash.dependency-conventions.gradle.kts (100%) rename {build-conventions => build-convention}/src/main/kotlin/zcash.kotlin-multiplatform-build-conventions.gradle.kts (90%) rename {build-conventions => build-convention}/src/main/kotlin/zcash.kotlin-multiplatform-jacoco-conventions.gradle.kts (100%) rename {build-conventions => build-convention}/src/main/kotlin/zcash.ktlint-conventions.gradle.kts (100%) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 064c744c..79b7b022 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -78,7 +78,7 @@ android { // TODO [#6]: Figure out how to move this into the build-conventions kotlinOptions { jvmTarget = libs.versions.java.get() - allWarningsAsErrors = project.property("IS_TREAT_WARNINGS_AS_ERRORS").toString().toBoolean() + allWarningsAsErrors = project.property("ZCASH_IS_TREAT_WARNINGS_AS_ERRORS").toString().toBoolean() } packagingOptions { diff --git a/build-conventions/build.gradle.kts b/build-convention/build.gradle.kts similarity index 100% rename from build-conventions/build.gradle.kts rename to build-convention/build.gradle.kts diff --git a/build-conventions/settings.gradle.kts b/build-convention/settings.gradle.kts similarity index 96% rename from build-conventions/settings.gradle.kts rename to build-convention/settings.gradle.kts index df7334f5..1d180cda 100644 --- a/build-conventions/settings.gradle.kts +++ b/build-convention/settings.gradle.kts @@ -29,5 +29,3 @@ dependencyResolutionManagement { } } } - -rootProject.name = "build-conventions" diff --git a/build-conventions/src/main/kotlin/.editorconfig b/build-convention/src/main/kotlin/.editorconfig similarity index 100% rename from build-conventions/src/main/kotlin/.editorconfig rename to build-convention/src/main/kotlin/.editorconfig diff --git a/build-conventions/src/main/kotlin/zcash.android-build-conventions.gradle.kts b/build-convention/src/main/kotlin/zcash.android-build-conventions.gradle.kts similarity index 100% rename from build-conventions/src/main/kotlin/zcash.android-build-conventions.gradle.kts rename to build-convention/src/main/kotlin/zcash.android-build-conventions.gradle.kts diff --git a/build-conventions/src/main/kotlin/zcash.dependency-conventions.gradle.kts b/build-convention/src/main/kotlin/zcash.dependency-conventions.gradle.kts similarity index 100% rename from build-conventions/src/main/kotlin/zcash.dependency-conventions.gradle.kts rename to build-convention/src/main/kotlin/zcash.dependency-conventions.gradle.kts diff --git a/build-conventions/src/main/kotlin/zcash.kotlin-multiplatform-build-conventions.gradle.kts b/build-convention/src/main/kotlin/zcash.kotlin-multiplatform-build-conventions.gradle.kts similarity index 90% rename from build-conventions/src/main/kotlin/zcash.kotlin-multiplatform-build-conventions.gradle.kts rename to build-convention/src/main/kotlin/zcash.kotlin-multiplatform-build-conventions.gradle.kts index e987851c..3fe0713d 100644 --- a/build-conventions/src/main/kotlin/zcash.kotlin-multiplatform-build-conventions.gradle.kts +++ b/build-convention/src/main/kotlin/zcash.kotlin-multiplatform-build-conventions.gradle.kts @@ -23,7 +23,7 @@ pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { targets.all { compilations.all { kotlinOptions { - allWarningsAsErrors = project.property("IS_TREAT_WARNINGS_AS_ERRORS").toString().toBoolean() + allWarningsAsErrors = project.property("ZCASH_IS_TREAT_WARNINGS_AS_ERRORS").toString().toBoolean() freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn" } } diff --git a/build-conventions/src/main/kotlin/zcash.kotlin-multiplatform-jacoco-conventions.gradle.kts b/build-convention/src/main/kotlin/zcash.kotlin-multiplatform-jacoco-conventions.gradle.kts similarity index 100% rename from build-conventions/src/main/kotlin/zcash.kotlin-multiplatform-jacoco-conventions.gradle.kts rename to build-convention/src/main/kotlin/zcash.kotlin-multiplatform-jacoco-conventions.gradle.kts diff --git a/build-conventions/src/main/kotlin/zcash.ktlint-conventions.gradle.kts b/build-convention/src/main/kotlin/zcash.ktlint-conventions.gradle.kts similarity index 100% rename from build-conventions/src/main/kotlin/zcash.ktlint-conventions.gradle.kts rename to build-convention/src/main/kotlin/zcash.ktlint-conventions.gradle.kts diff --git a/docs/Setup.md b/docs/Setup.md index 905dbd4a..e3ebda00 100644 --- a/docs/Setup.md +++ b/docs/Setup.md @@ -35,7 +35,6 @@ Start by making sure the command line with Gradle works first, because **all the ## Troubleshooting 1. Verify that the Git repo has not been modified. Due to strict dependency locking (for security reasons), the build will fail unless the locks are also updated -1. If you 1. Try running from the command line instead of Android Studio, to rule out Android Studio issues. If it works from the command line, try this step to reset Android Studio 1. Quit Android Studio 2. Deleting the invisible `.idea` in the root directory of the project @@ -69,3 +68,19 @@ To enable release signing, a release keystore needs to be provided during the bu * ZCASH_RELEASE_KEY_ALIAS_PASSWORD On a developer machine, these might be set under the user's global properties (e.g. `~/.gradle/gradle.properties` on macOS and Linux). On a continuous integration machine, these can also be set using environment variables with the prefix `ORG_GRADLE_PROJECT_` (e.g. `ORG_GRADLE_PROJECT_ZCASH_RELEASE_KEYSTORE_PATH`). DO NOT set these in the gradle.properties inside the Git repository, as this will leak your keystore password. + +### Included builds +To simplify implementation of SDK features in conjunction with changes to the app, a Gradle [Included Build](https://docs.gradle.org/current/userguide/composite_builds.html) can be configured. + +1. Check out the SDK to a directory path of `../zcash-android-sdk` relative to the root of this app's repo. For example: + + parent/ + secant-android-wallet/ + zcash-android-sdk/ + +1. Verify that the `zcash-android-sdk` builds correctly on its own +1. Build `secant-android-wallet`, setting the Gradle property `IS_SDK_INCLUDED_BUILD=true` + +There are some limitations of included builds: +1. Properties from `secant-android-wallet` will override those set in `zcash-android-sdk` with the same name +1. Modules in each project cannot share the same name. For this reason, build-conventions have different names in each repo (`zcash-android-sdk/build-conventions` vs `secant-android-wallet/build-convention`) \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 50676ff6..f4f2733c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ android.nonTransitiveRClass=true android.builder.sdkDownload=true # Kotlin compiler warnings can be considered errors, failing the build. -IS_TREAT_WARNINGS_AS_ERRORS=true +ZCASH_IS_TREAT_WARNINGS_AS_ERRORS=true # The app module will crash at launch when coverage is enabled, so coverage is only enabled explicitly for tests. IS_COVERAGE_ENABLED=false @@ -48,6 +48,9 @@ ZCASH_GOOGLE_PLAY_SERVICE_KEY_FILE_PATH= # Deploy commits the build on Google Play, creating a new release ZCASH_GOOGLE_PLAY_DEPLOY_MODE=build +# Toggles between using the SDK Maven artifact versus an included build +IS_SDK_INCLUDED_BUILD=false + # Versions ANDROID_MIN_SDK_VERSION=24 ANDROID_TARGET_SDK_VERSION=31 diff --git a/preference-impl-android-lib/build.gradle.kts b/preference-impl-android-lib/build.gradle.kts index ede6154b..47ef0873 100644 --- a/preference-impl-android-lib/build.gradle.kts +++ b/preference-impl-android-lib/build.gradle.kts @@ -9,7 +9,7 @@ android { // TODO [#6]: Figure out how to move this into the build-conventions kotlinOptions { jvmTarget = libs.versions.java.get() - allWarningsAsErrors = project.property("IS_TREAT_WARNINGS_AS_ERRORS").toString().toBoolean() + allWarningsAsErrors = project.property("ZCASH_IS_TREAT_WARNINGS_AS_ERRORS").toString().toBoolean() freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn" } diff --git a/sdk-ext-lib/build.gradle.kts b/sdk-ext-lib/build.gradle.kts index 916a97a1..dd944300 100644 --- a/sdk-ext-lib/build.gradle.kts +++ b/sdk-ext-lib/build.gradle.kts @@ -8,7 +8,7 @@ android { // TODO [#6]: Figure out how to move this into the build-conventions kotlinOptions { jvmTarget = libs.versions.java.get() - allWarningsAsErrors = project.property("IS_TREAT_WARNINGS_AS_ERRORS").toString().toBoolean() + allWarningsAsErrors = project.property("ZCASH_IS_TREAT_WARNINGS_AS_ERRORS").toString().toBoolean() freeCompilerArgs = freeCompilerArgs.plus("-Xopt-in=kotlin.RequiresOptIn") } } diff --git a/settings.gradle.kts b/settings.gradle.kts index 315e0f38..d5a2324c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -149,7 +149,7 @@ dependencyResolutionManagement { rootProject.name = "zcash-android-app" -includeBuild("build-conventions") +includeBuild("build-convention") include("app") include("build-info-lib") @@ -157,3 +157,14 @@ include("preference-api-lib") include("preference-impl-android-lib") include("sdk-ext-lib") include("ui-lib") + +if (extra["IS_SDK_INCLUDED_BUILD"].toString().toBoolean()) { + // Currently assume the SDK is up one level with a hardcoded directory name + // If this becomes problematic, `IS_SDK_INCLUDED_BUILD` could be turned into a path + // instead. + includeBuild("../zcash-android-sdk") { + dependencySubstitution { + substitute(module("cash.z.ecc.android:zcash-android-sdk")).using(project(":sdk-lib")) + } + } +} diff --git a/ui-lib/build.gradle.kts b/ui-lib/build.gradle.kts index e6d87e20..d71202bb 100644 --- a/ui-lib/build.gradle.kts +++ b/ui-lib/build.gradle.kts @@ -19,7 +19,7 @@ android { // TODO [#6]: Figure out how to move this into the build-conventions kotlinOptions { jvmTarget = libs.versions.java.get() - allWarningsAsErrors = project.property("IS_TREAT_WARNINGS_AS_ERRORS").toString().toBoolean() + allWarningsAsErrors = project.property("ZCASH_IS_TREAT_WARNINGS_AS_ERRORS").toString().toBoolean() freeCompilerArgs = freeCompilerArgs.plus("-Xopt-in=kotlin.RequiresOptIn") }