当使用gradle'java

编程入门 行业动态 更新时间:2024-10-28 09:18:09
本文介绍了当使用gradle'java-library'时,库中的类不能被引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

升级到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 修正了问题

  • 工作正常标签 android-studio3-test / java-library-plugin -OK
  • 变更

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 MyClass

What 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

本文发布于:2023-06-10 22:57:17,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:gradle   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!