迁移到AndroidX后,在运行单元测试时构建Failed to transform 'C:\Users\User\.gradle\caches\modules-2\files-2.1\org.robolectric\android-all\9-robolectric-4913185-2\92c6ca3712d7a06f76f70655ec81162ff372fb19\android-all-9-robolectric-4913185-2.jar' using Jetifier. Reason: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 3-byte UTF-8 sequence.. (Run with --stacktrace for more details.) To disable Jetifier, set android.enableJetifier=false in your gradle.properties file.
时收到此错误。我确实需要将enableJetifier设置为true。
有人知道为什么会发生或如何解决吗?我刚刚添加了更多代码以提供更好的见解。所有版本都在版本数组中。
gradle.properties:
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
android.useAndroidX=true
android.enableJetifier=true
版本:
ext.versions = [
androidSupport : '28.0.0',
otto : '1.3.8',
retrofit : '2.4.0',
okhttp3 : '3.11.0',
animator : '2.2.3',
gson : '2.8.5',
joda : '2.9.3',
commonsLang3 : '3.4',
commonsIo : '2.5',
commonsCollections: '3.2.2',
commonsCodec : '1.10',
espresso : '3.1.0-beta01',
hamcrest : '1.3',
junit : '4.12',
mockito : '1.10.19',
powerMock : '1.6.5',
dagger : '2.17',
parcel : '1.1.5',
butterKnife : '9.0.0-SNAPSHOT',
robolectric : '4.0-beta-1',
assertj : '3.11.1',
awaitility : '3.1.2',
material : '1.0.0'
]
Build.gradle:
dependencies {
implementation 'com.google.android.gms:play-services-auth:16.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation('androidx.annotation:annotation:1.0.0') {
force true
}
implementation "com.google.guava:guava:$versions.guava"
implementation "com.google.dagger:dagger:$versions.dagger"
annotationProcessor "com.google.dagger:dagger-compiler:$versions.dagger"
implementation "com.squareup:otto:$versions.otto"
implementation "com.squareup.retrofit2:retrofit:$versions.retrofit"
implementation "com.squareup.retrofit2:converter-gson:$versions.retrofit"
implementation "com.squareup.okhttp3:okhttp:$versions.okhttp3"
implementation "com.google.android.material:material:$versions.material"
implementation "jp.wasabeef:recyclerview-animators:$versions.animator"
implementation "com.google.code.gson:gson:$versions.gson"
implementation "net.danlew:android.joda:$versions.joda"
implementation "org.apache.commons:commons-lang3:$versions.commonsLang3"
implementation "commons-collections:commons-collections:$versions.commonsCollections"
implementation "commons-io:commons-io:$versions.commonsIo"
implementation "commons-codec:commons-codec:$versions.commonsCodec"
implementation "com.squareup.picasso:picasso:$versions.picasso"
implementation "org.parceler:parceler-api:$versions.parcel"
annotationProcessor "org.parceler:parceler:$versions.parcel"
implementation "com.jakewharton:butterknife:$versions.butterKnife"
annotationProcessor "com.jakewharton:butterknife-compiler:$versions.butterKnife"
// test dependencies
testImplementation "junit:junit:$versions.junit"
testImplementation "org.mockito:mockito-core:$versions.mockito"
testImplementation "org.powermock:powermock-core:$versions.powerMock"
testImplementation "org.powermock:powermock-module-junit4:$versions.powerMock"
testImplementation "org.powermock:powermock-module-junit4-rule:$versions.powerMock"
testImplementation "org.powermock:powermock-api-mockito:$versions.powerMock"
testImplementation "org.powermock:powermock-classloading-xstream:$versions.powerMock"
testImplementation "org.hamcrest:hamcrest-core:$versions.hamcrest"
testImplementation "org.hamcrest:hamcrest-library:$versions.hamcrest"
testImplementation "org.robolectric:robolectric:$versions.robolectric"
testImplementation "org.assertj:assertj-core:$versions.assertj"
testImplementation "org.robolectric:android-all:9-robolectric-4913185-2"
// android test dependencies
androidTestImplementation 'androidx.test:runner:1.1.0-beta01'
androidTestImplementation 'androidx.test:rules:1.1.0-beta01'
androidTestImplementation "junit:junit:$versions.junit"
androidTestImplementation "org.mockito:mockito-core:$versions.mockito"
androidTestImplementation "org.hamcrest:hamcrest-core:$versions.hamcrest"
androidTestImplementation "org.hamcrest:hamcrest-library:$versions.hamcrest"
androidTestImplementation "com.squareup.retrofit2:retrofit-mock:$versions.retrofit"
androidTestImplementation "com.google.guava:guava:$versions.guava"
androidTestImplementation 'androidx.annotation:annotation:1.0.0'
androidTestImplementation("androidx.test.espresso:espresso-contrib:$versions.espresso", {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestImplementation("androidx.test.espresso:espresso-intents:$versions.espresso", {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestImplementation("androidx.test.espresso:espresso-core:$versions.espresso", {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestImplementation "com.google.dagger:dagger:$versions.dagger"
androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:$versions.dagger"
androidTestImplementation 'androidx.multidex:multidex:2.0.0'
androidTestImplementation "org.awaitility:awaitility:$versions.awaitility"
}
答案 0 :(得分:0)
Jetifier可能是一个错误。尝试将其添加到项目gradle:
buildscript {
dependencies {
classpath 'com.android.tools.build.jetifier:jetifier-processor:1.0.0-beta02'
}
}
如果您正在使用数据绑定,则可能需要将此添加到应用程序gradle依赖项中:
annotationProcessor 'com.android.tools.build.jetifier:jetifier-core:1.0.0-beta02'
如果您使用的是Kotlin,则需要这两个
kapt 'com.android.tools.build.jetifier:jetifier-core:1.0.0-beta02'
annotationProcessor 'com.android.tools.build.jetifier:jetifier-core:1.0.0-beta02'
答案 1 :(得分:0)
使用以下依赖项已解决的问题
{{1}}