[Python] How to import Python in Kotlin?(android studio)

Discussão em 'Python' iniciado por Stack, Fevereiro 8, 2025.

  1. Stack

    Stack Membro Participativo

    I want to import Python in Android Studio using chaquopy. I installed Python 3.8.0 and put it in the same directory as the specified directory, and I got the error message: Unresolved reference: buildPython. Is there any library I have to plugin in build.gradle?

    Here's the code below.

    1. build.gradle.kts(Project):

    buildscript {
    repositories {
    google()
    mavenCentral()
    maven("https://chaquo.com/maven")
    }
    dependencies {
    classpath("com.android.tools.build:gradle:8.7.2")
    classpath("com.chaquo.python:gradle:16.0.0")
    }
    }

    plugins {
    id("com.android.application") version "7.4.0" apply false // Android Application Plugin
    id("org.jetbrains.kotlin.android") version "1.9.10" apply false // Kotlin Android Plugin
    id("com.chaquo.python") version "16.0.0" apply false
    }

    1. build.gradle.kts(Module):

    plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
    id("com.chaquo.python")
    }

    android {
    namespace = "com.example.test"
    compileSdk = 35

    defaultConfig {
    applicationId = "com.example.test"
    minSdk = 31
    targetSdk = 35
    versionCode = 1
    versionName = "1.0"
    buildPython = "C:/Python38/python.exe"

    ndk {
    abiFilters += listOf("arm64-v8a", "armeabi-v7a", "x86_64", "x86")
    }
    }

    chaquopy{
    defaultConfig {
    version = "3.8"
    buildPython("C:/Test_241115_23/Test/app/python/test.py", "-3.8")
    extractPackages("")
    }
    }

    dependencies {
    // Kotlin standard library
    implementation("org.jetbrains.kotlin:kotlin-stdlib:2.0.21")
    }


    I appreciate your help.

    Continue reading...

Compartilhe esta Página