简体   繁体   中英

How do I add a java gradle submodule to my Android module?

Suppose I have an Android application project in IntelliJ Idea with Gradle. Call it MyApplication . What I want to do is to add a plain java library module (not Android library project) as a submodule to MyApplication . Lets call this module a testlib . And then when whole project is built, I want this module compiled to jar and included to /libs folder of MyApplication.

What I tried: I've created a submodule testlib and included it as a dependency to MyApplication , but I get a following warning:

Warning:Gradle: module 'testlib' won't be compiled. Unfortunately you can't have non-Gradle Java module and Android-Gradle module in one project.

Is this even possible?

IntelliJ IDEA does not support Gradle and Non-Gradle modules in one single project. A comment from JetBrains in their forum states this clearly.

The solution is to either convert the Maven modules into Gradle modules or split the project in two. With the latter approach, if you build the plain java library module with Maven before building the Gradle project, you will still be able to use it as a dependency in the Android application project.

Beware of using different Java language source levels in multi-module Gradle projects. IntelliJ IDEA does not handle them correctly due to a bug in either IntelliJ IDEA or Gradle. (There is a pending discussion whether this should be fixed in the IDE or Gradle.)

If you've created your project in IntelliJ as an Android-gradle project, then when you go to the "Add new module" window you should see an "Gradle: Java library" option like this:

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM