【问题标题】:How to import a class from another module in Android Studio 2.0 beta 5?如何从 Android Studio 2.0 beta 5 中的另一个模块导入一个类?
【发布时间】:2016-06-01 09:36:48
【问题描述】:

我正在尝试从另一个库 (A) 模块导入一个类。还有另一个模块是android app(B)。所以我正在尝试将 A 导入 B

settings.gradle

include ':A', ':B'

B build.gradle

  dependencies {
    compile project(':A')   
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'

}

当我尝试进行 gradle 同步时,它给了我以下错误:

错误:与依赖项“org.hamcrest:hamcrest-core”冲突。解决 应用程序 (1.1) 和测试应用程序 (1.3) 的版本不同。看 http://g.co/androidstudio/app-test-app-conflict了解详情。

错误:与依赖项“junit:junit”冲突。已解决的版本 应用程序(4.8.2)和测试应用程序(4.12)不同。看 http://g.co/androidstudio/app-test-app-conflict了解详情。

如果我删除该行:

    compile project(':A')   

gradle 同步没有任何错误,但我无法将 A 导入 B。

有人可以建议我为什么会导致错误吗?

【问题讨论】:

    标签: android-studio android-gradle-plugin build.gradle


    【解决方案1】:

    发现模块A的gradle文件中已经添加了以下依赖,所以我的B gradle文件中不需要再添加了。

    我需要删除

    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    

    然后 gradle 同步没有任何错误。

    现在我可以将模块 A 导入 B。

    【讨论】:

    • 谢谢伙计,这完全帮助了我你太棒了!
    • 哇,真是救命啊
    猜你喜欢
    • 2016-03-28
    • 2019-10-18
    • 1970-01-01
    • 2020-05-18
    • 1970-01-01
    • 1970-01-01
    • 2019-08-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多