Kotlin库项目失败的解决方案:[Lkotlin / reflect / KProperty

我目前正在建立一个写在Kotlin的图书馆项目。 当我导出一个.aar文件并在一个项目上编译时,我得到了一个by lazy lambda .aar的以下错误。

我在示例应用程序中有错误

 Rejecting re-init on previously-failed class java.lang.Class: java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/jvm/internal/Lambda; ... java.lang.NoClassDefFoundError: Failed resolution of: [Lkotlin/reflect/KProperty; ... Caused by: java.lang.ClassNotFoundException: Didn't find class "kotlin.reflect.KProperty" on path: DexPathList 

在库项目中引用的行exception

 private val view: View by lazy { LayoutInflater.from(context).inflate(R.layout.overlay_view, this, false) } 

库项目的Gradle文件

 apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: "org.jetbrains.kotlin.android.extensions" android { compileSdkVersion 27 defaultConfig { minSdkVersion 16 targetSdkVersion 27 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" androidExtensions { experimental = true } } sourceSets { main.java.srcDirs += 'src/main/kotlin' test.java.srcDirs += 'src/test/kotlin' androidTest.java.srcDirs += 'src/androidTest/kotlin' } buildTypes { debug { ... } release { ... } } defaultConfig { multiDexEnabled true vectorDrawables.useSupportLibrary = true } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } testOptions { unitTests.returnDefaultValues = true } } ext.kotlin_version = '1.2.21' dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) api "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" api "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.22.2' api "org.jetbrains.anko:anko-coroutines:0.10.4" api 'com.android.support:appcompat-v7:27.0.2' api 'com.android.support:support-annotations:27.0.2' api 'com.squareup.okhttp3:okhttp:3.9.1' api 'com.squareup.okhttp3:logging-interceptor:3.9.1' api 'com.squareup.moshi:moshi-kotlin:1.5.0' testImplementation 'junit:junit:4.12' testCompile "org.json:json:20140107" testCompile "org.mockito:mockito-core:2.13.0" testCompile group: 'org.mockito', name: 'mockito-inline', version: '2.13.0' androidTestImplementation "org.mockito:mockito-android:2.13.0" testImplementation 'com.squareup.okhttp3:mockwebserver:3.9.1' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' } repositories { mavenCentral() } kotlin { experimental { coroutines "enable" } } 

可能是什么问题?

One Solution collect form web for “Kotlin库项目失败的解决方案:[Lkotlin / reflect / KProperty”

问题是没有项目的依赖关系构建aar文件。

我的解决方案是创建私有maven存储库,并发布我的项目与依赖。

要将你的依赖关系添加到生成的pom.xml文件中,你可以在模块级别的build.gradle withXml任务修改你的publish方法

 apply plugin: 'maven-publish' group = 'com.mapfit' archivesBaseName = 'mapfit-sdk' version = '1' publishing { repositories { maven { url myMavenRepoWriteUrl credentials { username 'myMavenRepo' password myMavenRepoReadPassword } } } publications { aar(MavenPublication) { // Artifact properties groupId group version version artifactId archivesBaseName artifact("$buildDir/outputs/aar/${archivesBaseName}-debug.aar") pom.withXml { //Creating additional node for dependencies def dependenciesNode = asNode().appendNode('dependencies') //Defining configuration names from which dependencies will be taken (debugCompile or releaseCompile and compile) def configurationNames = ["debugCompile", 'compile'] configurationNames.each { configurationName -> configurations[configurationName].allDependencies.each { if (it.group != null && it.name != null) { def dependencyNode = dependenciesNode.appendNode('dependency') dependencyNode.appendNode('groupId', it.group) dependencyNode.appendNode('artifactId', it.name) dependencyNode.appendNode('version', it.version) //If there are any exclusions in dependency if (it.excludeRules.size() > 0) { def exclusionsNode = dependencyNode.appendNode('exclusions') it.excludeRules.each { rule -> def exclusionNode = exclusionsNode.appendNode('exclusion') exclusionNode.appendNode('groupId', rule.group) exclusionNode.appendNode('artifactId', rule.module) } } } } } } } } } 
  • 如何检查字符串不等于一个字符串,那么它将工作,否则没有? 在kotlin
  • 地图在Firebase onDataChange在Kotlin
  • 注释生成的Java源可空性(对于Kotlin)
  • 在Kotlin重复字符串n次
  • 为什么我得到@提供注释错误?
  • Kotlin与Java:使用lambda参数调用函数
  • 从一个字符串获取Android的ID资源
  • 目录路径列表中的节点层次结构
  • 最好的方法来处理这种情况下,“聪明的演员是不可能的”
  • 在Kotlin的一行中写简单的循环
  • Kotlin中的Wicket NumberTextField在提交时抛出ClassCastException
  • Kotlin language will be the best programming language for Android.