运行一个新的Flutter项目,在IOS设备上没有问题可以正常的跑起来。运行在安卓设备上就出现了如下错误

* What went wrong:                                                      
Execution failed for task ':app:checkDebugDuplicateClasses'.            
> 1 exception was raised by workers:                                    
  java.lang.RuntimeException: Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules jetified-guava-20.0.jar (com.google.guava:guava:20.0) and jetified-listenablefuture-1.0.jar (com.google.guava:listenablefuture:1.0)
                                                                        
  Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.

解决办法如下:

1 找到Flutter项目中的android/gradle.properties文件

添加如下代码:

android.useAndroidX=true
android.enableJetifier=true

2 找到Flutter项目中的android/app/build.gradle文件

android{
//...
}


//添加这段代码
configurations {
    all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