Use libraries external

Hi evrybody !
I am creating an extension that uses an external library. the librarie is proj4j (https://github.com/locationtech/proj4j) that allows converting coordinates between the differents plane state systems and geographic systems. The extension I tested in eclipse and it worked perfect. I think I have linked the library well in my code but still the ANT compiler does not seem to understand the classes.
my funtion in Eclipse:
image
my extension code:
image
the error Runtime:
AndroidRuntime:
[mkdir] Created dir: D:\AI2 PROYECTOS\CrearExtensiones\appinventor-sources\appinventor\components\build\classes\AndroidRuntime
[javac] Compiling 292 source files to D:\AI2 PROYECTOS\CrearExtensiones\appinventor-sources\appinventor\components\build\classes\AndroidRuntime
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] Note: Wrote file file:/D:/AI2%20PROYECTOS/CrearExtensiones/appinventor-sources/appinventor/components/build/classes/AndroidRuntime/simple_components.json
[javac] Note: Wrote file file:/D:/AI2%20PROYECTOS/CrearExtensiones/appinventor-sources/appinventor/components/build/classes/AndroidRuntime/simple_components.txt
[javac] Note: Wrote file file:/D:/AI2%20PROYECTOS/CrearExtensiones/appinventor-sources/appinventor/components/build/classes/AndroidRuntime/simple_components_build_info.json
[javac] Note: Wrote file file:/D:/AI2%20PROYECTOS/CrearExtensiones/appinventor-sources/appinventor/components/build/classes/AndroidRuntime/AutogeneratedOdeMessages.java
[javac] Note: Wrote file file:/D:/AI2%20PROYECTOS/CrearExtensiones/appinventor-sources/appinventor/components/build/classes/AndroidRuntime/ComponentsTranslation.java
[javac] D:\AI2 PROYECTOS\CrearExtensiones\appinventor-sources\appinventor\components\src\com\geomatica\converCor\ConverCor.java:141: error: cannot find symbol
[javac] CRSFactory factory = new CRSFactory();
[javac] ^
[javac] symbol: class CRSFactory
[javac] location: class ConverCor
[javac] D:\AI2 PROYECTOS\CrearExtensiones\appinventor-sources\appinventor\components\src\com\geomatica\converCor\ConverCor.java:141: error: cannot find symbol
[javac] CRSFactory factory = new CRSFactory();
[javac] ^
[javac] symbol: class CRSFactory
[javac] location: class ConverCor
[javac] D:\AI2 PROYECTOS\CrearExtensiones\appinventor-sources\appinventor\components\src\com\geomatica\converCor\ConverCor.java:143: error: cannot find symbol
[javac] CoordinateReferenceSystem srcCrs = factory.createFromName("Wgs84");
[javac] ^
[javac] symbol: class CoordinateReferenceSystem
[javac] location: class ConverCor
[javac] D:\AI2 PROYECTOS\CrearExtensiones\appinventor-sources\appinventor\components\src\com\geomatica\converCor\ConverCor.java:144: error: cannot find symbol
[javac] CoordinateReferenceSystem dstCrs = factory.createFromName("CrsDestino", WktCrsB);
[javac] ^
[javac] symbol: class CoordinateReferenceSystem
[javac] location: class ConverCor
[javac] D:\AI2 PROYECTOS\CrearExtensiones\appinventor-sources\appinventor\components\src\com\geomatica\converCor\ConverCor.java:146: error: cannot find symbol
[javac] BasicCoordinateTransform transform = new BasicCoordinateTransform(srcCrs,dstCrs);
[javac] ^
[javac] symbol: class BasicCoordinateTransform
[javac] location: class ConverCor
[javac] D:\AI2 PROYECTOS\CrearExtensiones\appinventor-sources\appinventor\components\src\com\geomatica\converCor\ConverCor.java:146: error: cannot find symbol
[javac] BasicCoordinateTransform transform = new BasicCoordinateTransform(srcCrs,dstCrs);
[javac] ^
[javac] symbol: class BasicCoordinateTransform
[javac] location: class ConverCor
[javac] D:\AI2 PROYECTOS\CrearExtensiones\appinventor-sources\appinventor\components\src\com\geomatica\converCor\ConverCor.java:154: error: cannot find symbol
[javac] ProjCoordinate srcCoord = new ProjCoordinate(loIdeg,laIdeg);
[javac] ^
[javac] symbol: class ProjCoordinate
[javac] location: class ConverCor
[javac] D:\AI2 PROYECTOS\CrearExtensiones\appinventor-sources\appinventor\components\src\com\geomatica\converCor\ConverCor.java:154: error: cannot find symbol
[javac] ProjCoordinate srcCoord = new ProjCoordinate(loIdeg,laIdeg);
[javac] ^
[javac] symbol: class ProjCoordinate
[javac] location: class ConverCor
[javac] D:\AI2 PROYECTOS\CrearExtensiones\appinventor-sources\appinventor\components\src\com\geomatica\converCor\ConverCor.java:155: error: cannot find symbol
[javac] ProjCoordinate dstCoord = new ProjCoordinate();
[javac] ^
[javac] symbol: class ProjCoordinate
[javac] location: class ConverCor
[javac] D:\AI2 PROYECTOS\CrearExtensiones\appinventor-sources\appinventor\components\src\com\geomatica\converCor\ConverCor.java:155: error: cannot find symbol
[javac] ProjCoordinate dstCoord = new ProjCoordinate();
[javac] ^
[javac] symbol: class ProjCoordinate
[javac] location: class ConverCor
[javac] D:\AI2 PROYECTOS\CrearExtensiones\appinventor-sources\appinventor\components\src\com\geomatica\converCor\ConverCor.java:165: error: cannot find symbol
[javac] coorXY.add(X);
[javac] ^
[javac] symbol: variable X
[javac] location: class ConverCor
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 11 errors

