问题
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:
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.
来源:https://stackoverflow.com/questions/61125845/no-static-method-metafactory-optaplanner