'未解决的参考' app模块中引用的库函数的错误

时间:2018-03-12 20:24:17

标签: java android module architecture kotlin

使用示例:

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文件都已配置,我可以通过单击引用该类,它将我带到模块中的用法。当我构建它时告诉我Unresolved reference: ApiKey请帮我解决这个问题的底部。

App Module中的依赖关系:

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

1 个答案:

答案 0 :(得分:1)

我的猜测是你没有导入库。 你的帖子说我正在导入我的库ewn,但你包括:

implementation project(':enw')

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

implementation project(':ewn')

完成此操作后,我建议./gradlew clean后跟./gradlew build,如果不起作用,请重新启动Android Studio并使缓存无效(可在“文件”菜单中找到) MAC)。

祝你好运,快乐的编码!