com.android.tools.r8.errors.a:仅从Android O开始支持MethodHandle.invoke和MethodHandle.invokeExact

如何解决com.android.tools.r8.errors.a:仅从Android O开始支持MethodHandle.invoke和MethodHandle.invokeExact

我正在开发android本机应用程序,我为他们准备了一个库项目,其中包含这些应用程序的所有常用工具。 我正在用jfrog制品导入我的库,并且运行良好;现在,我想使用 git和sub-module 将我的库作为模块包含在我的项目中 ,以便能够同时在应用程序和库上工作。 但是现在(在我的包含两个模块(应用程序和库)的项目中),构建失败... 在尝试向这里寻求帮助之前,我已经尝试了很多事情……我认为问题来自两个模块之间的重复依赖关系,因为没有库子模块的构建就可以。

这是堆栈跟踪的开始:

C:\Users\sri\.gradle\caches\transforms-2\files-2.1\841047937c984e1ac263db2768d03619\jetified-objenesis-3.0.1.jar: D8: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)
Stack trace:
com.android.tools.r8.errors.a: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)
        at com.android.tools.r8.errors.a.a(:7)
...........
//end 
* What went wrong:
Execution failed for task ':app:dexBuilderDebug'.
> There was a failure while executing work items
   > A failure occurred while executing com.android.build.gradle.internal.dexing.DexWorkAction
      > Failed to process: C:\Users\sri\.gradle\caches\transforms-2\files-2.1\841047937c984e1ac263db2768d03619\jetified-objenesis-3.0.1.jar

1。应用程序build.gradle文件

顶级:

