如何解决颤振中的“ simple_permissions”错误?

时间:2019-05-10 09:42:38

标签: android-studio plugins flutter androidx

在flutter项目上运行包含simple_permissions的代码时出现错误。

Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...
C:\Users\ria\Downloads\flutter_windows_v1.2.1-stable\flutter\.pub-cache\hosted\pub.dartlang.org\simple_permissions-0.1.9\android\src\main\java\com\ethras\simplepermissions\SimplePermissionsPlugin.java:9: error: cannot find symbol
import android.support.v4.app.ActivityCompat;
                             ^
  symbol:   class ActivityCompat
  location: package android.support.v4.app
C:\Users\ria\Downloads\flutter_windows_v1.2.1-stable\flutter\.pub-cache\hosted\pub.dartlang.org\simple_permissions-0.1.9\android\src\main\java\com\ethras\simplepermissions\SimplePermissionsPlugin.java:10: error: package android.support.v4.content does not exist
import android.support.v4.content.ContextCompat;
                                 ^
C:\Users\ria\Downloads\flutter_windows_v1.2.1-stable\flutter\.pub-cache\hosted\pub.dartlang.org\simple_permissions-0.1.9\android\src\main\java\com\ethras\simplepermissions\SimplePermissionsPlugin.java:156: error: cannot find symbol
        ActivityCompat.requestPermissions(activity, perm, 0);
        ^
  symbol:   variable ActivityCompat
  location: class SimplePermissionsPlugin
C:\Users\ria\Downloads\flutter_windows_v1.2.1-stable\flutter\.pub-cache\hosted\pub.dartlang.org\simple_permissions-0.1.9\android\src\main\java\com\ethras\simplepermissions\SimplePermissionsPlugin.java:163: error: cannot find symbol
        return PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(activity, permission);
                                                    ^
  symbol:   variable ContextCompat
  location: class SimplePermissionsPlugin
C:\Users\ria\Downloads\flutter_windows_v1.2.1-stable\flutter\.pub-cache\hosted\pub.dartlang.org\simple_permissions-0.1.9\android\src\main\java\com\ethras\simplepermissions\SimplePermissionsPlugin.java:171: error: cannot find symbol
            if (ActivityCompat.shouldShowRequestPermissionRationale(registrar.activity(), permission)) {
                ^
  symbol:   variable ActivityCompat
  location: class SimplePermissionsPlugin
C:\Users\ria\Downloads\flutter_windows_v1.2.1-stable\flutter\.pub-cache\hosted\pub.dartlang.org\simple_permissions-0.1.9\android\src\main\java\com\ethras\simplepermissions\SimplePermissionsPlugin.java:175: error: cannot find symbol
                if (ActivityCompat.checkSelfPermission(registrar.context(), permission) == PackageManager.PERMISSION_GRANTED) {
                    ^
  symbol:   variable ActivityCompat
  location: class SimplePermissionsPlugin
6 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':simple_permissions:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for 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 2s
Finished with error: Gradle task assembleDebug failed with exit code 1
*******************************************************************************************
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.

*******************************************************************************************

2 个答案:

答案 0 :(得分:3)

我遇到了同样的问题,经过一些搜索我找到了这个存储库。

https://github.com/tq-systems/simple_permissions

此存储库解决了 AndroidX 兼容性问题。 像这样将它导入到 pubspec.yaml 中:

dependencies:
  simple_permissions:
    git:
      url: https://github.com/tq-systems/simple_permissions.git

答案 1 :(得分:0)

我遇到了同样的问题。我通过这些步骤解决了

步骤1 => 将您的android studio更新为最新版本 download here

第2步 卸载android studio并使用新的设置

安装新的

第3步 添加 Flutter插件

第4步 将此添加到 build.gradle

 dependencies {
    classpath 'com.android.tools.build:gradle:3.4.0'
    classpath 'com.google.gms:google-services:4.2.0'
    classpath ('com.google.firebase:firebase-plugins:1.1.0') {
        exclude group: 'com.google.guava', module: 'guava-jdk5'
    }
}

第5步 运行此命令

  

flutter软件包获得

更新您的包裹和档次

对我来说很好。