我正在尝试使用内部应用程序共享来测试我是否可以正确请求和下载按需动态功能模块。
当我尝试这个时,我可以看到它首先开始正确下载新功能,但它永远不会安装。我看到了这些com.example is installed but certificate mismatch
日志。这会导致问题吗?我知道内部应用程序共享上传是“使用内部应用程序共享密钥自动重新签名的,该密钥是由 Google 为您的应用程序自动创建的”。来源。内部应用共享是否可能未正确签署按需 apk?
下载有问题的代码:
private const val ONDEMAND_FEATURE_MODULE_NAME: String = "ondemandfeature" // must match gradle module name
fun downloadOnDemandFeature(context: Context) {
val request = SplitInstallRequest
.newBuilder()
.addModule(ONDEMAND_FEATURE_MODULE_NAME)
.build()
val splitInstallManager = create(context)
// Initializes a variable to later track the session ID for a given request.
var mySessionId = 0
val listener = SplitInstallStateUpdatedListener { state ->
if (state.sessionId() == mySessionId) {
when (state.status()) {
SplitInstallSessionStatus.DOWNLOADING -> {
val totalBytes = state.totalBytesToDownload()
val progress = state.bytesDownloaded()
Timber.d("Downloading on demand module: state DOWNLOADING")
Timber.d("Downloading on demand module: %d of %d bytes", progress, totalBytes)
}
SplitInstallSessionStatus.INSTALLED -> {
Timber.d("Downloading on demand module: state INSTALLED")
// TODO installed, now do stuff
}
SplitInstallSessionStatus.CANCELED -> {
Timber.d("Downloading on demand module: state CANCELED")
}
SplitInstallSessionStatus.CANCELING -> {
Timber.d("Downloading on demand module: state CANCELING")
}
SplitInstallSessionStatus.DOWNLOADED -> {
Timber.d("Downloading on demand module: state DOWNLOADED")
}
SplitInstallSessionStatus.FAILED -> {
Timber.d("Downloading on demand module: state FAILED")
}
SplitInstallSessionStatus.INSTALLING -> {
Timber.d("Downloading on demand module: state INSTALLING")
}
SplitInstallSessionStatus.PENDING -> {
Timber.d("Downloading on demand module: state PENDING")
}
SplitInstallSessionStatus.REQUIRES_USER_CONFIRMATION -> {
Timber.d("Downloading on demand module: state REQUIRES USER CONFIRMATION")
}
SplitInstallSessionStatus.UNKNOWN -> {
Timber.d("Downloading on demand module: state UNKNOWN")
}
}
}
}
splitInstallManager.registerListener(listener)
splitInstallManager
.startInstall(request)
.addOnSuccessListener { sessionId -> mySessionId = sessionId }
.addOnFailureListener { exception ->
Timber.e(exception, "Error installing ondemandfeature")
}
}
你可以在这里查看我的完整日志。