gpt4 book ai didi

android - Kotlin 库项目 : [Lkotlin/reflect/KProperty 的解析失败

转载 作者:太空狗 更新时间:2023-10-29 14:40:44 28 4
gpt4 key购买 nike

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

我在示例应用程序中遇到的错误

Rejecting re-init on previously-failed class java.lang.Class<com.myproject.lib.MainActivity$view$2>: 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

库项目中引用的行异常

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"
}
}

可能是什么问题?

最佳答案

问题是 aar文件是在没有项目依赖项的情况下构建的。

我寻求的解决方案是创建私有(private) maven存储库并使用依赖项发布我的项目。

将您的依赖项添加到生成的 pom.xml文件,您可以使用 withXml 修改您的发布方法模块级别的任务 build.gradle

apply plugin: 'maven-publish'
group = 'com.group'
archivesBaseName = 'group-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)
}
}
}
}
}
}
}
}
}

关于android - Kotlin 库项目 : [Lkotlin/reflect/KProperty 的解析失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48674893/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com