Android 7.0(Nougat)부터는 기본 인터페이스 방법만 지원됩니다.
Android Studio 3.1로 업그레이드했는데 다음 오류가 발생합니다.
기본 인터페이스 메서드는 Android N(--min-api 24): void arch.lifecycle에서만 지원됩니다.기본 LifecycleObserver.onCreate(Android.arch.lifecycle).라이프사이클 소유자)
메시지 {kind=ERROR, text=기본 인터페이스 메서드는 Android N(--min-api 24): void roid.arch.message만 지원됩니다.기본 LifecycleObserver.onCreate(Android.arch.lifecycle).라이프사이클 소유자), 출처=[알 수 없는 원본 파일], 도구 이름=Optional.of(D8)}
다음은 내 Gradle 구성입니다.
compileSdkVersion 27
//buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion 16
targetSdkVersion 27
multiDexEnabled true
//...
}
보시다시피, 저는 27개를 목표로 하고 있는데, 이미 24개보다 앞서고 있습니다.이걸 고치려면 정확히 어떻게 해야 하나요?1.8 자바로 변경하면 고객이 많이 누락되지 않을까요?Android Studio를 업그레이드하기 전에 이 오류가 발생하지 않은 이유는 무엇입니까?
최근에 입력한 LifecycleObserver 클래스에 대한 내용인지 모르겠습니다.Kotlin에 있었고 지금은 Java로 변경했지만 프로젝트를 정리한 후에도 동일한 오류가 발생합니다.
public class LifeCycleAwareObserver implements LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
public void onAppBackgrounded() {
AnalyticsUtils.trackStartSession(true);
}
@OnLifecycleEvent(Lifecycle.Event.ON_START)
public void onAppForegrounded() {
AnalyticsUtils.trackStartSession(false);
}
}
오류가 발생한 위치를 추적하여 해결하려면 어떻게 해야 합니까?
버전 종속성은 다음과 같습니다.
project.ext {
firebase_version = '12.0.0'
supportlib_version = '27.0.2'
room_version = '1.0.0'
espresso_version = '3.0.1'
archLifecycleVersion = '1.1.1'
}
CommonsWare에서 언급했듯이, 참조를 위해 이것을 다음과 같이 추가합니다.android {...}이 문제를 해결하기 위해 앱 모듈(앱 수준)의 build.gradle을 닫습니다.
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
...
}
이 문제를 해결하려면 Java 8을 사용해야 합니다.Android 설명서에 따라 File → Project Structure 메뉴를 클릭하여 이 작업을 수행할 수 있습니다.
소스 호환성 및 대상 호환성을 변경합니다.
또한 애플리케이션 레벨에서 직접 구성할 수도 있습니다.build.gradle파일:
android {
...
// Configure only for each module that uses Java 8
// language features (either in its source code or
// through dependencies).
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
앱 레벨 Gradle 파일에서 다음 코드를 작성해야 합니다.
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Android의 JavaVersion.java에서 제공됩니다.
Java 버전의 열거형입니다.
9시 이전: http://www.oracle.com/technetwork/java/javase/versioning-naming-139433.html
9시 이후: http://openjdk.java.net/jeps/223
build.gradle(모듈:app)을 업데이트합니다.compileOptions차단 및 추가JavaVersion.VERSION_1_8
apply plugin: 'com.android.application'
android {
.................
.........................
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
최신 Android Studio 버전 3.4.1에서 소스 호환성 및 *대상 호환성 Java 버전을 1.8로 다운그레이드하여 이 문제를 해결할 수 있습니다.
앱 폴더를 마우스 오른쪽 버튼으로 클릭하거나 Mac에서 +를 클릭하여 모듈 설정(프로젝트 구조) 창을 엽니다.
모듈 → 속성으로 이동합니다.
소스 호환성 및 대상 호환성 버전을 1.8로 변경
또는 을 클릭합니다.바로 그겁니다.그것은 당신의 문제를 해결해줄 것입니다.
또한 수동으로 build.gradle 파일을 추가할 수 있습니다(모듈: app).
android {
...
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
...
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 30
buildToolsVersion "30.0.0"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.example.architecture"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'androidx.room:room-runtime:2.2.5'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
annotationProcessor 'androidx.room:room-compiler:2.2.5'
def lifecycle_version = "2.2.0"
def arch_version = "2.1.0"
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-service:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version"
implementation "androidx.cardview:cardview:1.0.0"
}
앱 모듈의 구성을 추가합니다.build.gradle
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
build.gradle 파일에서 이 코드를 사용합니다.
android {
compileOptions {
incremental true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
제 프로젝트는 버터나이프와 레트로 람다를 사용합니다.Java 버전을 설정하는 중입니다.VERSION_1_8이 작동하지 않습니다.이 Migrate from Retrolambda를 찾을 때까지 항상 ButterKnife 정적 인터페이스 기능을 비난했습니다.
TL;DR
JavaVersion만 추가하면 됩니다.VERSION_1_8 및 프로젝트에서 retrolambda를 완전히 제거합니다.성공적으로 구축됩니다.
minSdkVersion을 19에서 21로 변경하여 문제를 해결했습니다.
defaultConfig {
applicationId "com.example"
minSdkVersion 21
targetSdkVersion 29
versionCode 23
versionName "1.0"
vectorDrawables.useSupportLibrary = true
}
동적 기능을 사용하는 경우에도 이 문제가 발생했습니다.저는 이미 앱 모듈에서 Java 8 호환성을 활성화했지만 동적 기능 모듈에 이 호환성 행을 추가해야 했고 작동했습니다.
언급URL : https://stackoverflow.com/questions/49512629/default-interface-methods-are-only-supported-starting-with-android-7-0-nougat
'programing' 카테고리의 다른 글
| MySQL의 필드에서 가장 일반적인 값 선택 (0) | 2023.08.28 |
|---|---|
| 전역 변수 이름이 함수에 전달된 변수인 함수에서 전역 PowerShell 변수 설정 (0) | 2023.08.28 |
| 선택 2 상자 높이를 변경하려면 어떻게 해야 합니까? (0) | 2023.08.28 |
| nodeJs 콜백 간단한 예 (0) | 2023.08.28 |
| CSS를 사용하여 텍스트 삽입 (0) | 2023.08.28 |




