Skip to content

Architecture Mismatch in Native Files for Android APK #75

@vikaspizone

Description

@vikaspizone

I follow the following steps as per documents :

  1. I have built the repository for macOS on Intel-based systems and for Linux systems.

  2. I have created the native files and .jar files as expected.

image
  1. I ran the .jar file using your suggested command: java --class-path target/proj-2.1-SNAPSHOT.jar example/TransformPoints.java.
image
  1. I need to use these .jar files in my Android project, which is based on Kotlin Compose. I have imported the "proj-2.1-SNAPSHOT.jar" file and can access its classes.

  2. This .jar file produces the expected results when run in the terminal on my macOS laptop.

  3. However, when I try to build the Android project to generate a debug APK, I encounter an error.

  4. In Java, there is a file named "NativeResource.java" that contains a function called "libraryPath." This function imports a native file named "libproj-binding.dylib" (for macOS) or "libproj-binding.so" (for Linux).

image
  1. The project builds without issues, but when I run the code to access the classes, I use the following function:
private fun transformPoints() {
    try {
        val transformPoints = TransformPoints.main(arrayOf("EPSG"))
        val factory = Proj.getAuthorityFactory("EPSG")
        val regops = Proj.getOperationFactory(null)
        val sourceCRS = factory.createCoordinateReferenceSystem("4326") // WGS 84
        val targetCRS = factory.createCoordinateReferenceSystem("3857")
        val operation = regops.createOperation(sourceCRS, targetCRS)
        val coordinates = doubleArrayOf(
            45.500, -73.567,  // Montreal
            49.250, -123.100,  // Vancouver
            35.653, 139.839,  // Tokyo
            48.865, 2.349 // Paris
        )
        operation.mathTransform.transform(
            coordinates, 0,  // Source coordinates.
            coordinates, 0,  // Target coordinates (overwriting the source).
            4  // Number of points to transform.
        )

        System.out.printf("Montreal:  %11.1f %11.1f%n", coordinates[0], coordinates[1])
        System.out.printf("Vancouver: %11.1f %11.1f%n", coordinates[2], coordinates[3])
        System.out.printf("Tokyo:     %11.1f %11.1f%n", coordinates[4], coordinates[5])
        System.out.printf("Paris:     %11.1f %11.1f%n", coordinates[6], coordinates[7])
    } catch (e: Exception) {
        Log.d("proj", e.localizedMessage.toString())
    }
}
  1. This code throws an error: "throw new UnsatisfiedLinkError("Missing native file: " + nativeFile);".
image
  1. I found that the root cause of the issue is a mismatch between the architecture of "libproj-binding.dylib" (macOS) or "libproj-binding.so" (Linux) and the Android system (APK) which uses ARM64 architecture.
image
  1. Anyone Please help me generate the native file for the ARM64 architecture ?.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions