简体   繁体   中英

transformClassesWithDesugarForDebug build error when importing my custom Android Library

I'm trying to import a custom library to a freshly created project, but when I try to build it I get the next error:

Exception in thread "main" java.lang.TypeNotPresentException: Type org.openjdk.jdi.ReferenceType not present
    at sun.invoke.util.BytecodeDescriptor.parseSig(BytecodeDescriptor.java:85)
    at sun.invoke.util.BytecodeDescriptor.parseMethod(BytecodeDescriptor.java:63)
    at sun.invoke.util.BytecodeDescriptor.parseMethod(BytecodeDescriptor.java:41)
    at java.lang.invoke.MethodType.fromMethodDescriptorString(MethodType.java:1067)
    at com.google.devtools.build.android.desugar.LambdaDesugaring$InvokedynamicRewriter.toMethodHandle(LambdaDesugaring.java:599)
    at com.google.devtools.build.android.desugar.LambdaDesugaring$InvokedynamicRewriter.toJvmMetatype(LambdaDesugaring.java:586)
    at com.google.devtools.build.android.desugar.LambdaDesugaring$InvokedynamicRewriter.visitInvokeDynamicInsn(LambdaDesugaring.java:401)
    at org.objectweb.asm.MethodVisitor.visitInvokeDynamicInsn(Unknown Source)
    at org.objectweb.asm.MethodVisitor.visitInvokeDynamicInsn(Unknown Source)
    at org.objectweb.asm.ClassReader.a(Unknown Source)
    at org.objectweb.asm.ClassReader.b(Unknown Source)
    at org.objectweb.asm.ClassReader.accept(Unknown Source)
    at org.objectweb.asm.ClassReader.accept(Unknown Source)
    at com.google.devtools.build.android.desugar.Desugar.desugarClassesInInput(Desugar.java:401)
    at com.google.devtools.build.android.desugar.Desugar.desugarOneInput(Desugar.java:326)
    at com.google.devtools.build.android.desugar.Desugar.desugar(Desugar.java:280)
    at com.google.devtools.build.android.desugar.Desugar.main(Desugar.java:584)
Caused by: java.lang.ClassNotFoundException: Class org.openjdk.jdi.ReferenceType not found
    at com.google.devtools.build.android.desugar.HeaderClassLoader.findClass(HeaderClassLoader.java:53)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at sun.invoke.util.BytecodeDescriptor.parseSig(BytecodeDescriptor.java:83)
    ... 16 more

I have already checked similar questions but none worked for me.

This is the build.gradle for my freshly new created project:

apply plugin: 'com.android.application'

repositories {
  maven { url 'http://my.artifactory.repo.com/artifactory/' }
}

android {
  compileSdkVersion 26
  defaultConfig {
    applicationId "com.whatever.myapplicationtest"
    minSdkVersion 16
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

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

  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}

dependencies {
  implementation fileTree(dir: 'libs', include: ['*.jar'])
  implementation 'com.android.support:appcompat-v7:26.1.0'
  testImplementation 'junit:junit:4.12'
  androidTestImplementation 'com.android.support.test:runner:1.0.1'
  androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

  implementation('com.whatever.coollibrary:module:1.0.1@aar') {
    transitive = true
  }
  annotationProcessor 'com.google.auto.factory:auto-factory:1.0-beta5'
  annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
}

And this is the build.gradle for my custom library:

apply plugin: 'com.android.library'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

apply plugin: 'maven-publish'

buildscript {
  repositories {
    jcenter()
    google()
  }
}

android {
  compileSdkVersion 26
  defaultConfig {
    minSdkVersion 16
    targetSdkVersion 26
    versionCode 1
    versionName "0.1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  }

  buildTypes {    
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }

  packagingOptions {
    exclude 'META-INF/services/javax.annotation.processing.Processor'
    exclude 'META-INF/rxjava.properties'
  }

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

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

  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.21"

  implementation 'com.android.support.constraint:constraint-layout:1.0.2'
  implementation "com.android.support:appcompat-v7:26.1.0"
  implementation "com.android.support:cardview-v7:26.1.0"
  implementation "com.android.support:support-v4:26.1.0"
  implementation "com.android.support:design:26.1.0"

  implementation project(':javaModule1')
  implementation project(':javaModule2')
  implementation project(':javaModule3')
  implementation project(':androidModule')

  provided 'com.google.auto.factory:auto-factory:1.0-beta5'
  annotationProcessor 'com.google.auto.factory:auto-factory:1.0-beta5'

  implementation 'com.google.dagger:dagger:2.11'
  annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
  kapt 'com.google.dagger:dagger-compiler:2.11'
  provided 'javax.annotation:jsr250-api:1.0'
  implementation 'io.reactivex.rxjava2:rxjava:2.1.3'
  implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
  implementation 'com.squareup.picasso:picasso:2.5.2'

  testImplementation 'junit:junit:4.12'
  androidTestImplementation 'com.android.support.test:runner:1.0.1'
  androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

So far I've tried to use several Google libraries' versions (27.0.2, 26.1.0), several kotlin versions (jre7, jdk7, jdk8). And, of course, I've used clean , rebuild , Invalidate Caches and Restart , etc so many times I can't even remember.

After lots of tests and different approaches, I found out that the problem was related with the local Java modules included in the custom library.

Converting these modules into Android modules solved all the problems.

Still no idea of why the Java modules produced that error though. If anyone has any idea or insight about it, please share them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM