无法验证 dex:错误的方法句柄类型 7

Failed to verify dex: Bad method handle type 7

我正在尝试创建一个测试示例,其中我将 TextView 的内容设置为存储在 IPFS 中的文件的内容。

我将此存储库用于我的函数:https://github.com/ipfs/java-ipfs-api

尽管在多个地方启用了 multidex,但我不断收到似乎是 multidex 的错误:

defaultConfig {
        applicationId "*****"
        minSdkVersion 26
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        **multiDexEnabled true**
    }

dependancies{
    implementation 'com.android.support:multidex:1.0.0'
}

MainActivity.java:

 @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

这是我遇到的错误:

FATAL EXCEPTION: main
                                                                          Process: com.lab1.ac01220.blossom, PID: 20807
                                                                          java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.lab1.ac01220.blossom/com.lab1.ac01220.blossom.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.lab1.ac01220.blossom.MainActivity" on path: DexPathList[[zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/base.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_dependencies_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_0_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_1_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_2_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_3_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_4_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_5_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_6_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_7_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_8_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/lib/x86, /system/lib, /vendor/lib]]
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2718)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                              at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                              at android.os.Looper.loop(Looper.java:164)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                           Caused by: java.lang.ClassNotFoundException: Didn't find class "com.lab1.ac01220.blossom.MainActivity" on path: DexPathList[[zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/base.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_dependencies_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_0_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_1_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_2_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_3_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_4_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_5_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_6_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_7_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_8_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/lib/x86, /system/lib, /vendor/lib]]
                                                                              at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
                                                                              at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                                                                              at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                              at android.app.Instrumentation.newActivity(Instrumentation.java:1173)
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2708)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
                                                                              at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
                                                                              at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                                              at android.os.Looper.loop(Looper.java:164) 
                                                                              at android.app.ActivityThread.main(ActivityThread.java:6541) 
                                                                              at java.lang.reflect.Method.invoke(Native Method) 
                                                                              at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
05-01 17:51:48.094 20807-20807/com.lab1.ac01220.blossom E/AndroidRuntime:   Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/app/AppCompatActivity;
                                                                              at java.lang.VMClassLoader.findLoadedClass(Native Method)
                                                                              at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
                                                                              at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
                                                                                    ... 12 more
                                                                           Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AppCompatActivity" on path: DexPathList[[zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/base.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_dependencies_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_0_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_1_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_2_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_3_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_4_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_5_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_6_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_7_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_8_apk.apk", zip file "/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/lib/x86, /system/lib, /vendor/lib]]
                                                                              at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
                                                                              at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                                                                              at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                                    ... 15 more
                                                                                Suppressed: java.io.IOException: Failed to open dex files from /data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_dependencies_apk.apk because: Failure to verify dex file '/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_dependencies_apk.apk': Bad method handle type 7
                                                                              at dalvik.system.DexFile.openDexFileNative(Native Method)
                                                                              at dalvik.system.DexFile.openDexFile(DexFile.java:353)
                                                                              at dalvik.system.DexFile.<init>(DexFile.java:100)
                                                                              at dalvik.system.DexFile.<init>(DexFile.java:74)
                                                                              at dalvik.system.DexPathList.loadDexFile(DexPathList.java:374)
                                                                              at dalvik.system.DexPathList.makeDexElements(DexPathList.java:337)
                                                                              at dalvik.system.DexPathList.<init>(DexPathList.java:157)
                                                                              at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
                                                                              at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
                                                                              at com.android.internal.os.PathClassLoaderFactory.createClassLoader(PathClassLoaderFactory.java:43)
                                                                              at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:69)
                                                                              at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:36)
                                                                              at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:676)
                                                                              at android.app.LoadedApk.getClassLoader(LoadedApk.java:709)
                                                                              at android.app.LoadedApk.getResources(LoadedApk.java:936)
                                                                              at android.app.ContextImpl.createAppContext(ContextImpl.java:2242)
                                                                              at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5672)
                                                                              at android.app.ActivityThread.-wrap1(Unknown Source:0)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
                                                                                        ... 6 more
                                                                            [CIRCULAR REFERENCE:java.io.IOException: Failed to open dex files from /data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_dependencies_apk.apk because: Failure to verify dex file '/data/app/com.lab1.ac01220.blossom-ixLs4xcrmWVVfgtCrH9vpw==/split_lib_dependencies_apk.apk': Bad method handle type 7]

这是我的代码:

TextView example = view.findViewById(R.id.example);
        IPFS ipfs = new IPFS("/ip4/127.0.0.1/tcp/4001");
        try {
            ipfs.refs.local();
            NamedStreamable.ByteArrayWrapper file = new NamedStreamable.ByteArrayWrapper("hello.txt", "G'day world! IPFS rocks!".getBytes());
            MerkleNode addResult = ipfs.add(file).get(0);
            Multihash filePointer = Multihash.fromBase58("QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB");
            byte[] fileContents = ipfs.cat(filePointer);
            this.example.setText(new String(fileContents));
        } catch (IOException e) {
            e.printStackTrace();
        }

编辑: 在我安装 jitpack 和 java-ipfs-api

之前我没有收到这个错误

您的代码无关紧要。错误是“无法打开 dex 文件 [...] 错误的方法句柄类型 7”。

MethodHandleType 在 art/libdexfile/dex/dex_file.h

中定义
  enum class MethodHandleType : uint16_t {  // private
    kStaticPut         = 0x0000,  // a setter for a given static field.
    kStaticGet         = 0x0001,  // a getter for a given static field.
    kInstancePut       = 0x0002,  // a setter for a given instance field.
    kInstanceGet       = 0x0003,  // a getter for a given instance field.
    kInvokeStatic      = 0x0004,  // an invoker for a given static method.
    kInvokeInstance    = 0x0005,  // invoke_instance : an invoker for a given instance method. This
                                  // can be any non-static method on any class (or interface) except
                                  // for “<init>”.
    kInvokeConstructor = 0x0006,  // an invoker for a given constructor.
    kInvokeDirect      = 0x0007,  // an invoker for a direct (special) method.
    kInvokeInterface   = 0x0008,  // an invoker for an interface method.
    kLast = kInvokeInterface
  };

因此,在您的情况下,您可以看到您的方法之一是 直接(特殊)方法的调用者(我猜它指的是 DMH). It was added in commit 631827d.

此时,我想知道您是否遇到了 java 8 支持的美术错误;因为预计在 dex 中成功脱糖的东西无法在艺术中执行。

刚遇到同样的问题,是因为某些库使用了Java 8个特征,你的情况应该是java-ipfs-api。为了解决这个问题,配置 Android Gradle 插件以支持 Java 8 通过将以下代码添加到您的 build.gradle 文件中,请务必使用最新的 Android gradle 插件:

android {
...
...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

解决方案取自 here