无法解析符号'TextRecognizer'



从这里开始执行简单的步骤:https://developers.google.com/ml-kit/vision/text-recognition/android#java

我甚至不能编译这个应用程序。

所以在你开始之前我做了"部分:

我签入我的代码(build。gradle文件,上面写着"Project:"):

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

在我的代码构建中。gradle文件,那个写着"Module":

的文件
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.google.android.gms:play-services-mlkit-text-recognition:17.0.0' }

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.textrectest">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.TextRecTest">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.mlkit.vision.DEPENDENCIES"
android:value="ocr" />
</application>
</manifest>

然后,我继续下一节。

In my project:

package com.example.textrectest;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {

private Button btnMain;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnMain = (Button) findViewById(R.id.btnMain);
btnMain.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "hola", Toast.LENGTH_LONG).show();
}
});

TextRecognizer recognizer = TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS);
}
}

但是,Android Studio说(代码编辑器本身告诉我他不喜欢我所做的),高亮显示了" texttrecognizer& quot;(带红色):

找不到符号TextRecognizer

我做错了什么?我猜这是一个完全愚蠢的东西,但我不知道它是什么。

Thanks much in advance

正如@Noah所评论的,"无效缓存/重启"&;选项为我做了这件事,现在我能够导入代码运行所需的模块(我想我以前可以手动导入它们,但我不知道我需要什么模块,而且IntelliJ的东西没有推荐给我,因为缓存,我猜)。

最新更新