简体   繁体   中英

I can't build a Flutter apk because access 'FlutterEngine' class

For a couple of weeks, I can't build an apk from my project because of incompatibilities of some libraries version and Flutter. So I updated everything, but there are some errors.

This time, the error is that:

  • flutter build apk
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done                      28,3s
The build failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetifier to solve the incompatibility.
Building plugin clipboard_manager...
Running Gradle task 'assembleAarRelease'...
Running Gradle task 'assembleAarRelease'... Done                    4,1s
√ Built build\app\outputs\repo.
Building plugin connectivity...
Running Gradle task 'assembleAarRelease'...
Running Gradle task 'assembleAarRelease'... Done                    3,3s
√ Built build\app\outputs\repo.
Building plugin package_info...
Running Gradle task 'assembleAarRelease'...
Running Gradle task 'assembleAarRelease'... Done                    3,6s
√ Built build\app\outputs\repo.
Building plugin shared_preferences...
Running Gradle task 'assembleAarRelease'...
Running Gradle task 'assembleAarRelease'... Done                    4,8s
√ Built build\app\outputs\repo.
e: C:\Trabalho\Projetos\MyProject\android\app\src\main\kotlin\com\example\MyProject\MainActivity.kt: (3, 28): Unresolved reference: NonNull
e: C:\Trabalho\Projetos\MyProject\android\app\src\main\kotlin\com\example\MyProject\MainActivity.kt: (4, 19): Unresolved reference: embedding
e: C:\Trabalho\Projetos\MyProject\android\app\src\main\kotlin\com\example\MyProject\MainActivity.kt: (5, 19): Unresolved reference: embedding
e: C:\Trabalho\Projetos\MyProject\android\app\src\main\kotlin\com\example\MyProject\MainActivity.kt: (8, 21): Unresolved reference: FlutterActivity
e: C:\Trabalho\Projetos\MyProject\android\app\src\main\kotlin\com\example\MyProject\MainActivity.kt: (9, 5): 'configureFlutterEngine' overrides nothing
e: C:\Trabalho\Projetos\MyProject\android\app\src\main\kotlin\com\example\MyProject\MainActivity.kt: (9, 42): Unresolved reference: NonNull
e: C:\Trabalho\Projetos\MyProject\android\app\src\main\kotlin\com\example\MyProject\MainActivity.kt: (9, 65): Unresolved reference: FlutterEngine
e: C:\Trabalho\Projetos\MyProject\android\app\src\main\kotlin\com\example\MyProject\MainActivity.kt: (10, 35): Cannot access class 'FlutterEngine'. Check your module classpath for missing or conflicting dependencies

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileReleaseKotlin'.
> Compilation error. See log for more details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 17s
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done                      18,5s
Gradle task assembleRelease failed with exit code 1

The error above mention the Kotlin file MainActivity.kt , so that is a copy of my file:

package com.targetsistemas.target_mlog2

import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity: FlutterActivity() {
    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine);
    }
}

  • flutter doctor -v
[√] Flutter (Channel dev, 2.1.0-12.1.pre, on Microsoft Windows [versão 10.0.19042.867], locale pt-BR)
    • Flutter version 2.1.0-12.1.pre at C:\Flutter
    • Framework revision 8264cb3e8a (3 weeks ago), 2021-03-10 12:37:57 -0800
    • Engine revision 711ab3fda0
    • Dart version 2.13.0 (build 2.13.0-116.0.dev)

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at C:\Users\israel.gomes\AppData\Local\Android\Sdk
    • Platform android-30, build-tools 30.0.2
    • ANDROID_HOME = C:\Users\israel.gomes\AppData\Local\Android\Sdk
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 4.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] IntelliJ IDEA Community Edition (version 2020.3)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.3
    • Flutter plugin version 55.0.4
    • Dart plugin version 203.7759

[√] VS Code (version 1.55.0)
    • VS Code at C:\Users\israel.gomes\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.20.0

[√] Connected device (3 available)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 7.1.1 (API 25) (emulator)
    • Chrome (web)                       • chrome        • web-javascript • Google Chrome 89.0.4389.114
    • Edge (web)                         • edge          • web-javascript • Microsoft Edge 87.0.664.75

• No issues found!

Try the following.

  1. delete the entire.gradle folder and install android dependency via android studio sync options
  2. restarted android studio (invalidate cache as well).
  3. in android studio menu > Build > clean project, then Build > Rebuild project

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM