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

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

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

问题

以下是翻译好的内容:

  1. 我需要在 Android 中生成一个 Webhook URL。最初我尝试了 Spring Framework,但实现起来似乎相当困难,我只想公开一个单一的 Webhook URL,所以我寻找了一个轻量级的框架。我现在尝试使用 [spark-java][1],但我无法让它运行起来。
  2. 错误信息:
  3. 被压制的异常:java.util.concurrent.ExecutionException: com.android.tools.r8.errors.a: MethodHandle.invoke MethodHandle.invokeExact 仅支持从 Android O 开始(--min-api 26
  4. at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:552)
  5. at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:513)
  6. at com.google.common.util.concurrent.FluentFuture$TrustedFuture.get(FluentFuture.java:86)
  7. at com.android.tools.r8.utils.U0.a(:14)
  8. at com.android.tools.r8.utils.U0.a(:9)
  9. ... 114 more
  10. [循环引用:com.android.tools.r8.errors.a: MethodHandle.invoke MethodHandle.invokeExact 仅支持从 Android O 开始(--min-api 26)]
  11. Caused by: com.android.tools.r8.a: MethodHandle.invoke MethodHandle.invokeExact 仅支持从 Android O 开始(--min-api 26
  12. 这是我的 build.gradle 文件:
  13. plugins {
  14. id 'com.android.application'
  15. // id 'org.springframework.boot' version '2.3.3.RELEASE'
  16. // id 'io.spring.dependency-management' version '1.0.10.RELEASE'
  17. }
  18. //apply plugin: 'com.android.application'
  19. android {
  20. compileSdkVersion 30
  21. buildToolsVersion "30.0.2"
  22. defaultConfig {
  23. applicationId "com.fivefaces.tauri"
  24. minSdkVersion 16
  25. targetSdkVersion 30
  26. versionCode 1
  27. versionName "1.0"
  28. testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  29. }
  30. buildTypes {
  31. release {
  32. minifyEnabled false
  33. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  34. }
  35. }
  36. compileOptions {
  37. sourceCompatibility JavaVersion.VERSION_1_8
  38. targetCompatibility JavaVersion.VERSION_1_8
  39. }
  40. }
  41. dependencies {
  42. implementation fileTree(dir: "libs", include: ["*.jar"])
  43. implementation 'androidx.appcompat:appcompat:1.1.0'
  44. implementation 'com.google.android.material:material:1.0.0'
  45. implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
  46. implementation 'androidx.navigation:navigation-fragment:2.1.0'
  47. implementation 'androidx.navigation:navigation-ui:2.1.0'
  48. testImplementation 'junit:junit:4.12'
  49. androidTestImplementation 'androidx.test.ext:junit:1.1.1'
  50. androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
  51. compileOnly 'org.projectlombok:lombok:1.18.12'
  52. annotationProcessor 'org.projectlombok:lombok:1.18.12'
  53. testCompileOnly 'org.projectlombok:lombok:1.18.12'
  54. testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
  55. // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
  56. compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.0.1'
  57. compile "com.sparkjava:spark-core:2.9.2"
  58. }
  59. * Gradle 版本为 6.6.1
  60. * `项目结构` 中,我已经检查了定义的 Java SDK,它正确地设置为 1.8
  61. * 我使用的最小 Android SDK API 16
  62. [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:

  1. 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)
  2. at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:552)
  3. at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:513)
  4. at com.google.common.util.concurrent.FluentFuture$TrustedFuture.get(FluentFuture.java:86)
  5. at com.android.tools.r8.utils.U0.a(:14)
  6. at com.android.tools.r8.utils.U0.a(:9)
  7. ... 114 more
  8. [CIRCULAR REFERENCE:com.android.tools.r8.errors.a: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)]
  9. 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:

  1. plugins {
  2. id 'com.android.application'
  3. // id 'org.springframework.boot' version '2.3.3.RELEASE'
  4. // id 'io.spring.dependency-management' version '1.0.10.RELEASE'
  5. }
  6. //apply plugin: 'com.android.application'
  7. android {
  8. compileSdkVersion 30
  9. buildToolsVersion "30.0.2"
  10. defaultConfig {
  11. applicationId "com.fivefaces.tauri"
  12. minSdkVersion 16
  13. targetSdkVersion 30
  14. versionCode 1
  15. versionName "1.0"
  16. testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  17. }
  18. buildTypes {
  19. release {
  20. minifyEnabled false
  21. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  22. }
  23. }
  24. compileOptions {
  25. sourceCompatibility JavaVersion.VERSION_1_8
  26. targetCompatibility JavaVersion.VERSION_1_8
  27. }
  28. }
  29. dependencies {
  30. implementation fileTree(dir: "libs", include: ["*.jar"])
  31. implementation 'androidx.appcompat:appcompat:1.1.0'
  32. implementation 'com.google.android.material:material:1.0.0'
  33. implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
  34. implementation 'androidx.navigation:navigation-fragment:2.1.0'
  35. implementation 'androidx.navigation:navigation-ui:2.1.0'
  36. testImplementation 'junit:junit:4.12'
  37. androidTestImplementation 'androidx.test.ext:junit:1.1.1'
  38. androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
  39. compileOnly 'org.projectlombok:lombok:1.18.12'
  40. annotationProcessor 'org.projectlombok:lombok:1.18.12'
  41. testCompileOnly 'org.projectlombok:lombok:1.18.12'
  42. testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
  43. // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
  44. compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.0.1'
  45. compile "com.sparkjava:spark-core:2.9.2"
  46. }
  • 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文件:

  1. apply plugin: 'com.android.application'
  2. android {
  3. compileSdkVersion 29
  4. buildToolsVersion "29.0.3"
  5. defaultConfig {
  6. applicationId "com.mycom.appname"
  7. minSdkVersion 27
  8. targetSdkVersion 29
  9. versionCode 1
  10. versionName "1.0"
  11. testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  12. }
  13. buildTypes {
  14. release {
  15. minifyEnabled false
  16. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  17. }
  18. }
  19. compileOptions {
  20. sourceCompatibility = 1.8
  21. targetCompatibility = 1.8
  22. }
  23. }
  24. dependencies {
  25. implementation fileTree(dir: 'libs', include: ['*.jar'])
  26. implementation 'androidx.appcompat:appcompat:1.0.2'
  27. implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
  28. implementation 'com.sparkjava:spark-core:2.9.2'
  29. testImplementation 'junit:junit:4.12'
  30. androidTestImplementation 'androidx.test.ext:junit:1.1.1'
  31. androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
  32. }

我们都在使用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.

  1. apply plugin: 'com.android.application'
  2. android {
  3. compileSdkVersion 29
  4. buildToolsVersion "29.0.3"
  5. defaultConfig {
  6. applicationId "com.mycom.appname"
  7. minSdkVersion 27
  8. targetSdkVersion 29
  9. versionCode 1
  10. versionName "1.0"
  11. testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  12. }
  13. buildTypes {
  14. release {
  15. minifyEnabled false
  16. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  17. }
  18. }
  19. compileOptions {
  20. sourceCompatibility = 1.8
  21. targetCompatibility = 1.8
  22. }
  23. }
  24. dependencies {
  25. implementation fileTree(dir: 'libs', include: ['*.jar'])
  26. implementation 'androidx.appcompat:appcompat:1.0.2'
  27. implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
  28. implementation 'com.sparkjava:spark-core:2.9.2'
  29. testImplementation 'junit:junit:4.12'
  30. androidTestImplementation 'androidx.test.ext:junit:1.1.1'
  31. androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
  32. }

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:

确定