在 android studio 中使用 chaquopy 时如何解决 Python.getInstance() 错误

How can I solve Python.getInstance() error when I use chaquopy in android studio

我正在尝试在 android studio 中使用 chaquopy 来识别视频中的音频并将其转换为文本,但是当我调用 Python.getInstance() 时,它会用红色覆盖它。可能是什么问题?

build.gradle(应用程序)

plugins {
    id 'com.google.gms.google-services'

    //for chaquopy(python)
    id 'com.android.application'
    id 'com.chaquo.python'
}


android {
    compileSdk 31

    defaultConfig {
        applicationId "com.talhakara.uzaktanegitimbitirmeprojesi"
        minSdk 16
        targetSdk 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
       // for chaquopy(python)
        ndk {
            abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
        }
        python {
            buildPython "C:/Users/enest/AppData/Local/Programs/Python/Python39/python.exe"

        }

        sourceSets {
            main {
                python.srcDir "src/main/python"
            }
        }
        //
    }

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





dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
    implementation 'androidx.annotation:annotation:1.2.0'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
    implementation 'com.google.android.gms:play-services-tasks:17.2.1'
    implementation 'androidx.navigation:navigation-fragment:2.3.5'
    implementation 'androidx.navigation:navigation-ui:2.3.5'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    implementation platform('com.google.firebase:firebase-bom:29.0.0')
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-firestore'
    implementation 'com.google.firebase:firebase-storage'

    implementation 'com.google.firebase:firebase-core:20.1.0'
    implementation 'com.google.firebase:firebase-messaging:23.0.0'
    implementation 'com.google.firebase:firebase-appindexing:20.0.0'
    implementation 'com.google.firebase:firebase-invites:17.0.0'
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.google.firebase:firebase-firestore:24.0.1'
    implementation 'com.firebaseui:firebase-ui-auth:4.0.0'


    implementation 'com.google.firebase:firebase-analytics:17.2.1'
    implementation 'com.google.firebase:firebase-database:19.2.0'


    implementation ('org.jitsi.react:jitsi-meet-sdk:2.9.0') { transitive = true }


    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "androidx.drawerlayout:drawerlayout:1.1.1"

   // implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.0'
}

build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
        //chaquopy
        maven { url "https://chaquo.com/maven" }

    }
    dependencies {

        classpath 'com.android.tools.build:gradle:7.0.4'
        classpath 'com.google.gms:google-services:4.3.10'
        //chaquopy
        classpath "com.chaquo.python:gradle:10.0.1"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}


task clean(type: Delete) {
    delete rootProject.buildDir
}

我的activity

  @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        binding = ActivityVideoConferenceBinding.inflate(getLayoutInflater());
        View view = binding.getRoot();
        setContentView(view);

        //start python
        if (! Python.isStarted()) {
            Python.start(new AndroidPlatform(VideoConference.this));
        }

        Python py = new Python.getInstance(); // this line is red and 
                                              //it doesn't show any errors
                                             
        binding.btnChooseVideo.setOnClickListener(view1 -> {

            callChooseFromVideo();

        });



    }

错误信息

error: cannot find symbol
    Python py = new Python.getInstance();
    symbol:   class getInstance
  location: class Python
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDebugJavaWithJavac
Caused by: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details

会不会是gradle版本的问题?因为我的 gradle 版本 7.0.4 在 chaquopy 的文档中显示 7.0 是最新的。它会导致这个问题吗?我使用 10.0.1 作为 chaquopy 版本,因为 android studio 推荐它作为最新版本。如果这些有问题,我应该使用哪个版本?

正确的语法只是 Python.getInstance(),而不是 new Python.getInstance()