B4A Library [Tool] Simple Library Compiler - Build libraries without Eclipse

Status
Not open for further replies.

agb2008

Member
Licensed User
Longtime User
I am trying to create a B4J library. Source .java files were in cp1251 encoding - so I converted them to UTF-8 w/o BOM using Notepad++.
Compilation complete without any errors - but when at the stage: "Creation XML file" I've got errors for each .java file: "error: unmappable
character for encoding Cp1251
" and then text in wrong encoding... But why ? I've already converted all files in my project to UTF-8.
Could you please advice ?
 

Asim A Baki

Active Member
Licensed User
Longtime User
I can't compile vitamio bundle library from source, it gives an error, while I successfully exported the jar and javadoc from eclipse


B4X:
Starting step: Compiling Java code.
javac 1.7.0_51
D:\Downloads\VitamioBundle-4.2.0-eclipse-source\VitamioBundle-4.2.0-B4A\src\uk\co\martinpearman\b4a\vitamio\widget\MediaController.java:3: error: package io.vov.vitamio.widget does not exist
import io.vov.vitamio.widget.OutlineTextView;
                            ^
1 error


Error.
 

Asim A Baki

Active Member
Licensed User
Longtime User
Now after successful compilation with now warnings, when I try to compile my B4A project I face this error

class file for io.vov.vitamio.widget.VideoView not found
java.lang.UnsatisfiedLinkError: Couldn't load vinit from loader dalvik.system.PathClassLoader[DexPathList[[zip file "xxxxpro-1.apk"],nativeLibraryDirectories=[/data/app-lib/xxxxpro-1, /vendor/lib, /system/lib]]]: findLibrary returned null

I used DependsOn in the project
When I remove it I get a mismatch with Build error

Any Ideas?
 
Last edited:

b4xscripter

Member
Licensed User
Longtime User
Just one question. I'm wrapping a library with an event methods, just like Location_LocationChanged from the LocationManager.
I am not good in Java and I don't know how to "take" the event from a java code. Here goes my code:

B4X:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package io.socket;

import java.net.MalformedURLException;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

