Use Android Studio With Maven ONLY - maven

All I want to do is use Android Studio without converting to Gradle. I MUST use maven (Client Requirements). How can I accomplish this?
I was able to get this working by opening up the pom.xml file but every time I close the project and reopen it, gradle is forced on me and I can't run anymore. Project layout also changes on me.
When I open up the project the first time using pom.xml, the module looks like this:
When I close the project and open up a 2nd time, the module looks like this:
(With the inability to run because Run/Debug says 'No Android facet found in the module')
I can get back to my original state by doing File->Open and reselecting the pom.xml file. I make sure to hit no on the first pop-up:
I blanked out my build.gradle file like so:
buildscript {
repositories {
}
dependencies {
}
}
repositories {
}
dependencies {
}
Extra Notes:
Exported from eclipse ADT for a build.gradle file. Android Studio was missing all External Libraries that were Maven
Dependencies.
Started my own build.gradle file to indlude dependencies but I don't want to maintain two separate files (build.gradle & pom.xml).
Deleted the build.gradle file and anything gradle related in the android project folder before reopening but that did nothing.
Developing on Linux OS Android Studio version 0.4.2

I don't like to answer my own questions but I thought a work around might help others in this case.
What I noticed is that Android Studio fights between gradle and maven and chooses gradle if you have a gradlefile for the project as well as maven.
Work Around
Open Module Settings
Remove all modules. Select the module and hit the minus key to
delete.
Click yes on the prompt.
Open up Maven Projects and click the plus key
Browse to your pom file and hit open.

Related

Modules, Gradle Subprojects, and IntelliJ Woes?

I am trying to make use of modules and gradle subprojects and either receive compile time errors or complaints from IntelliJ.
My project structure is as follows:
Root
- settings.gradle
- core
- build.gradle
- desktop
- build.gradle
- src/main/java/module-info.java
The desktop build.gradle file as a requirement on core as:
dependencies {
implementation project(":core")
}
There is no reference to the "core" project in the module-info.java files.
In this configuration, IntelliJ doesn't like usage of classes from the "core" project in the "desktop" project (I see a lot of red), but running gradlew.bat desktop:run works with no issues. Bug with IntelliJ? I am using microsoft's openjdk, but hopefully that doesn't matter.
My best attempt to fix this, was to add a module-info.java file to the core project as well and reference the core project in the desktop project's module-info.java file. Unfortunately this configuration, while making IntelliJ happy, renders me unable to run the desktop from command line anymore. I get errors about the core project being unable to find required modules that are the exact same as the required modules I pull in for the desktop module. I think this might be an error on my part, but I'm not sure how or what to do to fix it.
Would appreciate any insight.
P.S. Of these issues, I think I would prefer to get IntelliJ working with the first setup, because I intend to have this core library be shared between the desktop project and an android project, and while I haven't looked into it yet, I am not sure Android supports new java modules?
I think terminal should be the first priority. If your original setup made it compiled successfully under terminal, then there is no problem in your project. Do not add extra files for just making the IDE happy.
There's still something you can do. The first step is compiling your project successfully under terminal. This step downloads all the necessary dependencies before IntelliJ, reducing the problem scope to IntelliJ's linking and indexing. Then there are some options:
In the Gradle tool window, click the top-left button Refresh all Gradle projects.
Delete all the .idea folders in your project. Then open the root folder of your project via UI or CLI.
Click the invalidate caches/restart in the main menu.
You can also also create a new Gradle multi-module project with command gradle init, and open it with IntelliJ. It should be analyzed by IntelliJ normally. Then you can compare its project structure with yours. Maybe there's something different.
Hope these steps could help you.

How to make IntelliJ IDEA open Gradle's own source code?

I'm working on a Gradle plugin. Sometimes I want to look at the source code or Javadocs of Gradle's own classes. I want to do it from IntelliJ IDEA, without having to open a separate application. That is, Ctrl+click or Ctrl+B on a Gradle method or class and have IntelliJ open the source code of Gradle itself.
I have tried everything from Attaching Gradle sources in IntelliJ IDEA :
adding wrapper { ... } block in build.gradle
file gradle/wrapper/gradle-wrapper.properties has distribution type all (and, to my knowledge, has never had other distribution type on this particular machine)
I have also tried attaching sources manually by downloading Gradle source code from GitHub, but IntelliJ doesn't seem to be able to ingest it.
In addition to that, I have tried standard troubleshooting remedies of IntelliJ:
Refresh Gradle project
File > "Invalidate Caches / Restart" > "Invalidate and Restart"
Yet, when I click on method project.getProperties() (as an example), IntelliJ IDEA opens decompiled Project.class instead of the source code file Project.java.
How to make IntelliJ IDEA open Gradle's own source code?
Looks like you are facing this issue: IDEA-197970.

