I'm trying to create a Java Binding Library for Xamarin.Android.
I have created library with several errors, but i have handled them.
Problem exists when I'm trying to use this library in Xamarin.Android project.
I'm trying to port FreeFLow library
This is my application build result (posted only one of ~30 similar errors):
Error 1 package com.comcast.freeflow.core.AbsLayoutContainer does not exist
com.comcast.freeflow.core.AbsLayoutContainer.OnItemClickListener
And this error leads to .java file, which starts with:
public class AbsLayoutContainer_OnItemClickListenerImplementor
extends java.lang.Object
implements
mono.android.IGCUserPeer,
com.comcast.freeflow.core.AbsLayoutContainer.OnItemClickListener
Related
I generated a simple libGDX project with no dependencies. When I tried to build it as HTML app with Gradle (./gradlew html:dist), I get the following error message:
Tracing compile failure path for type 'xjcl.downgradius.client.HtmlLauncher'
[ERROR] Errors in 'file:/home/jan/Dropbox/py/AndroidStudioProjects/Downgradius_Android/html/src/xjcl/downgradius/client/HtmlLauncher.java'
[ERROR] Line 49: No source code is available for type xjcl.downgradius.DowngradiusGame; did you forget to inherit a required module?
I think the problem is caused by me using Kotlin in this project, and libGDX being intended for Java development. I observed that when I made a new main Game class in Java, that class was found by GWT, but not the Kotlin classes it imports.
I know Kotlin does some re-packaging (for example, if you put funA and funB in file Foo, they will be re-packaged as part of a new FooKt package, I think), but it should be able to find it as
it is declared in the right package (xjcl.downgradius)
it is declared as the only class in its file
I get no IDE warnings about importing it from Java.
I also tried converting Kotlin to Java code but the resulting Java code was full of errors.
Your assumptions are correct. GWT compiler works on Java sources. The error message it gives you is correct: There are no Java source code files to be found, you say it yourself that you used Kotlin.
If you want to use GWT, convert to correct Java source code.
Say an Android app uses a jar library and everything is working fine when the library is specified as a dependency:
dependencies {
...
...
compile 'org.example:example:1.1.1'
...
}
BUT : one of the classes in the org.example code needs to be tweaked.
One approach is to obtain the source code and put all of that in the java folder, and remove the module. When the tweak is made, that, and the entire library will be compiled.
Another approach is to make the tweak, compile, and replace the .class file within the .jar file.
Both of those methods have their drawbacks.
My question is: Is there an easier way to tweak code in a library?
When I tried just creating the package, placing the class that needed changing into the java folder, I got an error:
Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lorg/example/ClassNeedingChange;
I just wondered if there was a trick to getting code in the Java folder to override whats in a library jar file.
Additional Info:
Although not stated specifically above, the class that needs tweaking is buried in the library and is referenced by the library's code; I don't call it directly. For the simple case where the class that needed tweaking is one that my code (and only my code) called directly, then it would be a simple matter of extending the class using the Java construct. But for this simple case, I would not need to post this question.
Extend the class that needs tweaked in your code, and override the appropriate method.
Class A extends TweakMe {
#Override
public void someTweakedMethod() {
//Do stuff
}
}
I'm converting native Java code to android one.
There is a Android Java code from a native Java as following:
import com.jayway.jsonpath.JsonPath;
...
body = new String(bodyPart);
JsonPath.with(body).getString("psIp");
...
However, there is no with method in Android. How can I convert it?
JsonPath class comes from some library (most likely 'com.jayway.jsonpath:json-path:0.8.1'), which has com.jayway.jsonpathpackage. This class is not present neither in native Java, nor in native Android.
You have a dependency to that library, that has JsonPath class, in your Java project (anyway you added it - either through gradle, maven, or simply by adding a reference to jar file through IDE). If you would add that dependency to your Android project (gradle is preferred for adding dependencies in Android, though you can add it any other way), you will be able to use JsonPath class in your Android code also.
I am developing an android app which process speech and I have speech basic project (dependency for android project) ready on JAVA so I compiled JAVA project in eclipse in JAVA 7 compiler and exported that java project as a runnable jar.
I put this jar into my android studio project's libs folder and by right clicking selected AS A library, I got build successful message. But when I try run the android project it gives me error saying,
FATAL EXCEPTION: main Process: in.automator.automator, PID: 4242
java.lang.NoClassDefFoundError: jar_filename.Storage.class_in_jar_file
but the said class is there in the jar file, the only doubtful thing is the mentioned class file looks something like this
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioFormat.Encoding;
import marf.util.InvalidSampleFormatException;
public class MARFAudioFileFormat extends AudioFileFormat {
....
...
....
}
It refers javax.sound.sampled, so possibly that might causing the problem.
I tried searching on the google for the problem but didn't got the solution which can resolve the issue. I tried everything.
I am using JRE 7 in android studio and exporting java project in Compiler & itself.
How to resolve this error?
Thanks in advance.
You are correct, the problem lies in the fact that the library you're trying to depend on, in turn depends on the javax package hierarchy. Android does not provide javax, so those classes don't exist at runtime (even though they do exist in your computer's JDK, so your compiler doesn't complain - it's basically the same as not having a particular DLL installed that a program on your PC needs).
The NoClassDefFoundError is being thrown on the class that first references the invalid class dependencies, which is probably what's confusing. That class may indeed actually exist in your jar, but it requires classes that don't exist in order to complete its definition - so in effect, your class is not fully defined.
The only way around this is to figure out a way to do whatever you're after, without the javax namespace. I have heard of a few attempts to try to port javax.* into Android, but they never end well - many of the javax classes end up boiling down to native calls, which also won't exist on Android.
I develop an application in a "special" plugin-development environment.
This environment needs to include some java libraries by default so that the created plugin-application can be exported and used successfully.
The problem is now that the plugin-environment comes with an old "javax.mail" library. It is not supported to override this library in the environment.
Of course it is possible to include the newer javax.mail library into my plugin-application but the library is not recognized and the old library is used.
Question:
Is it possible to force a Java Application to use a special included library which is using the same package and class names like a "native" library from a "plugin-environment"?
What I have tried:
I tried to rename the package files within the custom library "javax.mail" to "javax_external.mail" and to use something like this in my application:
javax_external.mail.Session session = javax_external.mail.Session.getDefaultInstance(props);
But I get the error: Type mismatch: cannot convert from javax.mail.Session to javax.mail.Session