Android gradle import lots of errors and trouble - java

Im trying to get used to this new gradle system built into the new Android studio.
I've tried a really basic task, to import the websockets library into my project. So I imported the module via the normal route (File->Project Structure), I imported the java-websockets module in and added it as a dependency too. Finally I import the org.java_websockets class into my project.
My project ended up looking like this:
So this is where my problem starts, I give it a shot and try to build it and run into the usual gradle errors. So I added an 'include' line to my settings.gradle
include ':java-ws-client'
and another one into my build.gradle
compile project(':java-ws-client')
So now I find myself stuck with two problems:
One fairly undescriptive one:
and another:
I've tried updating my android studio to the latest one, and the project above is a fresh one.
How can I avoid pulling my hair out?

From your screenshot, settings.gradle is inside TestProjectProject, which makes TestProjectProject a root project. However, java-ws-client is parallel TestProjectProject, which is outside of TestProjectProject's scope. You cannot reference any project outside its scope using ":foobar" notation.
To fix the second problem, you should either move java-ws-client into TestProjectProject, or declare java-ws-client as an external dependency, and add proper repository resolver to find it.
To fix the first problem, make sure in TestProjectProject/build.gradle you have applied the Java plugin. The Java plugin creates the "default" configuration.

Related

Facing errors when trying to add a Java API

I am using the eclipse IDE and trying to use a JAVA API.
This is the API I am trying to add. https://github.com/spoonlabs/flacoco
It says that the API is only currently available as a snapshot and gives me the details to add it as a dependency in a pom.xml file.
I am not sure how to do this in eclipse. I have downloaded the M2Eclipse plug in and tried creating a maven project by skipping the archetypes but when I add the dependency I get too many errors.
These are the errors that pop up : https://ibb.co/Y4gNnN8
I do not know to resolve the issue.
If any more details related to the error is needed,please let me know.
You project hierarchy, as well as the pom.xml setups are wrong.
At the pom.xml, change the group id to something like com.<your_name>.<porject name> then create the same package structure under src/main/java (you should end with up with something like src/main/java/com/<your_name>/<porject_name>).
This should fix whatever you're seeing now.

How to update external jar file without breaking everything with gradle?

When updating an external jar file which contains breaking changes, so the code at certain points will have errors (which happens and is fine), I am unable to build my project via gradle, thus EVERY import from the jar shows up in my IDE as an error (Intellij).
This makes it super hard to actually see where the errors are, since ALL imports from the jar, even though all those classes are in there show up as "errors", since build failure means gradle simply wont import the jar at all...
The end result is that my IDE shows things like this (removed package name for security reasons):
All of those model.entity classes ARE in the jar, but gradle wont import them because the build process stops at the first syntax error in the code...
Is there any way around this? How to refactor large code bases without relying on the error messages inside the gradle console (which there might be a LOT of).
I'd like to import the jar first THEN fix the syntax errors? Maybe a different gradle command? I'm simply using "clean build"
There are 2 aspects here.
grade
IDE (appears to be Intellij) - imports the gradle to create project. unless on auto refresh, requires manual reimport (refresh button) when there are changes in gradle files
in your scenario, initial state is gradle build works, Intellij works fine
you replace the dependency with 'breaking' change.
gradle build - will fail at compile stages as code is yet to the fixed
IntelliJ - still is not seeing new dependency. click the re-import
The import will always succeed unless there are errors in .gradle files
After import IDE will now reflect new dependency

Cannot figure out error importing jme3 in eclipse

