I have a current Gradle, Java 11, project that I intent to use as a library with a set of general purpose functions for another apps.
I'm using the Gradle function:
java{
withSourcesJar()
}
To build a .jar with the source and JavaDoc included. However when I import that .jar into another app (via Gradle implementation) all the non java SDK dependencies in the .jar library fails with a message of the style:
Package 'x' is declared in module 'y', but module 'z' does not read it
Even though that all the required dependencies are already implemented (via Gradle as well) in the host app.
The part that puzzle me more, is that if I build the library jar, as a simple plain .jar(meaning source code but no Javadoc) the library works smoothly when implemented in other apps, it only fails when I try to build it as a withSourcesJar().
So any help that could point me on what I doing wring in the withSourcesJar() or what extra configuration should I add, would be appreciated.
Thanks.
Related
I'm using the Java library for the Google Maps API but cannot find the code at runtime. I've added the repository and dependencies to build.gradle as detailed in the readme. Everything compiles fine, the import statement autocompletes, I can open the source code in Eclipse through "View Declaration," and I can see Google Maps in the Java build path.
import com.google.maps.GeoApiContext;
// Throws exception!
GeoApiContext.Builder builder = new GeoApiContext.Builder();
Why is this library visible at compile time but not runtime?
ETA: The application is packaged as an EAR file and deployed to a web server.
With the scarse details you provided, my guess is that you built a jar file and then ran java -jar myApplication.jar.
The default jar file only contains the classes of you own application, and not its dependencies. If you want to make an executable jar, you have several options. Some of the more popular are:
Use the shadow plugin, which will repackage the jar to make it "fat" with all its dependencies.
Use the standard distribution plugin that will create a zip (or tar) of your project and its dependencies. It will also a script for setting the classpath correctly.
I want to build a java project with several dependencies in gradle, some are jar dependencies from the maven central repository, some are other java project dependencies, but there is also a native JNI dependency. I've managed to build the native dependency with gradle as a seperate project.
Now I want to import the compiled .so library as a depedency in my java project. I thought it would work something like this:
dependencies {
compile project(':nameofnativedependency')
}
The project is also listed in my settings.gradle file. However, when I compile the project, I can get an error:
Could not determine the dependencies of task ':test
Configuration with name 'default' not found.
So something must be misconfigured. What is the right way (I hope there is one) to compile a native project and import the .so file in the calling project?
The Gradle native plugin uses the new rule based software model. Model elements are not instantiated until after build.gradle has veen processed, and once instantiated they are immutable. To access those elements, you need to put your code inside the components closure, and access model elements through the $ variable (bearing in mind that elements accessed that way will be instantiated, therefore immutable).
To integrate a java build with a native build, you will probably want to use the java software model plugins, instead of the legacy java plugin. I have been playing around with it, and have a buildscript that I'm starting to feel a little proud of, incorporating all of the steps from generating headers from class files, building libs, copying into src/main/resources to be bundled in the jar, then extracting and loading libs at runtime (though this part's not quite done yet; Scijava's native library loader is probably the way to go).
I have a android project with a runtime directory, and there is a jar file in this directory. This project can be built in eclipse. However, if I put the jar file in some other place, say, libs directory. This project would fail to build. In addition, even if I place the jar file in the runtime directory, this project cannot be built in Intellij. When the project fails to build, the error logs looks like the following.
Android Dex: [GameDemo] EXCEPTION FROM SIMULATION:
..... bad range 5..6; actual size 5
at bytecode offset 0000005
while processing ()V
So here are my questions:
Given a project in Eclipse, why project can be built when the jar file is in runtime library, but not when it's in libs directory.
Even though the jar is in runtime directory, why this project cannot be built in Itellij. What's the difference in build process of the two ide in term of android project.
Thanks!
I believe you are having this issue because you are trying to integrate CMCC's mobile SDK. It's a piece of garbage but that's another topic. For your purpose, just setting the library as "Provided" instead of "Compile" in the module settings of your IntelliJ project will get you past the compile stage. the SDK's probably loading it on the fly but not sure why that's necessary. Also be careful how you add the dynamic lib they provided. Make sure you do a plain copy instead of through the android NDK module dependency crap.
Seems they wanna avoid their sdk to be easily decompiled and byte hacked.
So they provided a dev time lib written in java that has interface feature only and implemented the real logic/type/class in a native lib.
I have a Java project which is heavily used by all sorts of other Java and Android projects. The project contains some JAR libraries which shall be used by all projects, except for the Android one (in fact the Android project is a Android library project to be precise).
I marked the JARs as "export" in the Eclipse build path preferences of the Java project. However, the Android project shouldn't import these libraries (as they are Java libraries which make use of some classes which are not available on Android), but it shall import the rest of the code (which doesn't really use the libraries, but they are stored in there for convenience reasons and to ensure, that all other projects use the same library.
How can I prevent the JARs from being exported to the Android projects?
You can prevent all jars from being exported so that only the common project is a dependency for each project that needs it.
Then you can change the build path of each project to only include its necessary jars through the add jar.. dialog in build properties.
That's the easiest way.
A more extreme way would be to move to maven and then eclipse will only include the jars you specify in the pom - though that's a load of extra work for not much gain.
Alternatively, you could split the android specific code into a android-common separate project and then make your common project depend on it and export it - then your android project could rely on this android-common project instead of the existing common project.
I'm working on Android code that exists partly in a library project and partly in an app project; the app depends on the library. But the library is obfuscated, so instead of
import com.mycompany.mylibrary.MyClass
I have
import myobfuscatedlib.MyClass
This works fine in production, but I am trying to debug, and I would like to step into the library's methods; I would also like to be able to edit the library classes, then run the app and see my changes. At present the jar that the library file creates is in the app's build path; if I replace the jar with a project reference, all my imports are invalidated. How can I configure my projects to debug the unobfuscated code while obfuscating for the production build?