我遇到以下错误-> 错误:程序类型已存在:androidx.versionedparcelable.CustomVersionedParcelable
当我单击“生成错误”时,它显示以下内容:
AGPBI: {"kind":"error","text":"Program type already present: androidx.versionedparcelable.CustomVersionedParcelable","sources":[{}],"tool":"D8"}
:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
FAILURE: Build failed with an exception.
Run Code Online (Sandbox Code Playgroud)
我不明白是什么原因导致了此问题,因为我正在使用Parcelable库,但从未引起过这种类型的错误。
这是我项目的gradle文件。
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.package.name"
minSdkVersion 22
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// Lottie
implementation 'com.airbnb.android:lottie:2.8.0'
//Gson
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
//Dagger …Run Code Online (Sandbox Code Playgroud) error-handling android runtime-error gradle android-gradle-plugin
我正在尝试向我的应用程序添加一些单元测试,但在向我的 ViewModel 类添加测试时发现一些问题。
我使用该库创建了一个标准 ViewModel 类androidx. lifecycle。
在这些 ViewModel 类中,我启动一个协程来进行 API 调用并检索一些数据。
为此,我创建了一个 ViewModel 扩展函数,只是为了调用用例来最终进行 API 调用。
fun ViewModel.execute(useCase: suspend () -> Unit) {
viewModelScope.launch { useCase() }
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我正在使用viewModelScope以避免一些样板代码,并且它工作得很好。
另外,我将项目配置为使用 JUnit5 和 Mockito。一切都很顺利,直到我尝试为 ViewModel 类创建一些测试。
当我使用 LiveData 时,我创建了一个扩展,以便能够捕获 LiveData 对象的值。像这样:
import android.annotation.SuppressLint
import androidx.arch.core.executor.ArchTaskExecutor
import androidx.arch.core.executor.TaskExecutor
import org.junit.jupiter.api.extension.AfterEachCallback
import org.junit.jupiter.api.extension.BeforeEachCallback
import org.junit.jupiter.api.extension.ExtensionContext
/**
* JUnit5 extension to be able to test LiveData objects
*/
class InstantExecutorExtension : BeforeEachCallback, AfterEachCallback {
/**
* sets a delegate …Run Code Online (Sandbox Code Playgroud) 我正在制作一个 Android 应用程序,需要用户填写表格。在此表单中,有一个字段,用户必须输入她/他的身份证件(例如护照),我想知道是否可以同时显示带有数字和文本的键盘。
提前致谢。