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 } 
  • Asynchronization de reference no resuelta en Kotlin
  • Encapsulando get el nombre del método en un método de ayuda
  • Lista Kotlin (Mutable) <(raw) kotlin.Any?> Cast to List <JsonObject>
  • Acceder al valor del parámetro pnetworkingeterminado de una function en Kotlin
  • Intellij Idea no comstackrá kotlin pero maven lo hace
  • AndroidAnnotations - ViewById no se puede utilizar en un elemento privado
  • ¿Cómo funciona el borrado en Kotlin?
  • Gradle 3.0.0 (en Android Studio 3.0) reorderar la secuencia de tareas (cuando se comstack con el module Kotlin)?
  • ¿Cómo manejar la accesibilidad en la vista personalizada cuando no está diseñada para manejar clics?
  • ¿Cómo agregar leyenda secundaria al gráfico JavaFX?
  • Pausa / Reanudar un timer / retraso en RX