先放参考感谢前人种树:
https://juejin.im/post/5d312549f265da1b6f43aebf
https://www.jianshu.com/p/5ef065abfe07
http://www.bubuko.com/infodetail-3079263.html
今天使用image_picker插件的时候build报错了,其实之前写Flutter Application的时候没碰到多少问题,这回写Flutter Module集成到Native项目的时候问题还是比较多的。要考虑解决集成问题,混合路由栈管理,合作开发等问题。当然还有些问题在路上,就比如Android历史的android.support.xxx包和androidX兼容性问题,涉及到Flutter项目迁移到AndroidX
报错如下,原因是在使用androidx库时, 又不小心间接使用了其他的老库
在Flutter Module项目.android目录下的gradle.properties增加,build试试
android.useAndroidX=true android.enableJetifier=true
报错,编译和运行版本不一样
修改Flutter Module目录.android/app/build.gradle在dependencies属性里加,我这里不仅androidx.versionedparcelable不一样,都加上都加上
project.configurations.all { resolutionStrategy.eachDependency { details -> if (details.requested.group == 'com.android.support' && !details.requested.name.contains('multidex') ) { details.useVersion "27.1.1" }else if(details.requested.group == "androidx.versionedparcelable") { details.useVersion "1.0.0-rc01" }else if(details.requested.group == "androidx.lifecycle") { details.useVersion "2.0.0-rc01" }else if(details.requested.group == "androidx.core") { details.useVersion "1.0.0-rc01" } } }
报错
因为用androidx关系旧包的东西已经找不到了,换这里有个映射表https://blog.csdn.net/Comestudy123/article/details/84785440
.androidFluttersrcmainjavaioflutterfacadeFlutterFragment.java
//import android.support.annotation.NonNull; //import android.support.v4.app.Fragment; import androidx.annotation.NonNull; import androidx.fragment.app.*;
.androidFluttersrcmainjavaioflutterfacadeFlutter.java
//import android.arch.lifecycle.Lifecycle; //import android.arch.lifecycle.LifecycleObserver; //import android.arch.lifecycle.OnLifecycleEvent; //import android.support.annotation.NonNull; import androidx.lifecycle.*; import androidx.annotation.NonNull;
build走起,但是仍旧有老问题.android目录会随时删除,又需要把修改的配置文件和代码放到根目录copy后build,这块后面解决下,应该可以用Flutter Application工程做集成,后面试试