错误:仅从 Android O 开始支持 MethodHandle.invoke 和 MethodHandle.invokeExact (--min-api 26)

Posted

技术标签:

【中文标题】错误:仅从 Android O 开始支持 MethodHandle.invoke 和 MethodHandle.invokeExact (--min-api 26)【英文标题】:Erro: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26) 【发布时间】:2019-12-05 11:25:04 【问题描述】:

我有一个应用程序,当我将 android studio 更新到 3.4.2 版本并更新 gradle 时,我不得不强制更改一些库,例如使用 androidxappcomaptibility 和注释,无论如何,在那之后,同步的应用程序没有任何问题,但是当我想在设备上运行应用程序时,出现以下错误。我搜索了,我将 java 版本添加到 gradle 等但没有工作,我再次得到同样的错误。我该如何解决这个问题?

错误:MethodHandle.invoke 和 MethodHandle.invokeExact 仅支持从 Android O (--min-api 26) 开始

ORMDroid 库的gradle

buildscript 
ext.java_version = JavaVersion.VERSION_1_8
repositories 
    jcenter()
    google()

dependencies 
    classpath 'com.android.tools.build:gradle:3.4.2'
    classpath 'com.google.gms:google-services:4.0.2'


apply plugin: 'android-library'

dependencies 
implementation fileTree(dir: 'libs', include: '*.jar')


android 

compileOptions 
    sourceCompatibility java_version
    targetCompatibility java_version

compileSdkVersion 16
buildToolsVersion '28.0.3'

sourceSets 
    main 
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    

    // Move the tests to tests/java, tests/res, etc...
    androidTest.setRoot('tests')

    // Move the build types to build-types/<type>
    // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
    // This moves them out of them default location under src/<type>/... which would
    // conflict with src/ being used by the main source set.
    // Adding new build types or product flavors should be accompanied
    // by a similar customization.
    debug.setRoot('build-types/debug')
    release.setRoot('build-types/release')

defaultConfig 
    minSdkVersion  16



repositories 
google()

gradle 我的申请:

    buildscript 
    ext.java_version = JavaVersion.VERSION_1_8
    repositories 
        jcenter()
        google()
        maven
            url 'https://maven.fabric.io/public'
        
    
    dependencies 
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath 'com.google.gms:google-services:4.0.2'
        classpath 'io.fabric.tools:gradle:1.30.0'
    



apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'

dependencies 
    //implementation 'com.google.firebase:firebase-core:11.0.4'
    implementation fileTree(include: '*.jar', dir: 'libs')
    implementation project(':ORMDroid')
    implementation 'com.android.support:support-v4:29.1.0'
    implementation 'com.android.support:cardview-v7:29.1.0'
    implementation files('libs/javax.mail.jar')
    implementation files('libs/additionnal.jar')
    implementation files('libs/activation.jar')
    implementation 'com.android.support:appcompat-v7:29.1.0'
    implementation 'com.android.support:support-compat:29.1.0'
    //noinspection GradleCompatible
    //implementation 'com.google.android.ginstrumentTestms:play-services-maps:15.0.1'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'com.google.android.gms:play-services-location:15.0.1'
    implementation 'com.google.firebase:firebase-messaging:17.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'

    implementation 'com.android.support:support-annotations:29.1.0'
    implementation 'org.codehaus.groovy:groovy-all:2.4.15'


android 
    compileSdkVersion 29
    buildToolsVersion '28.0.3'
    compileOptions 
        sourceCompatibility java_version
        targetCompatibility java_version
    

    sourceSets 
        main 
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        

        // Move the tests to tests/java, tests/res, etc...
        androidTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instancem, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    
    defaultConfig 
        applicationId 'com.test.test'
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 104
        versionName "1.0.4"
    



//apply plugin: 'com.google.gms.google-services'
allprojects 
    repositories 
        google()
        maven 
            url 'https://maven.google.com/'
        
    

【问题讨论】:

【参考方案1】:

不确定这是否仍然相关,但在这种情况下,您只需要更新您的 gradles 中的 minSdkVersion。

Android O 要求 minSdkVersion 为 26,因此您可以这样更新。

minSdkVersion 26

【讨论】:

以上是关于错误:仅从 Android O 开始支持 MethodHandle.invoke 和 MethodHandle.invokeExact (--min-api 26)的主要内容,如果未能解决你的问题,请参考以下文章

仅从 Android 7.0 (Nougat) 开始支持默认接口方法

仅从 Android N 开始支持静态接口方法(--min-api 24)[重复]

Android权限gven仅从最低sdk版本开始

Android studio“MethodHandle.invoke 和 MethodHandle.invokeExact 仅支持从 Android O (--min-api 26) 开始”构建 AP

从 Android N (--min-api 24) 开始支持:okhttp3.Request okhttp3.Authenticator

仅从 Xamarin Android 中的 GPS 传感器检索位置信息