When using gradle 'java-library' the classes in the library cannot be referenced

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

Can you please upgrade to 4.0-milestone-2 to see if the problem persists?

yeah - it works with 4.0-milestone-2.
Thank you for the fast reply!

1 Like