Search code examples
android-studiochaquopy

Will apps developed using chaquopy create issues while deployment?


I would like to use chaquopy for the communication between java/kotlin and python code in android Studio. Below shown is my build gradle file:

    plugins {
    id 'com.android.application'
    id 'com.chaquo.python'
    }

    android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.image_processing_using_chaquopy"
        python{
            pip{
                install "numpy"
                install "opencv-contrib-python-headless"
                install "pillow"
          

            }
        }
        sourceSets{
            main{
                python{
                    srcDirs = ["src/main/python"]
                }
            }
        }
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }

        python{
            buildPython "C:/Users/hp/AppData/Local/Programs/Python/Python39/python.exe"
        }
    }

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

dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

Here, we are giving the python.exe local path and chaquopy is not listed in the dependencies too. Will it cause any problem while deploying this app on android phones or some other external devices?


Solution

  • Here, we are giving the python.exe local path

    This only affects the build process: this path is not used at runtime. In fact, it couldn't be used at runtime even if we wanted to, because an Android app has no direct access to the filesystem of your computer, even when you're using an emulator.

    However, to make it easier for other developers to build your source code, it would be better to remove the buildPython line and allow Chaquopy to find Python on the PATH, as it says in the documentation. If you installed Python from python.org using the default settings, then the py launcher will already be on the PATH, so this will work automatically.

    chaquopy is not listed in the dependencies too

    That's no problem: the Chaquopy plugin at the top of the file will add any necessary dependencies.