该应用程序适用于minSdkVersion 24,但在将其减少到minSdkVersion 19后,我收到的错误很少。在我的设备中运行它但在gradle sync时没有错误。错误日志已发布。依赖关系适用于minSdkVersion 24,但不适用于minSdkVersion 19,给我下面列出的错误,我需要它在minSdkVersion 19等较低版本上工作。任何帮助都将不胜感激。
错误记录在这里: 4个错误,1个警告
Calculate task graph 122ms
Run tasks 2m 7s 746ms null
Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:\Users\hp\.gradle\caches\modules-2\files-2.1\android.arch.lifecycle\common-java8\1.1.1\795d68cd761d093ccb235d1d91b8fd17c2ae25ff\common-java8-1.1.1.jar
com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.
com.android.tools.r8.CompilationFailedException: Compilation failed to complete
com.android.tools.r8.utils.AbortException
null
Default interface methods are only supported starting with Android N (--min-api 24): void android.arch.lifecycle.DefaultLifecycleObserver.onCreate(android.arch.lifecycle.LifecycleOwner)
我的应用级Gradle文件。(此处为minSdkversion 24)
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.hp.mkchat"
minSdkVersion 24
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled true
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:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.google.firebase:firebase-core:11.4.2'
implementation 'com.google.firebase:firebase-auth:11.4.2'
implementation 'com.android.support:support-v4:27.1.1-beta1'
implementation 'com.google.firebase:firebase-database:11.4.2'
implementation 'com.google.firebase:firebase-storage:11.4.2'
implementation 'com.google.firebase:firebase-messaging:11.4.2'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.android.support:multidex:1.0.1'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.squareup.okhttp:okhttp:2.5.0'
implementation 'com.firebaseui:firebase-ui-database:3.1.0'
implementation 'id.zelory:compressor:2.1.0'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
// ViewModel and LiveData
implementation "android.arch.lifecycle:extensions:1.1.1"
// alternatively - just ViewModel
implementation "android.arch.lifecycle:viewmodel:1.1.1" // use -ktx for Kotlin
// alternatively - just LiveData
implementation "android.arch.lifecycle:livedata:1.1.1"
// alternatively - Lifecycles only (no ViewModel or LiveData).
// Support library depends on this lightweight import
implementation "android.arch.lifecycle:runtime:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
// alternately - if using Java8, use the following instead of compiler
implementation "android.arch.lifecycle:common-java8:1.1.1"
// optional - ReactiveStreams support for LiveData
implementation "android.arch.lifecycle:reactivestreams:1.1.1"
// optional - Test helpers for LiveData
testImplementation "android.arch.core:core-testing:1.1.1"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
}
apply plugin: 'com.google.gms.google-services'
答案 0 :(得分:14)
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
答案 1 :(得分:1)
检查源兼容性和目标兼容性是否不是Java-8。将其设置为Java-8。
答案 2 :(得分:0)
从gradle中删除这些行有助于删除错误并在我的手机上成功运行,使其在Android 7版本下运行
// alternatively - just ViewModel
implementation "android.arch.lifecycle:viewmodel:1.1.1" // use -ktx for Kotlin
// alternatively - just LiveData
implementation "android.arch.lifecycle:livedata:1.1.1"
// alternatively - Lifecycles only (no ViewModel or LiveData).
// Support library depends on this lightweight import
implementation "android.arch.lifecycle:runtime:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
// alternately - if using Java8, use the following instead of compiler
implementation "android.arch.lifecycle:common-java8:1.1.1"
// optional - ReactiveStreams support for LiveData
implementation "android.arch.lifecycle:reactivestreams:1.1.1"
// optional - Test helpers for LiveData
testImplementation "android.arch.core:core-testing:1.1.1"
答案 3 :(得分:0)
我无法通过以上所有答案解决此问题,但是我找到了解决方案。我从我的libs项目文件夹中删除了appcompat v4库。
您的项目文件夹>应用>库> appcompat ... rar
删除它,然后重新启动android studio。