**UPDATE:
I closed and re-opened eclipse (which I've done before), and was presented with a new "quick fix" solution of moving the library to the module path (which it has been in before), and now I can reference it, but now
import com.jme3.app.SimpleApplication;
says
The package com.jme3.app is accessible from more than one module: jme3.core, jme3.desktop
my module-info now have warnings as well:
module-info.java:
module vast {
requires jme3.core; //Name of automatic module 'jme3.core' is unstable, it is derived from the module's file name.
requires jme3.desktop; //the same(ish)
requires jme3.lwjgl; // and so on
}
I'm going to fiddle around a bit and see what I can figure about those
**
So, I've decided to migrate one of my projects from LWJGL3 to JME3 (using Eclipse). I followed the advice of Setting up JME3 in Eclipse, specifically downloading the library, extracting it to a lib subfolder in my project, I then added the contents of the library to a User-Library (using Add JARs, since they are in my project), and added the library to my classpath. I know eclipse sees the library (code suggestions), but I keep getting access errors.
Setup:
Arch Linux (latest)
Eclipse IDE for Java Developers (2019-12 (4.14.0))
Here's the code (small test class to make sure it runs before I refactor):
Test.java:
package lab.stone.werlious.vast;
import com.jme3.app.SimpleApplication; //the type com.jme3.app.SimpleApplication is not accessible.
public class Test extends SimpleApplication { //SimpleApplication cannot be resolved to a type
}
module-info.java:
module vast {
requires jme3.core; // jme3.core cannot be resolved to a module
}
I've tried many different combinations of adding the library (modulepath, classpath, user library, external JARs, internal lib JARs), and referencing it. I keep getting errors, even though SimpleApplication suggests importing com.jme3.app.SimpleApplication, which suggests adding requires jme3.core to module-info.
I am not using maven or gradle (detest those), and prefer to do things locally. I also prefer eclipse over jme3 sdk. Can someone tell me how to properly import this library (without maven or gradle)? and how to properly import it in my code? I didn't have this issue adding LWJGL3 to eclipse before, and currently jme3 is added the same as lwjgl3 in my source project (jars in lib folder in project, lib folder added as user library, user library added to classpath).
Thank you all for your help
As a side note, because I'm sure someone will mention it, I've been on various forums for about 2 hours trying to figure this out, including stackexchange. I can't find a similar issue with a solution that works for me.

Issues importing github project as library into existing project in android studio?

I know similar questions have been asked many times in the past, I'm working to try import a Github project to be a library Github Project for my existing project. I've reference to related stackoverflow solutions discussed here for the steps (visually or setting.gradle/build.gradle code solution) to import it but without any success in it.
Tried including include ':library:CanvasView' into setting.gradle and
compile project(':library:CanvasView')into build.gradle
Had error statement Error:Configuration with name 'default' not found. Tried solutions here to solve it without any success.
But for once, I've managed to gradle compile it with this statement, compile it fileTree(dir: 'library', include: ['CanvasView']) in build.gradle
To my dismay, I realize that I was not able to call the API of the library in my main project, because the java file of the imported library was marked with an red icon. Tried solutions here but isn't helping to call the API. Thanks for any help rendered!
Make sure you have the right names.
Note this is assuming you have already checkout your project from github. I usually put the projects under the same workspace directory. Like such:
-Workspace
--MyApp
--SomeLib
1.In your settings.gradle make sure you are pointing to the right place.
My example:
include ':SomeLib'
project (':SomeLib').projectDir = new File('../SomeLib/SomeLib')
2.In your build gradle make sure you are compiling the right Module name
compile project(':SomeLib')
A good check to see if you are doing things correctly at step 1. Before you go to step 2 make sure the library comes to the Project View. If it comes make sure your actual source code is there. Java classes etc. If you see that stuff then go to step 2. From step 2 you should be good. Let me know how it goes.
To be exact this is your example:
settings.gradle
include ':CanvasView'
project (':CanvasView').projectDir = new File('../CanvasView/CanvasView')
build.gradle
compile project(':CanvasView')

Android studio can't edit library

I downloaded this library and i extracted the rar into my app\libs folder.
Then I added compile 'com.github.lzyzsd:circleprogress:1.1.0#aar' to my build gradle as it says, and clicked on sync.
Then I noticed that the max is set to 100 (in file DonutProgress.java).
I changed it to 5, clicked on sync again but nothing changed.
After few hours of trying I decided to completely remove the extracted folder from my app\libs and sync again to see what happens.
Surprisingly, everything was still working like library was still there.
Can someone explain me what's happening here, I have to edit it but it seems whatever I do to the library doesn't affect the app.
It seems like it's using another library from totally different folder, I don't know, I tried searching for DonutProgress on my computer but didn't find anything that seems useful.
Please help.
When you add compile 'com.github.lzyzsd:circleprogress:1.1.0#aar' to your build.gradle dependencies, you are telling Gradle to go fetch this library from a repository when you build.
For most Android apps, this means that when you do a build, Gradle will go and download the library (in this case a .aar) from jCenter. This is good because it means you no longer need to manage the JARs (or other library files) yourself.
If you want to use a custom version of that library, then you should not add that dependency to your Gradle build script. Instead you should add it as either a module or a local dependency (e.g. compile files('libs/custom_library_name.aar')).

Categories

Resources