Spring STS not recognizing project structure with Gradle

I'm trying to do this getting started guide from Spring. So I cloned the project using git from the command line. As I'm working with Gradle, I removed the Maven files from the repository to clean the project.
After that I open my STS and go to File -> Open Projects from File System and navigate to the /initial folder of the repository. The project is imported correctly but when I try to add some "java stuff" (packages, classes, etc.) I get several errors and I can only add folders and files, which is quite annoying for working.
To be more descriptive, I'll add some images so you can see what's happening. This is the project initially imported into STS as I described above:
Then I try to add some java stuff, let's say for example a source folder. So Right Click on library -> New -> Source folder and this is the result:
And in the properties of library I have the following:
So the question is: how can I tell to STS to recognize the library folder as a Java Project (or Gradle module, I don't know how to call it) instead of a plain folder so I can add my packages and classes?
Thanks in advance for your answers.
In case you would like to work with Gradle, you should use the Gradle integration for Eclipse (project Buildship) and install that into your STS environment. After that, you should be able to import the projects either from disc as existing Gradle project (not as file system) or via the wizard that integrates the spring guides into STS (Import Getting Started Content). The wizard for the guides also let you choose between the Maven and the Gradle variant, so you don't need to close and delete stuff yourself.
Hope this helps!!!

How to elegantly build selected parts of a project

I have a project where I ideally wanted to be able to write something like this:
gradle build
or
gradle build -Pparts=part1,part5
Where the first command builds the whole project with a core part and all other parts. The second command builds the core part and selectively part1 and part5.
What I ended up with was splitting it up into subprojects and configuring them in the root build.gradle like this:
https://gist.github.com/Homyk/2d1d50b4678203817eaf
I can now do
gradle pack
or
gradle pack -Pparts=part1,part5
Which is fine but there are two problems at least that I would like to have solved:
I have to write a made up command instead of gradle build, which I care about because it`s open source, and I should not have to explain that.
With subprojects in Eclipse at least it`s very cumbersome to get it to build from Eclipse and develop effectively even when running 'gradle eclipse'. I ended up importing each subproject as a project which is pretty awful.
If I would solve this problem again starting from scratch what would the most elegant solution be?
Considering what you describe I would definitely go for a multi project set-up, this solves problem one as there are default ways to call only certain subprojects. More about multi-project build can be found here and a more specific StackOverflow question about executing tasks of subprojects can be found here.
I do not recognize the issues you describe in problem two. The integration in Eclipse works just fine after I installed the Gradle Integration for Eclipse Eclipse plugin from Springsource (although I have some JUnit issues). After you installed the Eclipse plugin just do the following to import the projects:
Apply the eclipse plugin to your Gradle build files.
In Eclipse open the 'Import' dialog by opening. By clicking File -> Import...
Choose Gradle Project as import source (located under the 'Gradle' category).
The 'Import Gradle Project' dialog will pup-up. Select the folder the root project is located in as root folder. Click Build Model. This should display the root project and it's subprojects. Select which project you want to import (probably all). Specify your 'Import Options' (I select everything except of the 'Use hierarchical project names'-option). Optionally add the projects to a working set. Than click Finish. The project should have been correctly imported.

Best way to incorporate Volley (or other library) into Android Studio project

I've seen different advice on the best way to do this This question covers creating a jar. Elsewhere, I've seen advice to simply copy the volley source into your own project. This section on libraries at android.com would seem the most authoritative. However, after compiling volley, I don't have an aal library, whereas that section says I should have.
So my question is this: I have an existing Android Studio project with a standard layout, and a git repository; what should I do to add volley? Where should I download it to? How should I add it to Android Studio? Which Gradle files, if any, do I need to modify.
Hopefully, for those of you have done this a few times, this should be bread-and-butter stuff, but I haven't been able to find a straightforward description.
--
Updating, per Scott Barta's suggestion.
The gradle.build file in the volley repository has this line.
apply plugin: 'android-library'
According to the documentation: "Library projects do not generate an APK, they generate a .aar package (which stands for Android archive)." However, when I build the volley project, no .aar is created.
My feeling is that as Volley is a library project, created by the Android team, it is most probably intended to be generated and used as .aar package. Any advice on whether it would be preferable to generate a .aar, and how to do that, would be appreciated.
As pointed out by others as well, Volley is officially available on Github:
Add this line to your gradle dependencies for volley:
compile 'com.android.volley:volley:1.0.0'
To install volley from source read below:
I like to keep the official volley repository in my app. That way I get it from the official source and can get updates without depending on anyone else and mitigating concerns expressed by other people.
Added volley as a submodule alongside app.
git submodule add -b master https://github.com/google/volley.git volley
In my settings.gradle, added the following line to add volley as a module.
include ':volley'
In my app/build.gradle, I added a compile dependency for the volley project
compile project(':volley')
That's all! Volley can now be used in my project.
Everytime I want to sync the volley module with Google's repo, i run this.
git submodule foreach git pull
LATEST UPDATE:
Use the official version from jCenter instead.
dependencies {
compile 'com.android.volley:volley:1.0.0'
}
The dependencies below points to deprecated volley that is no longer maintained.
ORIGINAL ANSWER
You can use this in dependency section of your build.gradle file to use volley
dependencies {
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
}
UPDATED:
Its not official but a mirror copy of official Volley. It is regularly synced and updated with official Volley Repository so you can go ahead to use it without any worry.
https://github.com/mcxiaoke/android-volley
Nowadays
dependencies {
compile 'com.android.volley:volley:1.0.0'
}
A lot of different ways to do it back in the day (original answer)
Add volley.jar as library
Download it from: http://api.androidhive.info/volley/volley.jar
Place it in your [MyProjectPath]/app/libs/ folder
Use the source files from git (a rather manual/general way described here)
Download / install the git client (if you don't have it on your system yet): http://git-scm.com/downloads
(or via git clone https://github.com/git/git ... sry bad one, but couldn't resist ^^)
Execute git clone https://android.googlesource.com/platform/frameworks/volley
Copy the com folder from within [path_where_you_typed_git_clone]/volley/src to your projects app/src/main/java folder (Integrate it instead, if you already have a com folder there!! ;-))
The files show up immediately in Android Studio. For Eclipse you will have to right-click on the src folder and press refresh (or F5) first.
Use gradle via the "unofficial" maven mirror
In your project's src/build.gradle file add following volley dependency:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// ...
compile 'com.mcxiaoke.volley:library:1.+'
}
Click on Try Again which should right away appear on the top of the file, or just Build it if not
The main "advantage" here is, that this will keep the version up to date for you, whereas in the other two cases you would have to manually update volley.
On the "downside" it is not officially from google, but a third party weekly mirror.
But both of these points, are really relative to what you would need/want.
Also if you don't want updates, just put the desired version there instead e.g. compile 'com.mcxiaoke.volley:library:1.0.7'.
As of today, there is an official Android-hosted copy of Volley available on JCenter:
compile 'com.android.volley:volley:1.0.0'
This was compiled from the AOSP volley source code.
UPDATE:
compile 'com.android.volley:volley:1.0.0'
OLD ANSWER:
You need the next in your build.gradle of your app module:
dependencies {
compile 'com.mcxiaoke.volley:library:1.0.19'
(Rest of your dependencies)
}
This is not the official repo but is a highly trusted one.
For incorporate volley in android studio,
paste the following command in terminal ( git clone https://android.googlesource.com/platform/frameworks/volley ) and run it. Refer android developer tutorial for this.
It will create a folder name volley in the src directory.
Then go to android studio and right click on the project.
choose New -> Module from the list.
Then click on import existing Project from the below list.
you will see a text input area namely source directory, browse the folder you downloaded (volley) and then click on finish.
you will see a folder volley in your project view.
the switch to android view and open the build:gradle(Module:app) file and append the following line in the dependency area:
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
Now synchronise your project and also build your project.
I have set up Volley as a separate Project. That way its not tied to any project and exist independently.
I also have a Nexus server (Internal repo) setup so I can access volley as
compile 'com.mycompany.volley:volley:1.0.4' in any project I need.
Any time I update Volley project, I just need to change the version number in other projects.
I feel very comfortable with this approach.
add
compile 'com.mcxiaoke.volley:library:1.0.19'
compile project('volley')
in the dependencies, under build.gradle file of your app
DO NOT DISTURB THE build.gradle FILE OF YOUR LIBRARY. IT'S YOUR APP'S GRADLE FILE ONLY YOU NEED TO ALTER
This solution is for Kotlin DSL (build.gradle.kts):
dependencies {
implementation("com.android.volley:volley:1.2.1")
// ...
}

Resources