Javax.json.bind with Android issues - java

Hi all I am trying to use javax.json-b with Android and getting errors. So I include the library in gradle using this line:
implementation group: 'javax.json.bind', name: 'javax.json.bind-api', version: '1.0'
Then import it the usual way:
import javax.json.bind.annotation.JsonbProperty
Compiles fine but when I run it on any device it gives me this:
../../../home/.gradle/caches/modules-2/files-2.1/javax.json.bind/javax.json.bind-api/1.0/10332203cb05f4ab2e8bf058bfd7d99648c5ca68/javax.json.bind-api-1.0.jar
Illegal class file: Class module-info is missing a super type.
So I cleared the gradle cache incase it was a bad version, same happened, I removed the import implementation line from the build.gradle file and downloaded the jar from the maven repository but I got a similar issue.
I thought initially that this means the Java version on the Android phone is incompatible with the version the jar was compiled for. But I am less convinced of that now I think it is something else. Can anyone shed some light on this for me please?
Damien

The module-info is used only with Java 9 and up for the new "Jigsaw" module feature added with Java 9:
https://www.oracle.com/corporate/features/understanding-java-9-modules.html
AFAIK Android does not yet support Java 9, but does support most, if not all, of Java 8.
Does Android Studio 3 support Java 9 for Android development? If so, what features of Java 9 are supported?
You can delete the compiled file module-info.class, it doesn't need to be there when not using modules. You will find it inside the jar file javax.json.bind-api-1.0.jar, and you can remove it using any zip file or jar tool like winzip, winrar, gzip, zip, or jar.

Related

Gradle: keyword `cvs` not allowed in java package name

I tried to create an Android project with package com.cvs.app and Gradle is crashing during the build. If I remove cvs from the package - works fine.
Note: cvs in the package works fine with Gradle version 3.2 and lower.
Is there a list of prohibited keywords in Gradle?
Can I overcome this limitation somehow?
As #Martheen mentioned in comments - this is a knows issue in Gradle - github.com/gradle/gradle/issues/5321
Seems to be resolved in 4.0.10

Android Studio Java Module does not find dependencies

I always get problems in my Android Studio Projects when I accidentally update parts of the IDE.
Usually it is always grade which complains it can´t find build tools anymore what so ever. If anyone could give me a hint how to avoid it ( I really don't got to have the latest versions, I'd rather stick to one and avoid updates and broken projects) it would be very much appreciated.
But currently a even stranger problem occurred.
The Gradle build works but when running the code this error is thrown:
Error:(62, 22) Gradle: error: package com.apple.eawt does not exist
My build.gradle file is this.
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
My JDK versions in library/Java/JavaVirtualMachines are
1.6.0 , 1.7.0 and 1.8.0
in 1.6.0 the ui.jar ist included but as soon as I change the JDK in the project structure it tells me I must use java 1.8
Any help is appreciated!
EDIT: I managed to solve it by adding jar dependency into my build path.
I had to add the UI.jar which includes the eawt classes.
Now my application is complaining that it can´t find audio resources and images. They are in the resource folder, they worked before....
Does anybody got an idea what the source of these problems is? It's all connected, the missing com.apple.eawt which I had to add again and my resource files. What causes these problems?
Ok I found the solution myself. The jar archive which gets created by gradle was missing. I have no clue why it got lost, but after adding it again:
Module-rightclick-Module Properties-> add jar dependency-> search modulname.jar archive in module directory/build/... and add it, it worked fine again.
In my example as shown in my project folder it would be the javalib folder (module) /build/libs/javalib.jar (modulename.jar)
Here is the official documentation for this archive file:
I guess for newer versions things changed because I can't find those archives anymore in my newer projects. Does anybody know something about this?

#Generated annotation using gradlew + dagger

