【发布时间】:2018-07-30 15:09:12
【问题描述】:
我有一个包含两个模块的项目; main app 模块和我包含在 app 模块中的另一个模块,让我们将此模块称为 myModule。
我想在 myModule 中使用 SphericalUtil,它包含在 android-maps-utils 中,所以我在属于 myModule 的 build.gradle 文件中添加了 compile 'com.google.maps.android:android-maps-utils:0.5+'。
奇怪的是我无法导入任何属于 android-maps-utils 库的类,它似乎只是不存在于 myModule 中,即使我没有收到 gradle 错误。当我在属于 myModule 的任何类中键入 SphericalUtil 时,我会收到对“Add library android-maps-utils to classpath”的建议,但它似乎没有做任何事情。
当我在应用程序模块 gradle 文件中添加完全相同的行时,它似乎确实有效。我可以在属于应用模块的任何类中输入SphericalUtil,Android Studio 会识别该类并允许我自动导入它。
我也尝试过使用不同的库,例如okhttp,但没有问题,我可以在 myModule 中自动导入并使用它,所以问题似乎与android-maps-utils 相关。也许按照将库添加到类路径的建议破坏了事情?我真的没有猜测,所以任何帮助都是真的。
如果有帮助,myModule gradle 文件如下所示:
apply plugin: 'java-library'
repositories {
maven { url "https://maven.google.com" }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// https://mvnrepository.com/artifact/com.google.android/android
compileOnly group: 'com.google.android', name: 'android', version: '4.1.1.4'
compile 'com.google.maps.android:android-maps-utils:0.5+'
compile 'com.squareup.okhttp3:okhttp:3.8.1'
compile files('libs/experiment.resultlogger-0.0.2.jar')
}
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
【问题讨论】:
-
您是否将 MyModule 添加到 settings.gralde 文件中?像这样:包括':MyModule'
-
是的,我做到了。它说:
include ':app', ':myModule' -
您能否发布您的 MyModule build.gralde 文件?
-
刚刚添加到我原来的帖子中
-
尝试将此添加到 gradle 文件的顶部,然后同步/构建项目:应用插件:'com.android.library',它可能需要 android { ... } 的东西跨度>
标签: java android gradle android-maps-utils