BUILD FAILED
D:\AI2 PROYECTOS\CrearExtensiones\appinventor-sources\appinventor\build.xml:46: The following error occurred while executing this line:
D:\AI2 PROYECTOS\CrearExtensiones\appinventor-sources\appinventor\components\build.xml:217: The following error occurred while executing this line:
D:\AI2 PROYECTOS\CrearExtensiones\appinventor-sources\appinventor\build-common.xml:125: Compile failed; see the compiler error output for details.

Total time: 27 seconds
Picked up _JAVA_OPTIONS: -Xmx1024M

..I appreciate any help you can give me

You will have to post full code here.
Also note that while using app inventor sources to make extensions you need to add jar to lib folder and define it in components/build.xml file.
Check this for more info:
https://docs.google.com/document/d/1xk9dMfczvjbbwD-wMsr-ffqkTlE3ga0ocCE1KOb2wvw/pub#h.3kn0fmfydnq1

1 Like

the .jar librarie


the copy sentence in my buil.xml

my extension code

package com.geomatica.converCor;

// © Ing. Ruben Dario Cuervo

// https://topografo-ruben-cuervo.business.site "

// cuervoman99@gmail.com

// Creacion de extensiones para la geomatica. Mayo 2021.

// Esta extension convierte coordenadas geograficas a planas y viceversa.

import com.google.appinventor.components.common.ComponentCategory;

import com.google.appinventor.components.common.PropertyTypeConstants;

import com.google.appinventor.components.annotations.*;

import com.google.appinventor.components.runtime.*;

import com.google.appinventor.components.common.YaVersion;

import com.google.appinventor.components.runtime.errors.YailRuntimeError;

import java.lang.NumberFormatException;

import java.util.LinkedList;

import java.util.List;

//import librarie proj4j.jar;

@UsesLibraries(libraries = "proj4j.jar")

@DesignerComponent(version = ConverCor.VERSION,

description = "Conversion de coordendas geograficas a planas y viceversa. " + "Ruben Dario Cuervo H.",

category = ComponentCategory.EXTENSION,

nonVisible = true,

iconName = "")

@SimpleObject(external = true)

public class ConverCor extends AndroidNonvisibleComponent implements Component {

  public static final String[] cmtCali_wkt = new String[] {

    "+proj=tmerc",

    "+lat_0=3.446927122222",

    "+lon_0=-76.543802852778",

    "+k=1",

    "+x_0=110000",

    "+y_0=110000",

    "+a=6379388",

    "+b=6357911.946",

    "+units=m",

    "+no_defs"

   };

public static final String[] MCV2009_wkt = new String[] {

    "+proj=tmerc",

    "+lat_0=3.441883055556",

    "+lon_0=-76.52056250",

    "+k=1",

    "+x_0=1061900.18",

    "+y_0=872364.63",

    "+a=6379137",

    "+b=6357752.314",

    "+units=m",

    "+no_defs"

   };

public static final String[] CMT12_wkt = new String[] {

    "+proj=tmerc",

    "+lat_0=4",

    "+lon_0=-73",

    "+k=0.9992",

    "+x_0=5000000",

    "+y_0=2000000",

    "+ellps=GRS80",

    "+units=m",

    "+no_defs"

   };



public static final int VERSION = 1;

        

public static final String DEFAULT_CRS_A = "EPSG:4326";

public static final String DEFAULT_CRS_B = "EPSG:3115";

public static final float DEFAULT_LODEG = 0f;

public static final float DEFAULT_LADEG = 0f;

public static final float DEFAULT_X = 0f;

public static final float DEFAULT_Y = 0f;

private ComponentContainer container;

private String crs_a = "";

private String crs_b;

private float lodeg = 0.0f;

private float ladeg = 0.0f;

private float x = 0.0f;

private float y = 0.0f;

public ConverCor(ComponentContainer container) {

    super(container.$form());

    this.container = container;

    Crs_A(DEFAULT_CRS_A);

    Crs_B(DEFAULT_CRS_B);

    LoDeg(DEFAULT_LODEG);

    LaDeg(DEFAULT_LADEG);

}

// Obtener los valores /  Getter methods.

@SimpleProperty(category = PropertyCategory.BEHAVIOR)

public String Crs_A() {

    return crs_a;

}   