I'm confronting a weird issue using gradlew(4.10.2) + dagger(2.18).
The problem is when I call:
./gradlew :app:compileDebugAndroidTestKotlin
The build fails with:
Task :Common:compileDebugJavaWithJavac FAILED
/CommonModule_ProvidesGsonFactory.java:6: error: package javax.annotation.processing does not exist
import javax.annotation.processing.Generated;
/CommonModule_ProvidesGsonFactory.java:8: error: cannot find symbol
#Generated(
But if I run the task from Android Studio, the task succeed and the #Generated is not present in the dagger generated class.
Do you have some clue to avoid the #Generated annotation using ./gradlew?
if you have :
javax annotation does not exist
I have this issue on my macOS
this error occures because your jdk is above of 1.8
just add below code on build.gradle of your apps .
//Resolve jdk8+ Generation Annotations - javax annotation does not exist
compileOnly 'com.github.pengrad:jdk9-deps:1.0'
Dagger uses auto-common's GeneratedAnnotations to figure out which #Generated annotation to use. It does this based on the classpath.
What this means is that while the annotation processor is running, javax.annotation.processing.Generated is available and used in the generator, but when the resulting file is compile in another task, it is no longer on the classpath.
Potential causes could be that code was generated using a newer version of the JDK and the incremental build is invalid, requiring a full "clean & rebuild" or there is a problem with java language levels where the annotation processor runs on Java 9+, but android is compiled as Java 8 or lower.
Using ./gradlew compileDebugAndroidTestKotlin -Dorg.gradle.java.home=<Android studio jre path> solved the problem.
I had this problem when I updated my Android Studio to 4.2
The problem was solved when I upgrade the Kotlin version from 1.3.51 to 1.4.31
It seems the problem is reported and solved in this issue:
https://github.com/google/dagger/issues/1449
https://youtrack.jetbrains.com/issue/KT-32804
change to embeded Android studio version and only clean!(not rebuild) Improove #kiskae answer
I also got "package javax.annotation.processing does not exist import javax.annotation.processing.Generated" in Android Studio while trying to build the project with Gradle.
Due to some reasons I cannot upgrade any dependencies in the project. What worked for me in this case:
not only install Java 8 instead of any higher Java versions you have (you can download it from here, for example: https://www.oracle.com/ru/java/technologies/javase/javase-jdk8-downloads.html),
but also check out Project Structure -> SDK location -> JDK location and make sure that this folder really contains jdk. The right option to choose can start with JAVA_HOME, for instance.
My case was that after some update this location was set by default as embedded JDK which did not contain any jdk and as a quite newbie to Android I have spent a couple of beautiful hours trying to figure out what's wrong with my Java 8.
In my case I change "Gradle JDK" and it's work perfectly.
Go to "File ==> project structure ==> SDK Location ==> Gradle settings ==> then change the selected gradle JDK from the drop down menu "
Hope this will help you.

Does Android API 18 supports jdk1.7.0_80?

I use jdk1.7.0_80 for my project but there is a .jar file which apparently compiled with jdk1.6. I'm getting some exception related to that library and tells some files are not defined but I didn't modify anything related to that since six months ago. I want to know the conflict between used JDKs break something?
if you open old projects usually version conflicts will happen. gradle, android tools even android studio had an issue after upgrade. but in your case you say jar file compiled with 1.6 and java 7 had a problem. with java 8, my old jar file didnt created a problem in my project so you might want to delete jdk 7 and install jdk8update74, which is the latest version.

How to use a java 8 library with android?

I'm trying to use a library that uses java 8 in my android project. I cannot find a way to make this work. I've tried to use retro lambda but it has not helped. I keep getting the error: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version(0034.0000)
I've researched this and learned it's because there is java 8 syntax in the included library. I've been compiling with java 8 sdk and am using android studio 08.2. Help!
The library is:https://github.com/robrua/Orianna
Solution 1
Wait for android to support Java8.
Solution 2
Use an earlier version of the library that isn't Java8 and/or ask the developer of the library to provide one/ the last Java6 (or Java7 for kitcat upwards) library.
Solution 3
This is some kind of hack and I haven't tested or even used it!
Use retrolambda to backport the Java8-bytecode to Java6. On the homepage of retrolambda you find some documentation about it.
Downloads of retrolambda are here.
Probably you will have to unzip the library jar to a folder and the run a command like the following:
java -Dretrolambda.inputDir=<extracted_classfiles>
-Dretrolambda.classpath=<extracted_classfiles>
-Dretrolambda.bytecodeVersion=50
-javaagent:retrolambda.jar
-jar retrolambda.jar
Maybe you have to extend the classpath depending on the dependencies of the library.
Then you have to copy the resulting jar-file into your android-project's lib folder.
It is also possible to program Java8 for android.
If retrolambda doesn't work maybe you can find another tool to backport Java8-bytecode to Java6-bytecode.

Categories

Resources