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: 'com.android.application' 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'), 'proguard-rules.pro' } } } 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="http://schemas.android.com/apk/res/android" package="com.example.cloverprototypeone"> <uses-permission android:name="android.permission.GET_ACCOUNTS"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
and my MainActivity.kt
package com.example.cloverprototypeone import android.accounts.Account import android.os.Bundle import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.clover.sdk.util.CloverAccount class MainActivity : AppCompatActivity() { private var mAccount : Account? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) } override fun onResume() { super.onResume() if (mAccount == null) { mAccount = CloverAccount.getAccount(this) if (mAccount == null) { Toast.makeText(this, "Clover Account is null", Toast.LENGTH_LONG).show() return } 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: runtime.network.speed: full hw.accelerometer: yes hw.device.name: Clover Station 2018 hw.lcd.width: 1920 hw.initialOrientation: landscape image.androidVersion.api: 25 tag.id: default hw.mainKeys: no hw.camera.front: 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 hw.camera.back: 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: runtime.network.latency: none disk.dataPartition.size: 10G hw.sensors.orientation: yes avd.ini.encoding: UTF-8 hw.gpu.enabled: yes