创建示例flutter插件以导入AndroidX并获取错误,无法解析符号“ XXX”

时间:2019-06-12 03:44:23

标签: flutter

我创建了一个示例flutter插件,并按照AndroidX兼容性文档将插件升级到AndroidX
1.在Android Studio中编辑Android代码
2.使用IDE迁移到AndroidX
3. classpath仍为“ com.android.tools.build:gradle:3.2.0”,手动更改为3.3.0
4. gradle.properties具有

android.enableJetifier=true
android.useAndroidX=true 

IDE附加的
5.

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 

已由IDE更改
6.

androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' 

已由IDE更改
7.之后,我添加了从图像选择器插件复制的Java类“ ImagePickerFileProvider”,但仍然出现错误“无法解析符号'FileProvider'”

package xxx.flutter_plugin_androidx_test;

import androidx.core.content.FileProvider;

/**
 * Providing a custom {@code FileProvider} prevents manifest {@code <provider>} name collisions.
 *
 * <p>See https://developer.android.com/guide/topics/manifest/provider-element.html for details.
 */
public class ImagePickerFileProvider extends FileProvider {}

1 个答案:

答案 0 :(得分:0)

  1. 我创建一个Android项目并比较build.gradle(模块:app),并将以下行添加到依赖项中

        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'androidx.appcompat:appcompat:1.0.0'
        implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
        implementation 'com.google.android.material:material:1.0.0'
    

    摘要

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'androidx.appcompat:appcompat:1.0.0'
        implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
        implementation 'com.google.android.material:material:1.0.0'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'androidx.test:runner:1.1.0'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
    }
    
  2. 将带有flutter插件并附加

    的build.gradle(Module:your_project_name)进行了比较
    dependencies {
        api 'androidx.legacy:legacy-support-v4:1.0.0'
    }
    

    摘要

    android {
        compileSdkVersion 28
    
        defaultConfig {
          minSdkVersion 21
          testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
        lintOptions {
          disable 'InvalidPackage'
        }
      }
    
    dependencies {
        api 'androidx.legacy:legacy-support-v4:1.0.0'
    }
    
  3. 重建项目并重新打开项目