scottnj avatar image
scottnj asked scottnj commented

CloverAccount.getAccount(this) returning null

I'm trying to follow the Integrating with Clover Android SDK guide but CloverAccount.getAccount(this) is always returning null. I read the other posts in the community forum but they didn't help me.

I setup a Station 2018 and a Mini 2nd Gen emulator for my sandbox account following the guide. They both have the Clover launcher running and I went through the tedious process of clicking install for all the Clover apps. The Launcher shows my sandbox merchant info on the right and the Inventory app downloaded my inventory. Everything seems to be working correctly with the emulators.

I created a new project in Android Studio using the "Empty Activity" template. Updated the gradle file with the SDK versions and added the Clover dependency. Added the permission to the manifest. Then added some simple code in the Main Activity as in the guide. The three files are shown below. The project builds without errors. I generate a signed release apk with v1 signature.

In the sandbox dashboard I created a new app, enabled all the permissions (just for learning in the sandbox), upload and save the apk generated above. I then click "preview in app market" and then "Connect".

The app then installs in the emulators and when I run them, the Toast says "clover account is null". I'm still new to the Clover SDK so I am sure I am doing something wrong. But I can not get CloverAccount.getAccount(this) to return anything but null.

Here is my gradle file

apply plugin: ''
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
//    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.cloverprototypeone"
        minSdkVersion 17
        //noinspection ExpiredTargetSdkVersion
        targetSdkVersion 25
        versionCode 3
        versionName "0.0.3 - alpha"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), ''

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    // Clover
    implementation 'com.clover.sdk:clover-android-sdk:228.3'

My manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""

    <uses-permission android:name="android.permission.GET_ACCOUNTS"/>

        <activity android:name=".MainActivity">
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />


and my MainActivity.kt

package com.example.cloverprototypeone

import android.accounts.Account
import android.os.Bundle
import android.widget.Toast
import com.clover.sdk.util.CloverAccount

class MainActivity : AppCompatActivity() {

    private var mAccount : Account? = null

    override fun onCreate(savedInstanceState: Bundle?) {

    override fun onResume() {

        if (mAccount == null) {
            mAccount = CloverAccount.getAccount(this)

            if (mAccount == null) {
                Toast.makeText(this, "Clover Account is null", Toast.LENGTH_LONG).show()
            } else {
                Toast.makeText(this, "Clover Account is not null", Toast.LENGTH_LONG).show()

AVD Manager Emulator Details

Name: Clover_Station_2018_API_25_x86_64
CPU/ABI: Intel Atom (x86_64)
Path: C:\Users\scott\.android\avd\Clover_Station_2018_API_25_x86_64.avd
Target: default [] (API level 25)
Skin: 1920x1080
SD Card: 512M
fastboot.chosenSnapshotFile: full
hw.accelerometer: yes Clover Station 2018
hw.lcd.width: 1920
hw.initialOrientation: landscape
image.androidVersion.api: 25 default
hw.mainKeys: no emulated
avd.ini.displayname: Clover Station 2018 API 25 x86_64
hw.gpu.mode: auto
hw.ramSize: 3072
PlayStore.enabled: false
fastboot.forceColdBoot: yes
hw.cpu.ncore: 4
hw.keyboard: yes
hw.sensors.proximity: yes
hw.dPad: no
hw.lcd.height: 1080
vm.heapSize: 80
skin.dynamic: yes
hw.device.manufacturer: Clover Network, Inc.
hw.gps: yes
skin.path.backup: _no_skin
hw.audioInput: yes
image.sysdir.1: system-images\android-25\default\x86_64\
showDeviceFrame: no virtualscene
AvdId: Clover_Station_2018_API_25_x86_64
hw.lcd.density: 160
hw.arc: false
hw.device.hash2: MD5:507c9c96cd858c3cc993cf7ac781ff7a
fastboot.forceChosenSnapshotBoot: no
fastboot.forceFastBoot: no
hw.trackBall: no
hw.battery: yes
hw.sdCard: yes
tag.display: none
disk.dataPartition.size: 10G
hw.sensors.orientation: yes
avd.ini.encoding: UTF-8
hw.gpu.enabled: yes

Clover Android SDK
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

It sounds like you have done everything correctly so I would be interested in knowing the answer to this...

0 Likes 0 ·

So far everything you are doing seems okay. Are you sure the emulator you created for Station 2018 has API level 25 and the Mini 2nd gen has API level 27?

0 Likes 0 ·
scottnj avatar image scottnj Jacob Abrams ♦♦ ·

In trying to figure things out I just created a new Station 2018 emulator from scratch making sure I followed the guide exactly. Only this time I tried a x86_64 image. I will add the "details" from the AVD manager for this emulator to my post. The problem is the same on the new emulator.

Something that I just noticed, when I go into "More Tools" on the emulator and select "Installed Apps" on the sidebar, then select my app. It says "This app is not available on this device. Please open on a supported device." in a yellow box on the right??? But on the left it says "Supported Devices: Station, Mini, Flex, Station (2018)".

0 Likes 0 ·

The Android emulator is not considered a Clover device by "More Tools" so it your app will never appear in "More Tools" on an emulator.

0 Likes 0 ·

1 Answer

Jacob Abrams avatar image
Jacob Abrams answered scottnj commented

Google has made it very difficult to get accounts via AccountManager. The docs at Google explaining getAccountsByType are really confusing:

Basically since you target API level 25 you are expected to ask for the GET_ACCOUNTS permission at runtime. This is kind of explained at but it's not totally clear.

I recommend targeting an even older API level such as 22 or less otherwise you will need to write a bunch of code to prompt the user for permission just to get it working on the emulator. On real Clover devices we auto-grant the permissions that would otherwise require runtime granting so you only have to do this on the emulator if you target 23 or higher.

1 comment
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

I set the target SDK to 22 and CloverAccount.getAccount(this) is no longer null. Thank you for the help!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community