 @SimpleProperty(category = PropertyCategory.BEHAVIOR)

public String Crs_B() {

    return crs_b;

}

@SimpleProperty(category = PropertyCategory.BEHAVIOR)

public float LoDeg() {

    return lodeg;

}

@SimpleProperty(category = PropertyCategory.BEHAVIOR)

public float LaDeg() {

    return ladeg;

}

// Establecer valores // Setter methods.

@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_STRING, defaultValue = "" )

@SimpleProperty(description = "Asigna el valor del CRS A. " +  "Sistema de cordenadas inicial")

public void Crs_A(String nuevoCrs_A) {

    this.crs_a = nuevoCrs_A;

}



@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_STRING, defaultValue = "")

@SimpleProperty(description = "Asigna el valor del CRS B. " +  "sistema de coordenadas final")

public void Crs_B(String nuevoCrs_B) {

    this.crs_b = nuevoCrs_B;

}

@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_FLOAT, defaultValue = "")

@SimpleProperty(description = "Asigna la longitud en decimales. " +  "o la x coordenada inicial")

public void LoDeg(float nuevoLoDeg) {

    this.lodeg = nuevoLoDeg;

}

@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_FLOAT, defaultValue = "" )

@SimpleProperty(description = "Asigna la latitud en decimales. " +  "o la y coordenada inicial")

public void LaDeg(float nuevoLaDeg) {

    this.ladeg = nuevoLaDeg;

}

// Funcion para calcular de coordenadas geograficas a planas usando la libreria proj4j

// Funtion that convert geographics Latitude and Longitude

// to local Projected mercator transverse. 

@SimpleFunction(description = "Introduce la longitud, la latitud y EL CRS destino ,obtendras las coordenadas finales.")

public List GeoToPlane(float loIdeg, float laIdeg, String WktCrsB ) {

    

    CRSFactory factory = new CRSFactory();

    //  CoordinateReferenceSystem dstCrs = factory.createFromName("EPSG:3115");

    CoordinateReferenceSystem srcCrs = factory.createFromName("Wgs84"); 

    CoordinateReferenceSystem dstCrs = factory.createFromName("CrsDestino", WktCrsB);

                                    

    BasicCoordinateTransform transform = new BasicCoordinateTransform(srcCrs,dstCrs);

    

//  BasicCoordinateTransform transformInv = new BasicCoordinateTransform(srcCrs,llwgs84);



//  float loDeg = ProjectionMath.dmsToDeg(-76.0,33.0,3.98217);

//  float laDeg = ProjectionMath.dmsToDeg(3.0,27.0,18.00625);

    

    // Note these are x, y or longitude, latitude in Deg mode.

    ProjCoordinate srcCoord = new ProjCoordinate(loIdeg,laIdeg);

    ProjCoordinate dstCoord = new ProjCoordinate();

            

    // Writes result into dstCoord

    transform.transform(srcCoord, dstCoord);

    

//System.out.println("X== " + dstCoord.x +"/ Y=N= "+ dstCoord.y);

      float x = dstCoord.x;

      float y = dstCoord.y;

      List coorXY = new LinkedList();

      coorXY.add(X);

      coorXY.add(y);

//    YaiList ycoorXY = YailList.MakeList(coorXY);

//    String scoorXY =  YailList.ToString(ycoorXY);

   YaCalculado(coorXY); 

    return coorXY;

}

// Bloque disponible despues de calcular las coordenadas.

@SimpleEvent(description = "Muestra las coordenadas calculadas.")

public void YaCalculado(List coorXY){

    EventDispatcher.dispatchEvent(this, "YaCalculado", coorXY);

}    

}

1 Like

should be
@UsesLibraries(libraries = "proj4/proj4j.jar")

1 Like

Please remove your email from your post.

1 Like

sorry. how i do it?

1 Like

No, that's not needed.


@cuervoman99 you have not imported those classes.

2 Likes

how i do it?

1 Like

Let's say A is class of jar ABC having com.pkgOfJar as its package name.
So to import class A and use it in your class you will have to write import com.pkgOfJar.A;

I suggest you to copy imports from your Eclipse project.

1 Like

thanks. I'm going to try and I'll tell you

1 Like