/**
*
* @author XXXXXX
*/
public class SocketIOClient {
private SocketIO socket;
public SocketIOClient(String host) throws MalformedURLException {
   
                        this.socket = new SocketIO(host);
                socket.connect(new IOCallback() {
            @Override
            public void onMessage(JSONObject json, IOAcknowledge ack) {
                try {
                    System.out.println("Server said:" + json.toString(2));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onMessage(String data, IOAcknowledge ack) {
                System.out.println("Server said: " + data);
            }

            @Override
            public void onError(SocketIOException socketIOException) {
                System.out.println("an Error occured");
                socketIOException.printStackTrace();
            }

            @Override
            public void onDisconnect() {
                System.out.println("Connection terminated.");
            }

            @Override
            public void onConnect() {
                System.out.println("Connection established");
            }

            @Override
            public void on(String event, IOAcknowledge ack, Object... args) {
                System.out.println("Server triggered event '" + event + "'");
            }
                        });
                                }
public void initialize(String host) throws MalformedURLException        
{
          SocketIOClient sc = new SocketIOClient(host);
          socket = sc.socket;
}
public void emit(String event,String jsonStr) throws ParseException {

                        org.json.simple.JSONObject jsonConf = null;
                        jsonConf = (org.json.simple.JSONObject)new JSONParser().parse(jsonStr);
                        socket.emit("joinCloud",jsonConf);              
}
}


From B4A, after the library is compiled, I can see the emit and initialize methods. But I need to "catch" the methods with @override.
Can I do it using de Simple Library Compiler?

Thank in advance, guys!
 

b4xscripter

Member
Licensed User
Longtime User
Well, using the Simple Library Compiler I could compile it:

B4X:
package anywheresoftware.b4a.SocketIOClient;

import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.*;
import anywheresoftware.b4a.BA;
import android.telephony.*;



import java.net.MalformedURLException;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.json.simple.parser.ParseException;
import io.socket.*;



@Permissions(values={"android.permission.INTERNET"})
@ShortName("SocketIOClient")
@DependsOn(values={"json-org","json-simple-1.1.1","WebSocket","socket2"})
@ActivityObject
@Events(values={"OnConnect(json as String)"})



public class SocketIOClient {
private SocketIO socket;
private BA ba;
private String eventName;
public void connect(String host) throws MalformedURLException {
   
      this.socket = new SocketIO(host);
          socket.connect(new IOCallback() {
            @Override
            public void onMessage(JSONObject json, IOAcknowledge ack) {
                try {
                    System.out.println("Server said:" + json.toString(2));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onMessage(String data, IOAcknowledge ack) {
                System.out.println("Server said: " + data);
            }

            @Override
            public void onError(SocketIOException socketIOException) {
                System.out.println("an Error occured");
                socketIOException.printStackTrace();
            }

            @Override
            public void onDisconnect() {
                System.out.println("Connection terminated.");
            }

            @Override
            public void onConnect() {
                System.out.println("Connection established");
                ba.raiseEvent(this, eventName + "_onconnect","OK");
            }

            @Override
            public void on(String event, IOAcknowledge ack, Object... args) {
                System.out.println("Server triggered event '" + event + "'");
            }
                        });
                                }
public void initialize(BA ba, String EventName) throws MalformedURLException        
{
          this.ba = ba;
          this.eventName = EventName.toLowerCase(BA.cul);
}

}


Here goes my question because I don't understand very well what name should I use in my case to get the event working.....


B4X:
@Events(values={"OnConnect(json as String)"})

Should I put this one?

B4X:
Sub OnConnect(valor As String)
Msgbox("connected!","info")  

End Sub



Or this one, supposing that I initialize it this way:


B4X:
     Sub Globals

    Dim socket As SocketIOClient

End Sub

Sub Activity_Create(FirstTime As Boolean)
     DisableStrictMode
     socket.initialize("socket")
     socket.connect("http://192.168.1.3:8080/")

End Sub

Sub socket_onconnect(valor As String)
Msgbox("connected!","info")  

End Sub


I supposed this last name because of the:

B4X:
ba.raiseEvent(this, eventName + "_onconnect","OK");


Could anyone help me?

Thank you!!!!
 

ac9ts

Active Member
Licensed User
Longtime User
I have successfully compiled the source. I am having an issue with the generated XML file. I am getting the following error but am unsure on where to look since there are no source line numbers listed. I am using v1.03.

B4X:
Starting step: Compiling Java code.
Completed successfully.
Starting step: Creating jar file.
Completed successfully.
Starting step: Creating XML file.
java.lang.NullPointerException
    at BADoclet.writeClass(BADoclet.java:175)
    at BADoclet.start(BADoclet.java:376)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.sun.tools.javadoc.DocletInvoker.invoke(DocletInvoker.java:310)
    at com.sun.tools.javadoc.DocletInvoker.start(DocletInvoker.java:189)
    at com.sun.tools.javadoc.Start.parseAndExecute(Start.java:366)
    at com.sun.tools.javadoc.Start.begin(Start.java:219)
    at com.sun.tools.javadoc.Start.begin(Start.java:205)
    at com.sun.tools.javadoc.Main.execute(Main.java:64)
    at com.sun.tools.javadoc.Main.main(Main.java:54)

Error.

It seems to be tripping up on figuring out what to do with parameter type "Locale"
This is the code being parsed.
B4X:
    /**
     * Sets the launch options.
     *
     * @param relaunchIfRunning Launches the app even if the same application is running on the receiver
     * @param locale The {@link Locale}
     */

    public void setLaunchOptions(boolean relaunchIfRunning, Locale locale) {
        mLaunchOptions = new LaunchOptions.Builder().setLocale(locale).setRelaunchIfRunning(relaunchIfRunning).build();
    }

and this is the last lines of the XML file.
B4X:
<method>
            <name>setLaunchOptions</name>
            <comment>Sets the launch options.
relaunchIfRunning: Launches the app even if the same application is running on the receiver
locale: The (@link Locale)</comment>
            <returntype>void</returnt
 
Last edited:

ac9ts

Active Member
Licensed User
Longtime User
I'm wrapping a SDK and I don't want to change names (unless I have to) as the library compiles as is. Is the change you are suggesting to get it through the XML generation? Is it getting stuck on set/get combinations?
 

ac9ts

Active Member
Licensed User
Longtime User
What are the rules that the parser is using to build the XML file? I changed the line as suggested and it parsed it but I'm getting the same error further in. If having a method name capitalized causes it to be exposed and lower case "hides" it, there are many other methods that were parsed that have lower case names. I'm not a Java guy (that's why I purchased b4a) so any little hint on what I need to do to complete this library would be helpful.

I'm not sure how easy this would be to do but if the line that is causing this error could be displayed, it would make it a bit easier to debug.
 
Last edited:

ac9ts

Active Member
Licensed User
Longtime User
So, based on the error I'm receiving, is there a "set" without a passed parameter or a "get" with a void return type? I'm grasping at straws here.

I am changing certain names such as setUpLauncher() to setupLauncher() as I know these are not properties. Should I also change them to _setupLauncher() or something else so the "set" is not parsed?

B4X:
java.lang.NullPointerException
    at BADoclet.writeClass(BADoclet.java:175)
    at BADoclet.start(BADoclet.java:376)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.sun.tools.javadoc.DocletInvoker.invoke(DocletInvoker.java:310)
    at com.sun.tools.javadoc.DocletInvoker.start(DocletInvoker.java:189)
    at com.sun.tools.javadoc.Start.parseAndExecute(Start.java:366)
    at com.sun.tools.javadoc.Start.begin(Start.java:219)
    at com.sun.tools.javadoc.Start.begin(Start.java:205)
    at com.sun.tools.javadoc.Main.execute(Main.java:64)
    at com.sun.tools.javadoc.Main.main(Main.java:54)

Error.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…