square/reader-sdk-android-quickstart

Reader SDKs for Debug and Release Environments

davenotdavid opened this issue · 4 comments

Similar to this question without it being addressed (where instead, we have two production Square accounts each pointing to a debug and release environment): #8

^ with that in mind, is it possible to download the Reader SDK dependencies from the repository based on build types when authorizing into it with respective credentials (i.e. our debug/dev creds pointing to a production Square account's Reader SDK, and the release creds pointing to another production Square account's Reader SDK in this case) via the same repository URL? Because, I'm not really seeing any documentation on this as of now.

Here's the relevant parts of the app level build.gradle file:

...

final SQUARE_READER_SDK_APP_ID_DEV = 'sq0idp-T4SClu2rWV2AcYcEiHALXg'
final SQUARE_READER_SDK_APP_ID_PROD = 'sq0idp-cyEZl-H328bxzEh0E4tq5w'
final SQUARE_READER_SDK_VERSION = "1.3.6"

...

buildTypes {
    debug {
        ...

        repositories {
            maven {
                url "https://sdk.squareup.com/android"
                credentials {
                    username SQUARE_READER_SDK_APP_ID_DEV
                    // Set as a property from CI command with one of its env vars
                    password squareReaderSdkPasswordDev
                }
            }
        }

    }
    release {
        ... 

        repositories {
            maven {
                url "https://sdk.squareup.com/android"
                credentials {
                    username SQUARE_READER_SDK_APP_ID_PROD
                    // Set as a property from CI command with one of its env vars
                    password squareReaderSdkPasswordProd
                }
            }
        }
    }
}

...

dependencies { 
    ...

    debugImplementation "com.squareup.sdk.reader:reader-sdk-$SQUARE_READER_SDK_APP_ID_DEV:$SQUARE_READER_SDK_VERSION"
    releaseImplementation "com.squareup.sdk.reader:reader-sdk-$SQUARE_READER_SDK_APP_ID_PROD:$SQUARE_READER_SDK_VERSION"
    runtimeOnly "com.squareup.sdk.reader:reader-sdk-internals:$SQUARE_READER_SDK_VERSION"
    
    ...
}

...

Note that building this locally (via Gradle builds and the ./gradlew androidDependencies task) works properly, but not our CI as mentioned in my SO post: https://stackoverflow.com/questions/61240438/execution-failed-for-task-appandroiddependencies-on-circle-ci-but-not-locall

^ but it passes on CI when only downloading the dependency from one build type (i.e.
temporarily commenting out the release creds to only get the debug one, but doesn't work simultaneously
)

Hello!
This is really strange, as Gradle should be resolving the aar and its transitive dependencies automatically based on .pom file. But you can try to help it like it's suggested here.

Add @aar and transitive = true in the end of the debug/release dependencies, and see if that resolves the problem on CircleCI:

debugImplementation ("com.squareup.sdk.reader:reader-sdk-$SQUARE_READER_SDK_APP_ID_DEV:$SQUARE_READER_SDK_VERSION@aar") {
    transitive = true
}
releaseImplementation ("com.squareup.sdk.reader:reader-sdk-$SQUARE_READER_SDK_APP_ID_PROD:$SQUARE_READER_SDK_VERSION@aar") {
    transitive = true
}

@Armaxis - thank you for the response. I like that suggestion, but it still turns out Circle isn't happy, which is very, very strange since I see the aar file that I can download myself after authorizing into the repo:

> Task :app:androidDependencies
debug

> Task :app:androidDependencies FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:androidDependencies'.
> Could not resolve all artifacts for configuration ':app:debugCompileClasspath'.
   > Could not find reader-sdk-sq0idp-T4SClu2rWV2AcYcEiHALXg.aar (com.squareup.sdk.reader:reader-sdk-sq0idp-T4SClu2rWV2AcYcEiHALXg:1.3.6).
     Searched in the following locations:
         https://sdk.squareup.com/android/com/squareup/sdk/reader/reader-sdk-sq0idp-T4SClu2rWV2AcYcEiHALXg/1.3.6/reader-sdk-sq0idp-T4SClu2rWV2AcYcEiHALXg-1.3.6.aar

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 2m 17s
1 actionable task: 1 executed

Exited with code exit status 1

I'm gonna have to investigate further how to fix this on Circle's end... :-/

It's searching for a wrong file:

reader-sdk-sq0idp-T4SClu2rWV2AcYcEiHALXg.aar

Instead of:

reader-sdk-sq0idp-T4SClu2rWV2AcYcEiHALXg-1.3.6.aar

There's something wrong with Gradle on your CI 😕 I don't know what Gradle uses under the hood to pull artifacts from Maven, but if it does use something from the environment (local maven setup? java?) it would explain why it doesn't work on Circle CI but does locally.
I'd suggest filing an issue on Gradle's github as well, maybe folks over there would be able to point out why certain artifacts aren't accessible from Circle CI but are locally.
Link this issue and previous one for reference, there's lots of useful info.
Good luck!

@Armaxis - Oh wow, good catch! I never noticed that... Thanks for this, and once again, I'll go see what's going on with my CI :-)