You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android CredentialProviderService缺失所需能力问题求助

问题:自定义Passkey Credential Provider服务提示"Credential Provider Service does not have the required capabilities"

在开发支持Passkeys的Android应用时,我使用Jetpack Credential库实现了CredentialProviderService自定义服务,在Manifest中声明并关联了配置provider.xml(指定了android.credentials.TYPE_PUBLIC_KEY_CREDENTIAL能力),但日志一直提示服务缺少必要能力。


自定义服务代码

class CustomCredentialProviderService : CredentialProviderService() {
    private val TAG = "CredentialProviderService"
    override fun onBeginCreateCredentialRequest(
        request: BeginCreateCredentialRequest,
        cancellationSignal: CancellationSignal,
        callback: OutcomeReceiver<BeginCreateCredentialResponse, CreateCredentialException>
    ) {
        Log.d(TAG,"onBeginCreateCredentialRequest called")
    }

    override fun onBeginGetCredentialRequest(
        request: BeginGetCredentialRequest,
        cancellationSignal: CancellationSignal,
        callback: OutcomeReceiver<BeginGetCredentialResponse, GetCredentialException>
    ) {
        Log.d(TAG,"onBeginGetCredentialRequest called")
    }

    override fun onClearCredentialStateRequest(
        request: ProviderClearCredentialStateRequest,
        cancellationSignal: CancellationSignal,
        callback: OutcomeReceiver<Void?, ClearCredentialException>
    ) {
        Log.d(TAG,"onClearCredentialStateRequest called")
    }

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        return super.onStartCommand(intent, flags, startId)
    }

    override fun onCreate() {
        super.onCreate()
    }

    override fun onUnbind(intent: Intent?): Boolean {
        return super.onUnbind(intent)
    }

    override fun onRebind(intent: Intent?) {
        super.onRebind(intent)
    }

    override fun onDestroy() {
        super.onDestroy()
    }
}

AndroidManifest代码

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.PassKeysDemo"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <service android:name=".CustomCredentialProviderService"
            android:permission="android.permission.BIND_CREDENTIAL_PROVIDER_SERVICE"
            android:exported="false">
           <intent-filter>
               <action android:name="android.service.credentials.CredentialProviderService"/>
           </intent-filter>
           <meta-data android:name="android.credentials.provider"
               android:resource="@xml/provider"/>
        </service>
    </application>

</manifest>

provider.xml代码

<?xml version="1.0" encoding="utf-8"?>
<credential-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:settingsSubtitle="Use Passkeys"
    android:capability="android.credentials.TYPE_PUBLIC_KEY_CREDENTIAL"/>

日志信息

I/CredManSysService: starting executeCreateCredential with callingPackage: com.dashlane.dashlanepasskeydemo
I/CredManSysServiceImpl: Service does not have the required capabilities
I/CredManSysServiceImpl: Service does not have the required capabilities
I/CreateRequestSession: Provider session created and being added for: ComponentInfo{com.google.android.gms/com.google.android.gms.auth.api.credentials.credman.service.RemoteService}

排查与解决步骤

  1. 修正provider.xml的能力配置格式
    根标签的android:capability是单值属性,无法同时覆盖Passkey的创建和获取能力。需要改用<capability>子标签分别声明两种核心能力:

    <?xml version="1.0" encoding="utf-8"?>
    <credential-provider xmlns:android="http://schemas.android.com/apk/res/android"
        android:settingsSubtitle="Use Passkeys">
        <capability android:name="android.credentials.TYPE_PUBLIC_KEY_CREDENTIAL_CREATE" />
        <capability android:name="android.credentials.TYPE_PUBLIC_KEY_CREDENTIAL_GET" />
    </credential-provider>
    
  2. 验证服务访问权限
    确保BIND_CREDENTIAL_PROVIDER_SERVICE权限正确配置,系统需要绑定该服务来处理Passkey请求。当前android:exported="false"的设置是安全的,系统可通过权限直接访问,无需修改。

  3. 更新Jetpack Credentials库版本
    检查依赖的androidx.credentials:credentials和androidx.credentials:credentials-play-services-auth库是否为最新版本,旧版本可能存在配置解析缺陷。

  4. 确认设备环境
    Passkeys要求Android 12(API 31)及以上版本,同时需确保设备上的Google Play Services已更新到最新状态。

内容的提问来源于stack exchange,提问作者yathaarth batra

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 18:00:04