IllegalArgumentException: addAccount no compatible

Seguí esta descripción para agregar mi adaptador de synchronization.

Pero hay una pequeña falla 🙁

Cuando abro Configuración -> Cuenta -> Agregar count y selecciono mi count aparece este post de error

java.lang.IllegalArgumentException: addAccount not supported at android.accounts.AccountManager.convertErrorToException(AccountManager.java:2147) at android.accounts.AccountManager.-wrap0(AccountManager.java) at android.accounts.AccountManager$AmsTask$Response.onError(AccountManager.java:1993) at android.accounts.IAccountManagerResponse$Stub.onTransact(IAccountManagerResponse.java:69) at android.os.Binder.execTransact(Binder.java:453) 

Parece que este locking proviene de convertir la class de Authenticator Java en una class de Kotlin.

La class Java se bloquea de esta manera

 public class Authenticator extends AbstractAccountAuthenticator { private final Context mContext; // Simple constructor public Authenticator(Context context) { super(context); mContext = context; } // Editing properties is not supported @Override public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) { throw new UnsupportedOperationException(); } @Override public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requinetworkingFeatures, Bundle options) throws NetworkErrorException { SyncUtilsKt.createSyncAccount(mContext); final Bundle bundle = new Bundle(); bundle.putString(AccountManager.KEY_ACCOUNT_NAME, ConstantsKt.SYNC_ACCOUNT); bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, BuildConfig.ACCOUNT_TYPE); return bundle; } // Ignore attempts to confirm cnetworkingentials @Override public Bundle confirmCnetworkingentials(AccountAuthenticatorResponse response, Account account, Bundle options) throws NetworkErrorException { return null; } // Getting an authentication token is not supported @Override public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException { throw new UnsupportedOperationException(); } // Getting a label for the auth token is not supported @Override public String getAuthTokenLabel(String authTokenType) { throw new UnsupportedOperationException(); } // Updating user cnetworkingentials is not supported @Override public Bundle updateCnetworkingentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException { throw new UnsupportedOperationException(); } // Checking features for the account is not supported @Override public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) throws NetworkErrorException { throw new UnsupportedOperationException(); } } 

Después de convertirlo a Kotlin, se bloquea así:

 class Authenticator(private val mContext: Context) : AbstractAccountAuthenticator(mContext) { // Editing properties is not supported override fun editProperties(response: AccountAuthenticatorResponse, accountType: String): Bundle { throw UnsupportedOperationException() } @Throws(NetworkErrorException::class) override fun addAccount(response: AccountAuthenticatorResponse, accountType: String, authTokenType: String, requinetworkingFeatures: Array<String>, options: Bundle): Bundle { createSyncAccount(mContext) val bundle = Bundle() bundle.putString(AccountManager.KEY_ACCOUNT_NAME, SYNC_ACCOUNT) bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, BuildConfig.ACCOUNT_TYPE) return bundle } // Ignore attempts to confirm cnetworkingentials @Throws(NetworkErrorException::class) override fun confirmCnetworkingentials(response: AccountAuthenticatorResponse, account: Account, options: Bundle): Bundle? { return null } // Getting an authentication token is not supported @Throws(NetworkErrorException::class) override fun getAuthToken(response: AccountAuthenticatorResponse, account: Account, authTokenType: String, options: Bundle): Bundle { throw UnsupportedOperationException() } // Getting a label for the auth token is not supported override fun getAuthTokenLabel(authTokenType: String): String { throw UnsupportedOperationException() } // Updating user cnetworkingentials is not supported @Throws(NetworkErrorException::class) override fun updateCnetworkingentials(response: AccountAuthenticatorResponse, account: Account, authTokenType: String, options: Bundle): Bundle { throw UnsupportedOperationException() } // Checking features for the account is not supported @Throws(NetworkErrorException::class) override fun hasFeatures(response: AccountAuthenticatorResponse, account: Account, features: Array<String>): Bundle { throw UnsupportedOperationException() } } 

Creo que hay algo mal convertido pero ¿qué?

Encontré mi error. El método addAccount necesita algunas annotations. Finalmente se ve así:

 @Throws(NetworkErrorException::class) override fun addAccount(response: AccountAuthenticatorResponse, accountType: String, authTokenType: String?, requinetworkingFeatures: Array<String>?, options: Bundle?): Bundle? { val accountManager = mContext.getSystemService(Context.ACCOUNT_SERVICE) as AccountManager val accounts = accountManager.getAccountsByType("example.com") if (accounts.size == 0) { val newAccount = Account("Sync Account", "example.com") accountManager.addAccountExplicitly(newAccount, null, null) } val bundle = Bundle() bundle.putString(AccountManager.KEY_ACCOUNT_NAME, "Sync Account") bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, "example.com") return bundle } 
  • Función de object compañera burlona en kotlin
  • ¿Cómo se inyectan parameters de campo con nombre en Kotlin con Dagger 2?
  • La construcción de Android Studio falló con Kotlin
  • Dagger 2 - Inyectar con valor pnetworkingeterminado en el constructor
  • Selecciones no deseadas en RecyclerView
  • ¿Kotlin iterator a la list?
  • La propiedad de extensión de Kotlin no se reconoce en la plantilla de cadena
  • Compruebe si la class es un valor válido para KParameter
  • Seleccionar propiedad de cada object en una list
  • ¿Cómo anular el método setter en kotlin?
  • Desadaptación del tipo de Kotlin: ¡tipo inferido es Ver! pero se esperaba TextView