没有静态方法metafactory(OptaPlanner)

huangapple go评论72阅读模式
英文:

No static method metafactory (OptaPlanner)

问题

最近我在我的 build.gradle 文件中添加了 OptaPlanner 的依赖,以便使用该库的车辆路径问题功能。当我尝试使用求解器时,我收到了以下错误:

java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.art/javalib/core-oj.jar)

我已经搜索过,并发现我需要在 build.gradle 中启用 JDK 1.8,我已经这样做了,但问题似乎仍未解决。我也附上了 build.gradle 文件。有任何建议吗?(我正在使用 Android Studio)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
    defaultConfig {
        applicationId "com.example.groceryrouter"
        minSdkVersion 26
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    // ... 其他配置 ...

}

dependencies {
    // ... 其他依赖 ...

    implementation 'org.optaplanner:optaplanner-core:7.36.0.20200331' {
        exclude group: 'xmlpull'
        exclude group: 'org.drools'
        // todo exclude, didn't work on optaplanner 6.1.0
        //exclude group: 'org.kie'
    }

    // ... 其他依赖 ...
}
英文:

Recently I added OptaPlanner dependency to my build.gradle in order to use the Vehicle Routing Problem of the Library. When I tried to use the solver I received the following error

java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.art/javalib/core-oj.jar)

I have google and found that I need to enable JDK 1.8 for the same which I have done in the build.gradle however it still doesn't seem to go away. I am attaching the build.gradle file as well. Any suggestions ? (I am using Android-Studio)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
    defaultConfig {
        applicationId "com.example.groceryrouter"
        minSdkVersion 26
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }


    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/kie.conf'
        exclude 'META-INF/ErraiApp.properties'
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation group: 'com.jtransc', name: 'jtransc-rt', version: '0.6.8'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation "androidx.cardview:cardview:1.0.0"
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'androidx.navigation:navigation-fragment:2.2.1'
    implementation 'androidx.navigation:navigation-ui:2.2.1'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.google.gms:google-services:4.3.3'
    implementation 'com.google.android.gms:play-services-auth:18.0.0'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha02'
    implementation 'com.google.android.libraries.places:places:2.2.0'
    // https://mvnrepository.com/artifact/commons-io/commons-io
    implementation group: 'commons-io', name: 'commons-io', version: '20030203.000550'
    implementation('org.optaplanner:optaplanner-core:7.36.0.20200331') {
        exclude group: 'xmlpull'
        exclude group: 'org.drools'
        // todo exclude, didn't work on optaplanner 6.1.0
        //exclude group: 'org.kie'
    }
    // Required -- JUnit 4 framework
    testImplementation 'junit:junit:4.12'
    // Optional -- Robolectric environment
    testImplementation 'androidx.test:core:1.0.0'
    // Optional -- Mockito framework
    testImplementation 'org.mockito:mockito-core:1.10.19'
    implementation "org.slf4j:slf4j-simple:1.7.9"
}

答案1

得分: 0

我推测你正在使用getter注解。请改为使用字段注解。

这是我们所做的改进,使用MethodHandles而不是反射来调用getter方法,速度更快,但在Android和Graal上存在兼容性问题。

英文:

I presume you're using getter annotations. Use field annotations instead.

It's an improvement we made to use MethodHandles instead of reflection to call getters, and they are faster, but it has compatibility issues on Android and Graal.

答案2

得分: 0

在应用的build.gradle中添加以下代码:

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }
}
英文:

In the app's build.gradle add this code

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }
}

huangapple
  • 本文由 发表于 2020年4月10日 00:30:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/61125845.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定