Search code examples
androidlmdbchaquopy

Failing to install python package 'lmdb' via chaquopy to android studio project


I quickly summarize as far as I got and appreciate any help. I'm really stuck on this... Please also give me a hint if I have not provided enough information to answer the question as I am new here :)

The python package 'lmdb' is written partly in python and C (see here). Because the package is not only written in python, a windows c++ compiler is needed when installing with pip. Alternatively one can install via a wheel file (see here). As far as I know, the possibility to install via conda in chaquopy is not given.

For me, installing with a wheel was not a success. (this i the file I used Building/synchronizing the project works well, running the application creates an error in build output when installing 'lmdb'. This is the error I got:

ModuleNotFoundError: No module named 'patch_ng'

I installed patch-ng additionally (link) and also created an own package named patch_ng including only the patch_ng.py file. Still got the same error.

This is the code inside the build.gradle file on application level:

android {
    compileSdk 32

    defaultConfig {
        applicationId "<name>"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        ndk {
            abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
        }

        python {
            version "3.8"

            buildPython "<path_to_anaconda>\\anaconda3\\python.exe"

            pip{
                // install "patch-ng"
                // install ".\\src\\main\\python\\patch_ng"
                // BOTH FOLLOWING LINES DID NOT WORK FOR ME ( TRIED ONE AFTER THE OTHER)
                install  "lmdb"
                install "libs\\lmdb-1.3.0-cp310-cp310-win_amd64.whl"
            }

            pip {
                install "scipy"
                install "requests==2.24.0"
                install "numpy"
                install "pandas"
                //install "paddleocr"
            }
        }

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

Solution

  • To install packages with C components on Android, you'd need to build an Android-compatible wheel. The instructions for doing that are here.

    There's also an existing entry for lmdb on the Chaquopy issue tracker, which would be the best place for any further discussion.