升级到Android Studio 3.0后,我还使用新的android gradle插件 com.android.tools.build:gradle:3.0.0-alpha1 ,并且想要使用 java-library gradle插件(而不是我有一个android应用程序模块,它依赖于一个普通的java模块<$ c 插件)为我的java模块。 $ C> LIB 。 lib 模块包含一个类 com.example.MyClass - 这个被android-app使用。 p>
在app模块的 build.gradle 文件中,我使用 implementation 作为 lib 模块的依赖配置:
dependencies {实现项目(':lib')}当我使用java插件,在 lib 模块的 build.gradle 文件中,如下所示:
apply plugin:'java'一切都好。
但是,当我将它改为
应用插件:'java-library'然后app模块找不到 MyClass : $ p $ MainActivity.java:6:错误:package com.example不存在 import com.example.MyClass; ^ MainActivity.java:15:错误:找不到符号 MyClass.TEST_CONST 符号:变量MyClass 我缺少什么?
下面是一个非常简单的github项目的链接,它说明了这个问题: android-studio3-test-java-library-plugin
解决方案这是一个重要问题。将gradle-wrapper更新为 4.0-milestone-2 修正了问题
After upgrading to Android Studio 3.0 I also use the new android gradle plugin com.android.tools.build:gradle:3.0.0-alpha1 and I want to use the java-library gradle plugin (instead of the java plugin) for my java-only modules.
I have an android app-module which depends on a plain java-module lib. The lib module contains a class com.example.MyClass - and this is used by the android-app.
In the build.gradle file of the app module I use implementation as dependency configuration for the lib module:
dependencies { implementation project(':lib') }When I use the java plugin, in the build.gradle file of the lib module, like this:
apply plugin: 'java'everything is okay.
But when I change it to
apply plugin: 'java-library'then the app module cannot find MyClass anymore:
MainActivity.java:6: error: package com.example does not exist import com.example.MyClass; ^ MainActivity.java:15: error: cannot find symbol MyClass.TEST_CONST symbol: variable MyClassWhat am I missing?
Here's a link to a very simple github project that illustrates the issue: android-studio3-test-java-library-plugin
解决方案It was a gradle-problem. Updating the gradle-wrapper to 4.0-milestone-2 fixed the issue
- working tag android-studio3-test/java-library-plugin-OK
- changes
更多推荐
当使用gradle'java
发布评论