I'm trying to make a simple Android app that writes, for example, an entity with a key called "Example" and a value of "Hello World". Following the tutorial here I've created and uploaded a backend and got the basic functionality detailed there to work using the Java Servlet module, but it wouldn't save any entity on the datastore (but rather just make a toast on the client app) so it was useless for my purposes.
So now I'm trying to import the DatastoreService and Entity classes so I could use the method DatastoreService.put(Entity). However, conflicting resources on the internet and myself being unable to find a coherent guide about this process caused multiple compile errors:
Adding the following dependencies to build.gradle (app):
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.1'
compile 'com.google.appengine:appengine-endpoints:1.9.1'
compile 'com.google.appengine:appengine-endpoints-deps:1.9.1'
compile 'javax.servlet:servlet-api:2.5'
Raises the error:
Gradle DSL method not found: 'appengineSdk()'
Adding the following dependency to build.gradle (project):
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.3'
And applying the plugin in the same file:
apply plugin: 'appengine'
Raises:
Error: Task with name 'assemble' not found in root project
I'm looking for clear instructions on how to properly implement the appropriate classes and handle the process as I'm very new to this aspect of Android Studio and it seems I've gone off-track. Thanks for your support.
Related
Please forgive me in advance as I've been using Java since the early 2000s and have been slow to transition new projects toward being compliant with Project Jigsaw and modules (introduced in Java 9.) I'm stuck and hoping someone can help me out. I've tried to create as minimal project as possible to help me focus on the problem. I'm using:
JavaFX - I followed the instructions on https://openjfx.io/openjfx-docs/ using their guidance for Modular Gradle with IntelliJ, though I'm not interested in building an image yet, so I'm leaving jlink out of it. This worked just fine.
Tablesaw for some pandas-like data crunching
JUnit 5.8.2
I have only one class file, HelloFX down the package org.hello.
Executing..
$ .\gradlew run
I get a ResolutionException error from Gradle while trying to run the project:
Error occurred during initialization of boot layer java.lang.module.ResolutionException: Modules shims and RoaringBitmap export package org.roaringbitmap to module listenablefuture
My project tree (all located in a root folder called TestProject):
./gradle
./gradlew
./build.gradle
./.gradle
./gradlew.bat
./settings.gradle
./.idea
./src
./src/test
./src/test/resources
./src/test/java
./src/main
./src/main/resources
./src/main/java
./src/main/java/module-info.java
./src/main/java/org
./src/main/java/org/hello
./src/main/java/org/hello/HelloTS.java
Here are the pertinent files:
settings.gradle
rootProject.name = 'TestProject'
build.gradle
plugins {
id 'application'
id 'java'
id 'idea'
id 'org.openjfx.javafxplugin' version '0.0.12'
id 'org.javamodularity.moduleplugin' version '1.8.10'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
javafx {
version = "17.0.2"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
test {
useJUnitPlatform()
}
dependencies {
implementation 'tech.tablesaw:tablesaw-core:0.42.0'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'
}
application {
mainModule = "$moduleName"
mainClassName = "org.hello.HelloFX"
}
module-info.java
module TestProject {
requires javafx.graphics;
requires javafx.controls;
requires tablesaw.core;
exports org.hello;
}
What I've discovered so far:
Eliminate Tablesaw - Comment out requires tablesaw.core; from module-info.java and implementation 'tech.tablesaw:tablesaw-core:0.42.0' from build.gradle and my little JavaFX app works just fine with modules, but then I lose Tablesaw.
Eliminate modules - Remove module-info.java, then comment out the mainModule line in build.gradle. Then, I can run both a sample JavaFX program and a sample Tablesaw program by simply changing mainClassName to the program I want to run. I can even add some Tablesaw code in my sample JavaFX app, and it works. This is my backup plan, since it gives me what I want, albiet without modularization.
So, I'm really stumped here. This post didn't help, nor did any other that tried to address this weird ResolutionException error from Gradle. My guess is that Tablesaw is not module compliant? Or I need some sort of exclusion clause in my dependencies for Tablesaw? I tried to use the java-library plugin and use the api clause in build.gradle for Tablesaw as it seemed like that plugin is for non-modular libraries, but that didn't work.
There must be a way to do this, but admittedly I am about ready to throw in the towel and, yet again, just go back to non-modular development for my latest project. I have been a huge fan of Java since its inception, (even fully certified back in the Sun Microsystems days! That'll date me!) I understand why modularization has been introduced. Makes complete sense! But frankly, I'm finding its implementation to be quite challenging to embrace.
Any help would be greatly appreciated. Thank you kindly!
Tablesaw 0.42.0 isn’t built to support the Java module system.
It has no module-info.
It uses shading for its dependencies
It uses dependencies like RoaringBitmap that have issues if you try to use them with the module system.
I suggest you log an issue with Tablesaw requesting that they modularize the library.
In the meantime, JavaFX should be run from the module path as it is only supported that way, but it will probably be better to run Tablesaw from the class path.
You can put JavaFX on the module path and add the JavaFX modules via command line switches.
Put Tablesaw on the class path, don’t add it as a module.
Don’t define a module-info for your app, create a non-modular app that adds the JavaFX modules via switches. This means that your app code is also on the class path so it can access Tablesaw and it can also access JavaFX modules through virtue of the command line switches.
I don’t use Gradle, so I can’t provide you the exact build script you need for this.
For more info see:
openjfx.Io getting started documentation on non-modular with gradle for your IDE
You will probably be able to package your app using the:
badass runtime plugin.
I am trying to incorporate ObjectBox in my hybrid Cordova/Android project. By dint of some trial and error I have managed to figure out two of the steps involved.
The app level build.gradle file has to be modified to include the ObjectBox Gradle plugin classpath "io.objectbox:objectbox-gradle-plugin:2.5.0"
Define a build-extras.gradle file to "apply" the ObjectBox plugin ext.postBuildExtras = {apply plugin: 'io.objectbox'}
The next step according to the ObjectBox docs is to define at least one Entity class
However, the issue here is that I need to import the javax.persistence.* classes into the project. It is not clear to me how I do this. I have run into suggestions along the lines of including
compile group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
in the dependencies section of the app level build.gradle file. However, this causes gradle to complain that it does not know the compile() function. I'd be much obliged to anyone who might be able to tell me how this should be done.
For the benefit of anyone running into this thread - you can download the JAR file for javax.persistence here. Place this line in the folder src/android/libsof your custom plugin and then modify plugin.xmlwith the line
<lib-file src='src/android/libs/name-of-javax-persistence.jar'/>
I create a Jar Lib called "errors" in Java.
I would like to use it in a module called "AndroidHTTPRequestLibrairy" and in my Android App.
But i have a error :
Program type already present:
In my module (AndroidHTTPRequestLibrairy) build.gradle i have :
implementation files('libs/errors-0.1.3-SNAPSHOT.jar')
And in my app I have :
implementation project(path: ':androidhttprequestlibrairy')
and
implementation files('libs/errors-0.1.3-SNAPSHOT.jar')
I dont understand why.
Can someone help me ?
Sincerely,
This issue appears because of namespace conflict.
You are trying to put one library twice in one project. When the Gradle build your project and at the moment when it tries to put in your app.apk archive the errors-0.1.3-SNAPSHOT.jar library it finds out that there is already the errors-0.1.3-SNAPSHOT.jar library and throws an exception.
So the solutions is to remove the implementation files('libs/errors-0.1.3-SNAPSHOT.jar') dependency form the application build.gradle file, because it allready transited in the implementation project(path: ':androidhttprequestlibrairy') dependency
I'm trying to implement my own annotation processor in my android studio project. All is working well and compiling until I add this simple line to build.gradle dependencies block:
dependencies {
.
.
.
annotationProcessor(':processor')
}
At that point I get this error when compiling:
Could not find :processor:. Required by:
project :app Search in build.gradle files
I've followed endless tutorials and nothing seems to help. I've just recently upgraded to AS 3.1 and thinking maybe it relates?
Here is the project structure: (mind you - here I add the annotation processor as a jar file. I've also attached an image trying to do it as a different module and same result)
Here is a different I'm trying to add it - creating the annotation processor in the same project with a different module and still no go:
Some extra info in pics...
Project structure:
app.build:
processor.build:
annotation:
MainActivity:
Processor implementation:
If you have everything inside the same artifact, — annotation processor, it's annotations and library classes, used by processor users, Android Gradle plugin requires you to declare two dependencies on the same artifact:
annotationProcessor project(':processor')
compile project(':processor')
or
annotationProcessor files('libs/processor.jar')
compile files('libs/processor.jar')
Note, that such setup might become unsupported in future. It is advisable to split your processor in separate module and make it depend on the rest of code. After doing so you will be able to declare dependencies like this:
annotationProcessor project(':processor') // processor-only jar
compile project(':processor-api') // annotations and classes for user code
I am trying to load and parse a shapefile using the GeoTools library. However, when I try to load the file the following call is resulting is a dependency failure for org.geotools.factory.FactoryRegistry:
DataStore newStore = DataStoreFinder.getDataStore(connect);
Error:
org/geotools/factory/FactoryRegistry
java.lang.NoClassDefFoundError: org/geotools/factory/FactoryRegistry
I have included the following dependencies in gradle:
compile files ('libs/geotools/gt-opengis-14.2.jar')
compile files ('libs/geotools/gt-api-14.2.jar')
compile files ('libs/geotools/gt-shapefile-14.2.jar')
compile files ('libs/geotools/gt-cql-14.2.jar')
compile files ('libs/geotools/gt-main-14.2.jar')
compile files ('libs/geotools/gt-referencing-14.2.jar')
compile files ('libs/geotools/gt-epsg-hsql-14.2.jar')
I am not sure if all of them are needed but none of them have the missing class. Is there any other dependency I am missing? The class is documented here.
The easy answer to this problem is to use Maven to manage your dependencies, this would then automatically pull in gt-metadata for you and solve your problem.
If you must manage your dependencies by hand then the I wrote a blog post that describes how to use oops to search the GeoTools jars for a class.