android - 无法在我的 Android 项目中设置 Chaquopy,注释问题

标签 android kotlin android-jetpack-compose build.gradle chaquopy

The Error 所以基本上当我将我的项目与 gradle 和 chaquopy 同步时。我无法声明该函数

我期待 gradle 同步成功,并且能够尽快开始该项目的工作。

这是我的 build.gradle.kts (:app),基于 this gradle在 chaquopy 自己的 github 存储库中找到。

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

afterEvaluate {
    val assetsSrcDir = "src/main/assets/source"
    delete(assetsSrcDir)
    mkdir(assetsSrcDir)
    for (filename in listOf("python/chaquopy/mediaPipe/main.py",
        "java/com/example/createzero/MainActivity.kt")) {
        val srcFile = file("src/main/$filename")
        if (! srcFile.exists()) {
            throw GradleException("$srcFile does not exist")
        }
        copy {
            from(srcFile)
            into(assetsSrcDir)
        }
    }
}

android {
    namespace = "com.example.createzero"
    compileSdk = 34

    defaultConfig {
        applicationId = "com.example.createzero"
        minSdk = 24
        targetSdk = 34
        versionCode = 1
        versionName = "1.0"

//        val plugins = buildscript.configurations.getByName("classpath")
//            .resolvedConfiguration.resolvedArtifacts.map {
//                it.moduleVersion.id
//            }.filter {
//                it.group == "com.chaquo.python" && it.name == "gradle"
//            }
//        if (plugins.size != 1) {
//            throw GradleException("found ${plugins.size} Chaquopy plugins")
//        }
//        versionName = plugins[0].version
//
//        val verParsed = versionName!!.split(".").map { it.toInt() }
//        versionCode = verParsed[0] * 1000000 +
//                verParsed[1] * 1000 +
//                verParsed[2] * 10

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

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

        resourceConfigurations += "en"
    }

    buildTypes {
        create("releaseMinify") {
            initWith(getByName("release"))
            isMinifyEnabled = true
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }

    lint {
        disable += "ValidFragment"
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    buildFeatures {
        compose = true
    }
    composeOptions {
        kotlinCompilerExtensionVersion = "1.4.3"
    }
    packaging {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
}

chaquopy {
    defaultConfig {
        // Android UI demo
        pip {
            install("Pygments==2.2.0")  // Also used in Java API demo
        }
        staticProxy("chaquopy.demo.ui_demo")

        // Python unit tests
        pip {
            // We use an old version of murmurhash (built from the Chaquopy branch
            // `murmurhash-0`), because in newer versions, importing murmurhash
            // automatically imports and extracts murmurhash/mrmr.so, which would
            // complicate the tests.
            install("murmurhash==0.28.0")  // Requires chaquopy-libcxx

            // Because we set pyc.src to false, we must test extractPackages via pip.
            install("../../product/gradle-plugin/src/test/integration/data/" +
                    "ExtractPackages/change_1/app/extract_packages")
        }
        extractPackages("ep_bravo", "ep_charlie.one")
        staticProxy("chaquopy.test.static_proxy.basic",
            "chaquopy.test.static_proxy.header",
            "chaquopy.test.static_proxy.method")
        pyc {
            // For testing bytecode compilation on device, and also to include test
            // source code in stack traces.
            src = false

            // For testing bytecode compilation during build.
            pip = true
        }
    }
}


dependencies {
    implementation("androidx.core:core-ktx:1.12.0")
    implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
    implementation("androidx.activity:activity-compose:1.8.1")
    implementation(platform("androidx.compose:compose-bom:2023.03.00"))
    implementation("androidx.compose.ui:ui")
    implementation("androidx.compose.ui:ui-graphics")
    implementation("androidx.compose.ui:ui-tooling-preview")
    implementation("androidx.compose.material3:material3")
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
    androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00"))
    androidTestImplementation("androidx.compose.ui:ui-test-junit4")
    debugImplementation("androidx.compose.ui:ui-tooling")
    debugImplementation("androidx.compose.ui:ui-test-manifest")


    //splash
    implementation("androidx.core:core-splashscreen:1.1.0-alpha02")



}

这是 build.gradle.kts(项目)文件

plugins {
    id("com.android.application") version "8.1.4" apply false
    id("org.jetbrains.kotlin.android") version "1.8.10" apply false
    id("com.chaquo.python") version "14.0.2" apply false
}

最佳答案

chaquopy 语法需要 Chaquopy 15,该版本将在未来几天内发布。

同时,您可以按照说明使用预发布版本 here :

  • At the top level of your project, edit the settings.gradle or build.gradle file to add this line to the repositories block within pluginManagement or buildscript (NOT within allprojects or dependencyResolutionManagement):

    maven { url = uri("https://chaquo.com/maven-test") }
    
  • Edit the build.gradle file to change the Chaquopy version to 15.0.0.

有关更多详细信息,请参阅Chaquopy 15 documentation .

关于android - 无法在我的 Android 项目中设置 Chaquopy,注释问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77627352/

相关文章:

transactions - Jooq 交易 : connections are not released to pool, 如果在交易中抛出异常

android - 使用 Jetpack Compose 绘制线条动画

android - Jetpack Compose 文本显示混淆

android - 在 Jetpack Compose 不可组合函数中获取上下文

android - 隐藏游戏资源

java - 如何解决无法解析方法 'put( int , int)'错误

enums - 使用关联类型时密封类与枚举

android - ChromeCast SDK 专辑封面

android - 如何在 Cursor 更新时更新 Listview header View?

android - Jetpack Compose Text 超链接部分文本