Android Studio中调用python的gradle的配置

复制代码
plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
    id("com.google.devtools.ksp")
    id("kotlin-kapt")
    id("com.chaquo.python")
}

android {
    namespace = "com.jsd.digital"
    compileSdk = 34

    defaultConfig {
        applicationId = "com.jsd.digital"
        minSdk = 24
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary = true
        }

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

        chaquopy {
            defaultConfig {
                buildPython("D:\\anaconda3\\envs\\face_re\\python.exe")

                pip {
                    options("--extra-index-url", "http://pypi.mirrors.ustc.edu.cn/simple/")
                    options("--trusted-host", "pypi.mirrors.ustc.edu.cn")
                    install("opencv-python==4.5.1.48")
                    install("dlib==19.19.0")
                    install("opencv_contrib_python==4.5.1.48")
                    install("deepface==0.0.74")
                    install("tensorflow==2.1.0")
                    install("protobuf==3.20.0")
                    install("ffmpeg-python")
                }
            }

        }
    }

    signingConfigs {
        create("keyStore") {
            storeFile = file("../digital.jks")
            storePassword = "rootgbjiGfrvf6KG7khd8K67h6g56f9q"
            keyAlias = "digital"
            keyPassword = "rootgbjiGfrvf6KG7khd8K67h6g56f9q"
        }
    }

    buildTypes {
        val signConfig = signingConfigs.getByName("keyStore")
        debug {
            signingConfig = signConfig
        }
        release {
            signingConfig = signConfig
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }
    buildFeatures {
        viewBinding = true
        compose = true
    }
    composeOptions {
        kotlinCompilerExtensionVersion = "1.4.3"
    }
    packaging {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
    ndkVersion = "28.0.12433566 rc1"
    buildToolsVersion = "34.0.0"
    kapt {
        arguments {
            arg("AROUTER_MODULE_NAME", project.name)
        }
    }
}

dependencies {
    // 引用 base 模块
    implementation(project(":base"))
    // 登录模块
    implementation(project(":login"))

    implementation("com.google.accompanist:accompanist-systemuicontroller:0.35.0-alpha")

    ksp("com.github.liujingxing.rxhttp:rxhttp-compiler:3.0.3")

    // 初始化组件库的启动器
    implementation("androidx.startup:startup-runtime:1.1.1")

    // 防止不必要的异常 crash
    implementation("com.github.SJJ-dot:Cockroach:2.0.1")
    implementation("me.weishu:free_reflection:3.0.1")

    // bugly
    implementation("com.tencent.bugly:crashreport:4.1.9.3")

    // curl
    implementation("com.github.mrmike:ok2curl:0.8.0")

    // 路由
    kapt("com.alibaba:arouter-compiler:1.5.2")

//    ksp("io.github.raamcosta.compose-destinations:ksp:2.0.0")
}

用于配置最新的Android studio项目的版本参考,版本号很重要。填的不对很容易编译失败。

其中重点的配置参数为:

复制代码
  ndk {
            abiFilters += listOf("armeabi-v7a", "arm64-v8a", "x86_64")
        }

        chaquopy {
            defaultConfig {
                buildPython("D:\\anaconda3\\envs\\face_re\\python.exe")

                pip {
                    options("--extra-index-url", "http://pypi.mirrors.ustc.edu.cn/simple/")
                    options("--trusted-host", "pypi.mirrors.ustc.edu.cn")
                    install("opencv-python==4.5.1.48")
                    install("dlib==19.19.0")
                    install("opencv_contrib_python==4.5.1.48")
                    install("deepface==0.0.74")
                    install("tensorflow==2.1.0")
                    install("protobuf==3.20.0")
                    install("ffmpeg-python")
                }
            }

        }
相关推荐
哲科软件5 小时前
跨平台开发的抉择:Flutter vs 原生安卓(Kotlin)的优劣对比与选型建议
android·flutter·kotlin
烛阴6 小时前
简单入门Python装饰器
前端·python
好开心啊没烦恼6 小时前
Python 数据分析:numpy,说人话,说说数组维度。听故事学知识点怎么这么容易?
开发语言·人工智能·python·数据挖掘·数据分析·numpy
面朝大海,春不暖,花不开7 小时前
使用 Python 实现 ETL 流程:从文本文件提取到数据处理的全面指南
python·etl·原型模式
2301_805054568 小时前
Python训练营打卡Day59(2025.7.3)
开发语言·python
万千思绪8 小时前
【PyCharm 2025.1.2配置debug】
ide·python·pycharm
微风粼粼10 小时前
程序员在线接单
java·jvm·后端·python·eclipse·tomcat·dubbo
云天徽上10 小时前
【PaddleOCR】OCR表格识别数据集介绍,包含PubTabNet、好未来表格识别、WTW中文场景表格等数据,持续更新中......
python·ocr·文字识别·表格识别·paddleocr·pp-ocrv5
你怎么知道我是队长10 小时前
python-input内置函数
开发语言·python
叹一曲当时只道是寻常10 小时前
Python实现优雅的目录结构打印工具
python