Trying to run Spark in Android: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O

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

Trying to run Spark in Android: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O

问题

以下是翻译好的内容:

我需要在 Android 中生成一个 Webhook URL。最初我尝试了 Spring Framework,但实现起来似乎相当困难,我只想公开一个单一的 Webhook URL,所以我寻找了一个轻量级的框架。我现在尝试使用 [spark-java][1],但我无法让它运行起来。

错误信息:

    被压制的异常:java.util.concurrent.ExecutionException: com.android.tools.r8.errors.a: MethodHandle.invoke 和 MethodHandle.invokeExact 仅支持从 Android O 开始(--min-api 26)
        at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:552)
        at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:513)
        at com.google.common.util.concurrent.FluentFuture$TrustedFuture.get(FluentFuture.java:86)
        at com.android.tools.r8.utils.U0.a(:14)
        at com.android.tools.r8.utils.U0.a(:9)
        ... 114 more
    [循环引用:com.android.tools.r8.errors.a: MethodHandle.invoke 和 MethodHandle.invokeExact 仅支持从 Android O 开始(--min-api 26)]
Caused by: com.android.tools.r8.a: MethodHandle.invoke 和 MethodHandle.invokeExact 仅支持从 Android O 开始(--min-api 26)

这是我的 build.gradle 文件:

plugins {
    id 'com.android.application'
//    id 'org.springframework.boot' version '2.3.3.RELEASE'
//    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}
//apply plugin: 'com.android.application'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.fivefaces.tauri"
        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'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.navigation:navigation-fragment:2.1.0'
    implementation 'androidx.navigation:navigation-ui:2.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    compileOnly 'org.projectlombok:lombok:1.18.12'
    annotationProcessor 'org.projectlombok:lombok:1.18.12'

    testCompileOnly 'org.projectlombok:lombok:1.18.12'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
    // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.0.1'
    compile "com.sparkjava:spark-core:2.9.2"
}

* Gradle 版本为 6.6.1
* 在 `项目结构` 中,我已经检查了定义的 Java SDK,它正确地设置为 1.8
* 我使用的最小 Android SDK 是 API 16

  [1]: http://sparkjava.com/documentation#routes
英文:

I need to generate a webhook url in android. Initially I tried Spring Framework, but it seems quite difficult to implement and I'm just looking to expose a single webhook url so I looked for a lightweight framework. I've now been trying to use spark-java, but I can't get it to run.

Error:

	Suppressed: java.util.concurrent.ExecutionException: com.android.tools.r8.errors.a: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)
		at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:552)
		at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:513)
		at com.google.common.util.concurrent.FluentFuture$TrustedFuture.get(FluentFuture.java:86)
		at com.android.tools.r8.utils.U0.a(:14)
		at com.android.tools.r8.utils.U0.a(:9)
		... 114 more
	[CIRCULAR REFERENCE:com.android.tools.r8.errors.a: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)]
Caused by: com.android.tools.r8.a: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)

And here's my build.gradle file:

plugins {
    id 'com.android.application'
//    id 'org.springframework.boot' version '2.3.3.RELEASE'
//    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}
//apply plugin: 'com.android.application'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.fivefaces.tauri"
        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'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.navigation:navigation-fragment:2.1.0'
    implementation 'androidx.navigation:navigation-ui:2.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    compileOnly 'org.projectlombok:lombok:1.18.12'
    annotationProcessor 'org.projectlombok:lombok:1.18.12'

    testCompileOnly 'org.projectlombok:lombok:1.18.12'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
    // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.0.1'
    compile "com.sparkjava:spark-core:2.9.2"


}
  • Gradle version is 6.6.1

  • In Project Structure, I already checked the defined Java SDK and it's correctly set to 1.8

  • Minimum Android SDK I'm using is API 16

答案1

得分: 0

我已经能够在Android上运行一个Spark服务器。以下是我的build.gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.mycom.appname"
        minSdkVersion 27
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation 'com.sparkjava:spark-core:2.9.2'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

我们都在使用Spark 2.9.2版本。我对gradle不是太熟悉,但我注意到表明依赖关系的方式有所不同(compile "com.sparkjava:spark-core:2.9.2"与implementation 'com.sparkjava:spark-core:2.9.2')。

英文:

I've been able to run a Spark server on Android. Here is my build.gradle.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.mycom.appname"
        minSdkVersion 27
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation 'com.sparkjava:spark-core:2.9.2'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

We are both using Spark 2.9.2. I'm not too familiar with gradle but I notice that the way we indicate the dependency on it is different (compile "com.sparkjava:spark-core:2.9.2" vs. implementation 'com.sparkjava:spark-core:2.9.2').

huangapple
  • 本文由 发表于 2020年8月26日 08:51:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/63588999.html
匿名

发表评论

匿名网友

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

确定