我尝试将自定义库导入到新创建的项目中,但是当我尝试构建它时,我收到了下一个错误:
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
我已经为我检查了similar questions,但none worked。
这是我刚刚创建的新项目的build.gradle:
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'
}
这是我的自定义库的build.gradle:
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'
}
到目前为止,我已尝试使用多个Google图书馆'版本(27.0.2,26.1.0),几个kotlin版本(jre7,jdk7,jdk8)。
当然,我已经使用clean
,rebuild
,Invalidate Caches and Restart
等多次,我甚至无法记住。
答案 0 :(得分:0)
经过大量测试和不同方法后,我发现问题与自定义库中包含的本地Java模块有关。
将这些模块转换为Android模块解决了所有问题。
仍然不知道为什么Java模块会产生错误。如果有人对此有任何想法或见解,请分享。