Tôi có vấn đề lạ và không biết cách giải quyết nó.Lỗi xây dựng Gradle: không thể truy cập tệp lớp tồi tệ nhất ITest: phương thức mặc định ITest.class được tìm thấy trong phiên bản 50.0 classfile
Tôi có một giao diện với phương pháp mặc định, như thế này:
public interface ITest{
default String getText(){
return "ITest";
}
}
và lớp mà thực hiện giao diện này, như thế này:
public class TestClasssss implements ITest{
private String text;
}
Và tôi cố gắng sử dụng lớp này bên trong đơn vị ứng dụng của tôi dự án thử nghiệm.
Vì vậy, nếu tôi sao chép các lớp học này bên trong dự án đơn vị thử nghiệm Android của tôi nó biên dịch ok và tất cả làm việc như mong đợi, tuy nhiên nếu lớp này và giao diện khai báo trong thư mục nguồn ứng dụng, ứng dụng không biên dịch và va chạm với
Error:(30, 10) error: cannot access ITest bad class file: ~\ITest.class
default method found in version 50.0 classfile
Please remove or make sure it appears in the correct subdirectory of the classpath.
Vì vậy, làm cách nào để khắc phục hành vi kỳ lạ này?
cấu hình graddle của tôi trông như thế này:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
}
}
repositories {
mavenCentral()
mavenLocal()
maven {
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
jcenter()
}
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'realm-android'
apply plugin: 'com.neenbedankt.android-apt'
apt {
arguments {
androidManifestFile variant.outputs[0]?.processResources?.manifestFile
}
}
android {
compileSdkVersion 24
buildToolsVersion '24.0.1'
defaultConfig {
applicationId "io.projectname"
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
}
testOptions {
unitTests.returnDefaultValues = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dataBinding {
enabled = true
}
sourceSets {
main {
res.srcDirs =
[
'src/main/res/controls',
'src/main/res/fragments',
'src/main/res/activities',
'src/main/res/views',
'src/main/res'
]
}
}
}
ext {
JUNIT_VERSION = '4.12'
DAGGER_VERSION = '2.2'
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.0.111-beta'
testCompile "org.robolectric:robolectric:3.1.1"
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile 'com.roughike:bottom-bar:1.3.4'
compile 'com.aurelhubert:ahbottomnavigation:1.2.3'
compile 'joda-time:joda-time:2.9.4'
compile 'com.annimon:stream:1.0.9'
compile 'com.kyleduo.switchbutton:library:1.4.1'
compile 'io.reactivex:rxandroid:1.2.0'
compile 'io.reactivex:rxjava:1.1.5'
compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'
compile('eu.davidea:flexible-adapter:5.0.0-SNAPSHOT') {
changing = true
}
compile 'com.github.aakira:expandable-layout:[email protected]'
compile "cn.aigestudio.wheelpicker:WheelPicker:1.1.2"
compile 'net.sf.biweekly:biweekly:0.5.0'
//Dagger dependencies started
compile "com.google.dagger:dagger:$DAGGER_VERSION"
apt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
provided 'javax.annotation:jsr250-api:1.0'
compile 'javax.inject:javax.inject:1'
testCompile "junit:junit:$JUNIT_VERSION"
testApt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
//Dagger dependencies finished
provided 'org.projectlombok:lombok:1.16.10'
}
Mã này không biên dịch chỉ khi TestClassss được sử dụng trong các thử nghiệm, nếu bạn xóa nó khỏi biên dịch dự án thử nghiệm một cách chính xác, tôi có đúng không? – Ph0en1x
Với ví dụ giả này - vâng, đúng vậy. Nhưng trong trường hợp thực sự nó không thành công chỉ khi tôi cố gắng truy cập các phương thức từ giao diện hoặc nếu cố gắng tạo ra một mô hình cho những lớp đó. –
@silent_coder Bạn có sử dụng retrolambda trong dự án của mình không? –