Java 无法在模块中使用android maps utils
我有一个包含两个模块的项目;Java 无法在模块中使用android maps utils,java,android,gradle,android-maps-utils,Java,Android,Gradle,Android Maps Utils,我有一个包含两个模块的项目;mainapp模块和我在app模块中包含的另一个模块,我们把这个模块称为myModule 我想在myModule中使用SphereCalutil,它包含在android maps utils中,因此我将编译'com.google.maps.android:android maps utils:0.5+'添加到属于myModule的build.gradle文件中 奇怪的是,我无法导入任何属于android maps utils库的类,它似乎不存在于myModule中,即
main
app模块和我在app模块中包含的另一个模块,我们把这个模块称为myModule
我想在myModule中使用SphereCalutil,它包含在android maps utils中,因此我将编译'com.google.maps.android:android maps utils:0.5+'
添加到属于myModule
的build.gradle文件中
奇怪的是,我无法导入任何属于android maps utils库的类,它似乎不存在于myModule中,即使我没有得到gradle错误。当我在属于myModule的任何类中键入SphericalUtil时,我得到了“将库android maps utils添加到类路径”的建议,但它似乎没有做任何事情
当我在app module gradle文件中添加完全相同的行时,它似乎确实起作用了。我可以在属于应用程序模块的任何类中键入spherecalutil
,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"
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.your.library"/>
您需要使用Android模块插件而不是java插件。正如政府所说: 要在项目中创建新的库模块,请执行以下操作:
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"
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.your.library"/>
您是否将MyModule添加到settings.gralde文件中?比如:include':MyModule'是的,我有。上面写着:include':app',':myModule'
你能发布你的myModule build.gralde文件吗?只是把它添加到我原来的postTry中,把它添加到gradle文件的顶部,然后同步/构建项目:apply plugin:'com.android.library',它可能需要安卓{…}东西如果我把它创建为安卓库,我可以在本机Java应用程序中使用该库吗?因为我想在非Android项目中也使用这个库。你不能在Java应用程序中使用Android库。您也不能将android地图utils
用于Java应用程序,因为它只用于android应用程序。