gpt4 book ai didi

java - 应用程序模块中引用的库函数出现“未解析的引用”错误

转载 作者:行者123 更新时间:2023-12-02 11:31:45 25 4
gpt4 key购买 nike

使用示例:

package jfyg.etherscan.helloetherescan

import android.app.Application

class HelloEtherscanApplication : Application() {
override fun onCreate() {
super.onCreate()
jfyg.ApiKey.takeOff.setApiKey("1234567891010dede") // <----
}
}

ApiKey 类是我从我的 ewn 库模块调用的类。尽管我没有遇到构建错误,但配置 kotlin 项目表示所有 kotlin 文件均已配置,并且我可以通过单击来引用该类,它会将我带到模块中的用法。当我构建时,它告诉我未解析的引用:ApiKey请帮助我深入了解这个问题。

应用程序模块中的依赖关系:

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

// kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

// google
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'

// tests
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 project(':enw') //<-- importing module here
}

enw 模块中的依赖项(这是库模块):

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

/**
Because RxAndroid releases are few and far between, it is recommended you also
explicitly depend on RxJava's latest version for bug fixes and new features.
*/
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.1.9'

// gson
implementation 'com.google.code.gson:gson:2.8.0'

// retrofit
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'

// kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

// tests
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'
}

Gradle 控制台:

  Putting task artifact state for task ':app:compileDebugKotlin' into context took 0.0 secs.
file or directory '/Users/ackoneb/Android/etherscan/app/src/main/kotlin', not found
file or directory '/Users/ackoneb/Android/etherscan/app/src/debug/kotlin', not found
file or directory '/Users/ackoneb/Android/etherscan/app/libs', not found
file or directory '/Users/ackoneb/Android/etherscan/app/src/main/kotlin', not found
file or directory '/Users/ackoneb/Android/etherscan/app/src/debug/kotlin', not found
Executing task ':app:compileDebugKotlin' (up-to-date check took 0.002 secs) due to:
Task.upToDateWhen is false.
All input files are considered out-of-date for incremental task ':app:compileDebugKotlin'.
file or directory '/Users/ackoneb/Android/etherscan/app/src/main/kotlin', not found
file or directory '/Users/ackoneb/Android/etherscan/app/src/debug/kotlin', not found
file or directory '/Users/ackoneb/Android/etherscan/app/src/main/kotlin', not found
file or directory '/Users/ackoneb/Android/etherscan/app/src/debug/kotlin', not found
file or directory '/Users/ackoneb/Android/etherscan/app/libs', not found
file or directory '/Users/ackoneb/Android/etherscan/app/libs', not found
Using Kotlin incremental compilation

e: /Users/ackoneb/Android/etherscan/app/src/main/java/jfyg/etherscan/helloetherescan/HelloEtherscanApplication.kt: (8, 22): Unresolved reference: ApiKey
e: /Users/ackoneb/Android/etherscan/app/src/main/java/jfyg/etherscan/helloetherescan/MainActivity.kt: (5, 21): Unresolved reference: ethereum
e: /Users/ackoneb/Android/etherscan/app/src/main/java/jfyg/etherscan/helloetherescan/MainActivity.kt: (11, 24): Unresolved reference: EthereumStat

[KOTLIN] deleting /Users/ackoneb/Android/etherscan/app/build/tmp/kotlin-classes/debug on error
[KOTLIN] deleting /Users/ackoneb/Android/etherscan/app/build/tmp/kotlin-classes/debug on error
:app:compileDebugKotlin FAILED
:app:compileDebugKotlin (Thread[Task worker for ':',5,main]) completed. Took 0.31 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details

最佳答案

我的猜测是您没有导入该库。您的帖子说我正在导入我的库 ewn 但随后您包括:

implementation project(':enw')

那么...应该是哪一个?

实现项目(':ewn') ?

正确完成后,我建议 ./gradlew clean 后跟 ./gradlew build ,如果不起作用,请重新启动 Android Studio 并使缓存无效(可以在 Mac 上的"file"菜单中找到)。

祝你好运,编码愉快!

关于java - 应用程序模块中引用的库函数出现“未解析的引用”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49243842/

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