颤动不安全的未经检查的操作并过度使用已弃用的 api 错误

Posted

技术标签:

【中文标题】颤动不安全的未经检查的操作并过度使用已弃用的 api 错误【英文标题】:flutter unsafe unchecked operation and overtiding a deprecated api errors 【发布时间】:2020-06-19 07:37:17 【问题描述】:

我收到以下错误:

Note: /Users/D/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.13.4/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /Users/D/flutter/.pub-cache/hosted/pub.dartlang.org/share-0.6.3+6/android/src/main/java/io/flutter/plugins/share/SharePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/D/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.5/android/src/main/java/io/flutter/plugins/pathprovider/PathProviderPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/D/flutter/.pub-cache/hosted/pub.dartlang.org/square_in_app_payments-1.3.0/android/src/main/java/sqip/flutter/internal/CardEntryModule.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

解决此问题的步骤:

将依赖项更新为以下内容:

cupertino_icons: ^0.1.3
  firebase_core: ^0.4.4+2
  firebase_auth: ^0.15.5+2
  google_sign_in: ^4.1.4
  image_picker: ^0.6.3+4
  cloud_firestore: ^0.13.4
  percent_indicator: ^2.1.1+1
  uuid: ^2.0.4
  share: ^0.6.3+6
  path_provider: ^1.6.5
  barcode_scan: ^2.0.1
  intl: ^0.16.1
  square_in_app_payments: ^1.3.0
  http: ^0.12.0+4
  firebase_storage: ^3.1.3
  firebase_crashlytics: ^0.1.3
  firebase_dynamic_links: ^0.5.0+11

已将 gradle 文件更新为:

dependencies 
    classpath 'com.android.tools.build:gradle:3.5.3'
    classpath 'com.google.gms:google-services:4.3.3'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'io.fabric.tools:gradle:1.31.0'

还将成绩包装器更改为 gradle-6.0.1-all.zip。

但没有运气。我花了一整天的时间来解决这个问题,但已经没有选择了。有人可以帮忙吗?

我的应用程序/Gradle 文件:

    def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) 
    localPropertiesFile.withReader('UTF-8')  reader ->
        localProperties.load(reader)
    


def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) 
//    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
    throw new FileNotFoundException ("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")


def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) 
    flutterVersionCode = '1'


def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) 
    flutterVersionName = '1.0.0'



apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) 
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))


android 
    compileSdkVersion 29
    lintOptions 
        disable 'InvalidPackage'
    

    defaultConfig 
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "my application package name"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode  18 //flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    

    signingConfigs 
        release 
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        
    
    buildTypes 
        release 
            signingConfig signingConfigs.release
            multiDexKeepFile file('multidex-config.txt')
            minifyEnabled true //  - true done
            useProguard false //  - true done

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'


        
    


flutter 
    source '../..'


dependencies 
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"



apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'

【问题讨论】:

【参考方案1】:

在您的project/android/app/build.gradle 文件中将multiDexEnabled 设置为true

defaultConfig 
      ......
       multiDexEnabled true
   

【讨论】:

已启用。我已将 app/gradle 内容添加到我的问题中。

以上是关于颤动不安全的未经检查的操作并过度使用已弃用的 api 错误的主要内容,如果未能解决你的问题,请参考以下文章

如何为已弃用的英特尔 IPP API 找到替代 API?

Magnolia 的 AccessDefinition 类中已弃用的角色

我应该如何在 Android 中使用/不使用已弃用的方法

如何隐藏zend framework2已弃用的消息

如何在不使用已弃用的类的情况下编写 Hadoop map reduce 作业?

Android getAllNetworkInfo() 已弃用。啥是替代方案?