im still quite new to gradle. I decided to transfer some code i oft use into an subproject. This subproject is a pure java project, so im using only the apply plugin: 'java' there.
I can build this project and in the build folder is see a jar which contains the compiled classes after the gradle assemble command was invoked.
What really bugs me at the moment is, how can i use the classes in my Android project using Android Studio ?
I tried to use the compile project command:
compile project(':PureJavaSubProject')
And it compiles the Project as expected. But Android Studio is not able to see the artifacts created by the Project ?
I read a bit in the Gradle Docs about Artifacts management but the Doc is not clear for me.
Anyone can point me how i need to declare or setup the gradle build to make it work ?
Are you including the subproject from your root project in your settings.gradle?
include 'PureJavaSubProject'
I can't verify from Android Studio I'm afraid. There is also more doc on multi project builds here:
http://www.gradle.org/docs/current/userguide/multi_project_builds.html
I had this same issue, and it turned out I had the directory structure for the Java subproject slightly wrong (I had copied it from another existing Eclipse project).
I had:
java-subproject/src/com/example/MyJavaClass.java
...when it should have been:
java-subproject/src/main/java/com/example/MyJavaClass.java
When I changed it to the correct structure, the main Android project then picked up the classes in the Java sub-project fine.
A fully working example of an Android Studio project with a pure Java sub-project can be see here on Github:
https://github.com/barbeau/JavaSubprojectDemo
Related
I have two projects
one plain java project and one gradle spring project created from jhipster
I would like to use the java project alongside with the gradle one.
After search on the net i have found how to do it link1 but this works only if all my projects are gradles.
Also when i try to add module dependency from Project Structure does not work.
Project tree
workspace
-project1
--build.gradle
-project2
What is the right way of doin this?
Also why i cannot make changes from IDE's project structure and automatically update build.gradle and settings.gradle with the new dependencies?
Change the plain java project into a gradle project, change the two projects into a gradle multi-project.
It's not hard to do, the plain java project probably just needs an almost empty build.gradle file and the settings.gradle file just needs to include it.
An IDE cannot help you much in these tasks, you will have to do most of it manually.
I downloaded a Android project and wanted to try it. So I imported it to Android Studio (2.2) and when running the project i get the error:
Error:Execution failed for task ':app:compileDebugJava'.
Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.
Before the runnning of every project worked and i'm searching for days but still found no working solution.
EDIT: Here is my project structure:
project structure
Maybe someone of you has the solution.
This kind of problem arises when you compile old project in your new updated Android Studio IDE Version.
Technically speaking : gradle build version is old. Just update with new
This can be achieve editing inside build.gradle(Project: App name)
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
//update latese gradle build version.
}
This might do the trick.
I think, you didn't setup JDK for current project. You've just loaded the code. Do it in project structure.
You can do it here: File > Project Structure > [Platform Settings] > SDKs.
I had the same issue. It turned out to be old versions of the buildscript dependencies classpath, and the buildToolsversion, that were included in the project config files. This was not related to the JDK path, changing the JDK path didn't help.
I followed this answer, with these additions:
In step 1, the gradle-wrapper.properties file is inside the gradle/wrapper folder in my main project folder. The lowest gradle version that Android Studio accepted here was gradle-3.3-all.zip
In step 4, for the classpath gradle version I used 2.3.2, this is the latest non-alpha version that I found, that works here. (not sure why these versions are different. but it works)
I also had to change the buildToolsVersion to '25.0.0' from the old '20.0.0', inside the file build.gradle in my module sub-folder.
Now I can compile the project in Android Studio successfully.
(The file gradlew in the project main folder is generated once at the project creation, and can be regenerated. It can be used to run gradle commands manually, such as debugging this issue. But it was not needed for this solution.)
editing inside build.gradle(Project: App name)
dependencies {
implementation 'com.android.tools.build:gradle:3.6.2'
//update latese gradle build version.
}
then sync it.
I have installed Android Studio but would like to use Gradle to build a simple "hello world" Java application that I have created outside of AS.
I have added the java plugin to my build.gradle file and ran `"gradle build" to try and build the .java file.
However, I am getting the error: "Gradle is not recognised as an internal or external command"
Do I need to install a separate version of Gradle, not bundled with AS to be able to build a java project?
Do I need to install a separate version of Gradle, not bundled with AS to be able to build a java project?
More or less.
There are two ways of using Gradle:
Download and install it, like you would most other development tools
Have a project set up for the Gradle Wrapper (gradlew and gradlew.bat files in the project root, plus the gradle/ directory containing the Wrapper JAR and properties file)
That latter approach will download a private copy of Gradle for this particular project, into the project's .gradle/ directory. This way, different projects can use different versions of Gradle without conflict.
Android Studio takes the latter approach; you can see the files that I mentioned in a newly-created Android Studio project, for example. For your own Java project, I'd do whatever is natural for your IDE that you plan on using for that project.
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?
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:
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.)
I am experiencing difficulties to install some project based on a build.gradle file. I was told in a precedent post, that I should use Android Studio but it seems even more difficult (reported conflict for gradle 1.10 and Android Studio). So I am asking if it is possible to import the project directly in my ide, https://github.com/chrisbanes/ActionBar-PullToRefresh. If yes, should I put the library folder below in my libs folder ? Here's a screen of the file hierarchy
Since you are using Android Studio and Gradle, you could import it as suggested by the QuickStart page :
The easiest way to add ActionBar-PullToRefresh to your project is via
Gradle, you just need to add the following dependency to your
build.gradle:
dependencies {
mavenCentral()
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}
I believe this is by far the easiest way to include that great library in your project.
If you are using Eclipse, you can still use the library, just download the project and create a create a new library project with the code from "library".
Check the guide http://www.jetbrains.com/idea/webhelp/cloning-a-repository-from-github.html
and other github integration http://www.jetbrains.com/idea/webhelp/using-github-integration.html