buildscript {
    ext.versions = [
            'kotlin'            : '1.4.0','powermock'         : '2.0.7','constraintLayout'  : '2.0.0','butterknife'       : '10.2.3','jsonwebtoken'      : '0.10.7','retrofit'          : '2.9.0','supportLibrary'    : '1.1.0','module'            : '3.5.10','okhttp'            : '4.8.1','mockito'           : '3.3.3','lifecycleVersion'  : '2.2.0','junit'             : '4.13','eventBus'          : '3.2.0','picasso'           : '2.71828','swipeRefreshLayout': '1.1.0','cardView'          : '1.0.0','viewPager'         : '1.0.0','material'          : '1.3.0-alpha02','rxjava'            : '3.0.4','rxandroid'         : '3.0.0','spoon'             : '1.7.1'
    ]
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
        classpath "io.realm:realm-gradle-plugin:7.0.1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.0'
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

应用程序级别:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.firebase.crashlytics'

//.. signing removed ... //

android {
    signingConfigs {
        //........
    }
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com......."
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 42
        versionName versionProperties['versionName']
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        ndk.abiFilters 'arm64-v8a','armeabi-v7a','x86','x86_64'

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
        debug {
            applicationIdSuffix ".debug"
            versionNameSuffix '-debug'
        }
    }
    lintOptions {
        abortOnError false
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildFeatures {
        viewBinding true
        dataBinding true
    }
    configurations {
        all*.exclude group: 'xmlpull',module: 'xmlpull'
        all*.exclude group: 'xpp3',module: 'xpp3_min'
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'],dir: 'libs')
    androidTestImplementation('androidx.test.espresso:espresso-core:3.3.0-rc03',{
        exclude group: 'com.android.support',module: 'support-annotations'
    })
    implementation project(':mob-android-qualiacmodule:qualiac-module')
    implementation "androidx.appcompat:appcompat:1.2.0"
    implementation "com.google.android.material:material:${versions.material}"
    implementation "androidx.constraintlayout:constraintlayout:${versions.constraintLayout}"
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:${versions.swipeRefreshLayout}"
    implementation "androidx.cardview:cardview:${versions.cardView}"
    implementation 'androidx.annotation:annotation:1.1.0'
    implementation 'com.google.firebase:firebase-analytics:17.5.0'
    implementation 'com.google.firebase:firebase-crashlytics:17.2.1'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'

    implementation 'com.google.firebase:firebase-ml-vision:24.1.0'
    implementation 'com.google.android.gms:play-services-vision-image-label:18.0.5'
    implementation 'com.google.android.gms:play-services-vision-common:19.1.1'
    implementation 'com.google.android.gms:play-services-vision:20.1.1'

    kapt "com.jakewharton:butterknife-compiler:${versions.butterknife}"
    implementation "com.jakewharton:butterknife:${versions.butterknife}"
    implementation "com.squareup.retrofit2:retrofit:${versions.retrofit}"
    implementation "com.squareup.retrofit2:converter-gson:${versions.retrofit}"
    implementation "com.squareup.retrofit2:adapter-rxjava2:${versions.retrofit}"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}"
    implementation "com.squareup.okhttp3:logging-interceptor:${versions.okhttp}"
    implementation "com.squareup.okhttp3:mockwebserver:${versions.okhttp}"
    implementation "com.squareup.okhttp3:okhttp:${versions.okhttp}"
    implementation "org.greenrobot:eventbus:${versions.eventBus}"
    implementation "io.reactivex.rxjava3:rxjava:${versions.rxjava}"
    implementation "io.reactivex.rxjava3:rxandroid:${versions.rxandroid}"

    implementation "com.squareup.picasso:picasso:${versions.picasso}"
    implementation 'com.jakewharton.timber:timber:4.7.1'
    implementation "androidx.core:core-ktx:1.3.1"
    implementation "android.arch.lifecycle:extensions:1.1.1"
    api 'com.google.guava:guava:29.0-jre'
    implementation "androidx.viewpager2:viewpager2:${versions.viewPager}"
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
    // ViewModel
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:${versions.lifecycleVersion}"
    // LiveData
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:${versions.lifecycleVersion}"
    // alternately - if using Java8,use the following instead of lifecycle-compiler
    implementation "androidx.lifecycle:lifecycle-common-java8:${versions.lifecycleVersion}"

    testImplementation 'junit:junit:4.13'

    androidTestImplementation "com.squareup.spoon:spoon-client:${versions.spoon}"
    androidTestImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-rc03'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test:rules:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.3.0-rc03'
}

kapt {
    generateStubs = true
}

android.applicationVariants.all { variant ->
    variant.outputs.all {
        def appName = "jobs"
        outputFileName = variant.name == "debug" ? "app-debug.apk" : "${appName}-${variant.name}-${variant.versionName}.apk"
    }
}

apply plugin: 'com.google.gms.google-services'

2。库build.gradle文件

//顶级

buildscript {
    ext.versions = [
            'kotlin'            : '1.3.72',......
    ]
    repositories {
        jcenter()
        google()
        mavenCentral()
    }
    dependencies {
        classpath "io.realm:realm-gradle-plugin:7.0.1"
        classpath 'com.android.tools.build:gradle:4.0.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.android.support:support-v4:28.0.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.15.2"

    }
}
allprojects {

    repositories {
        jcenter()
        google()
        mavenCentral()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

//库级别

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
apply plugin: 'kotlin-android-extensions'

def libraryVersion = '3.5.10'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        ndk.abiFilters 'arm64-v8a','x86_64'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
        }
    }

    lintOptions {
        abortOnError false
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    viewBinding {
        enabled = true
    }
    dataBinding {
        enabled = true
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'],module: 'support-annotations'
    })
    implementation "androidx.appcompat:appcompat:${versions.supportLibrary}"
    implementation "com.google.android.material:material:${versions.material}"
    implementation "androidx.constraintlayout:constraintlayout:${versions.constraintLayout}"
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:${versions.swipeRefreshLayout}"

    implementation 'com.google.firebase:firebase-ml-vision:24.0.3'
    implementation 'com.google.android.gms:play-services-vision-image-label:18.0.5'
    implementation 'com.google.android.gms:play-services-vision-common:19.1.1'
    implementation 'com.google.android.gms:play-services-vision:20.1.1'

    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation "androidx.cardview:cardview:${versions.cardView}"
    api 'com.google.firebase:firebase-core:17.4.4'
    implementation "com.squareup.retrofit2:retrofit:${versions.retrofit}"
    implementation "com.squareup.retrofit2:converter-gson:${versions.retrofit}"
    implementation "com.squareup.retrofit2:adapter-rxjava2:${versions.retrofit}"
    implementation "com.squareup.retrofit2:retrofit-mock:${versions.retrofit}"
    implementation "org.greenrobot:eventbus:${versions.eventBus}"
    api "com.squareup.okhttp3:logging-interceptor:${versions.okhttp}"
    implementation "com.squareup.okhttp3:mockwebserver:${versions.okhttp}"
    implementation "com.squareup.okhttp3:okhttp:${versions.okhttp}"
    api "io.jsonwebtoken:jjwt-api:${versions.jsonwebtoken}"
    runtimeOnly "io.jsonwebtoken:jjwt-impl:${versions.jsonwebtoken}"
    runtimeOnly("io.jsonwebtoken:jjwt-orgjson:${versions.jsonwebtoken}") {
        exclude group: 'org.json',module: 'json'
    }
    implementation "com.squareup.picasso:picasso:${versions.picasso}"
    implementation "io.reactivex.rxjava3:rxjava:${versions.rxjava}"
    implementation "io.reactivex.rxjava3:rxandroid:${versions.rxandroid}"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}"
    implementation "androidx.core:core-ktx:1.3.1"

    testImplementation "junit:junit:${versions.junit}"
    implementation "org.powermock:powermock-module-junit4:${versions.powermock}"
    implementation "org.powermock:powermock-module-junit4-rule:${versions.powermock}"
    implementation "org.powermock:powermock-api-mockito2:${versions.powermock}"
    implementation "org.powermock:powermock-classloading-xstream:${versions.powermock}"
    testImplementation 'org.mockito:mockito-core:3.4.6'

    implementation 'androidx.test:core:1.2.0'
    implementation 'androidx.test.ext:junit:1.1.1'
    implementation 'androidx.test:runner:1.2.0'
    implementation 'androidx.test:rules:1.2.0'
    implementation "androidx.test.espresso:espresso-core:${versions.espresso}"
    implementation "androidx.test.espresso:espresso-contrib:${versions.espresso}"
    implementation "com.squareup.spoon:spoon-client:${versions.spoon}"
    implementation "androidx.viewpager2:viewpager2:${versions.viewPager}"
    // ViewModel
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:${versions.lifecycleVersion}"
    // LiveData
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:${versions.lifecycleVersion}"
    // alternately - if using Java8,use the following instead of lifecycle-compiler
    implementation "androidx.lifecycle:lifecycle-common-java8:${versions.lifecycleVersion}"

    androidTestImplementation 'androidx.test:core:1.2.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test:rules:1.2.0'
    androidTestImplementation "androidx.test.espresso:espresso-contrib:${versions.espresso}"

    api 'com.google.guava:guava:29.0-jre'
    implementation "androidx.lifecycle:lifecycle-extensions:${versions.lifecycleVersion}"

}

解决方法

我找到了解决方法:

使用命令gradlew :app:dependencies,我发现导致问题的依赖项(org.objenesis:objenesis:2.6)被我的一个依赖项使用:org.powermock:powermock-api-mockito2:2.0.7。这是一个依赖项,我只用一次进行测试,而且可以用另一遍(我已经使用过)代替它做同样的事情,因此我决定删除此依赖项,现在效果很好!

结论:使用此命令可以确定哪个库正在使用引起该问题的.jar,并查看该库对您是否真的有用。

gradlew :<yourmodule>:dependencies 
,

错误消息

MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)

由输入程序使用其中一种方法(MethodHandle.invokeMethodHandle.invokeExact)引起。

以下代码对此进行了演示:

        try {
            MethodHandles.Lookup lookup = MethodHandles.publicLookup();
            MethodType methodType = MethodType.methodType(String.class,char.class,char.class);
            MethodHandle replaceMethodHandle =
                lookup.findVirtual(String.class,"replace",methodType);

            String output = (String) replaceMethodHandle.invoke("jovo",'o','a');
            System.out.println(output);
        } catch (Throwable e) {
            System.out.println("Exception from MethodHandle code " + e);
        }

如果项目minSdkLevel为26或更高版本,则此代码可以正常运行。在MIN_SDK级检查下,不可能有这样的代码,因为Android代码需要仅Android O支持的DEX代码版本。

您将需要确定像哪种使用MethodHandle的输入。

请注意,如果受攻击的调试设备运行的是Android O或更高版本,则在Android Studio中进行调试时,此代码将有效。这是由于Android Studio注入了用于调试版本的附加调试设备的API级别,从而覆盖了为项目配置的minSdkLevel

,

我的解决方案是在build.gradle的末尾添加以下几行

allprojects {
    configurations.all {
        resolutionStrategy.force 'org.objenesis:objenesis:2.6'
    }
}

感谢https://github.com/mockito/mockito/issues/2007

,

如果您使用 mockk,可能会发生此错误。

如果是,请替换:

androidTestImplementation group: 'io.mockk',name: 'mockk',version: mockk_version

作者:

androidTestImplementation group: 'io.mockk',name: 'mockk-android',version: mockk_version

https://github.com/mockk/mockk/issues/281#issuecomment-642176970

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-