使用fat-aar(com.kezong.fat-aar) 配合flutter package项目生成nativie项目中间件aar
1,.android项目内跟目录的build.gradle 添加如下:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// classpath "com.mobbeel.plugin:fat-aar:2.0.3"//这个使用出现bug
classpath 'com.kezong:fat-aar:1.1.7'//fat arr打包arr中间件
}
2,.android项目内Flutter/build.gradle
加入 apply plugin: 'com.kezong.fat-aar'
dependencies 加入依赖插件 例如:
embed project(path: ':connectivity', configuration:'default')
embed project(path: ':flutter_statusbar', configuration:'default')
embed project(path: ':fluttertoast', configuration:'default')
embed project(path: ':path_provider', configuration:'default')
embed project(path: ':shared_preferences', configuration:'default')
embed project(path: ':url_launcher', configuration:'default')
3,执行命令 flutter build apk
打印部分信息如下:
【Fat-aar-INFO】[embed detected][aar]io.flutter.plugins.connectivity:connectivity:1.0-SNAPSHOT
【Fat-aar-INFO】[embed detected][aar]com.example.flutterstatusbar:flutter_statusbar:1.0-SNAPSHOT
【Fat-aar-INFO】[embed detected][aar]io.github.ponnamkarthik.toast.fluttertoast:fluttertoast:1.0-SNAPSHOT
【Fat-aar-INFO】[embed detected][aar]io.flutter.plugins.pathprovider:path_provider:1.0-SNAPSHOT
【Fat-aar-INFO】[embed detected][aar]io.flutter.plugins.sharedpreferences:shared_preferences:1.0-SNAPSHOT
【Fat-aar-INFO】[embed detected][aar]io.flutter.plugins.urllauncher:url_launcher:1.0-SNAPSHOT
【Fat-aar-INFO】Merge resource,Library res:/Users/conghl/flutter/.android/Flutter/build/intermediates/exploded-aar/com.example.flutterstatusbar/flutter_statusbar/1.0-SNAPSHOT/res
【Fat-aar-INFO】Merge resource,Library res:/Users/conghl/flutter/.android/Flutter/build/intermediates/exploded-aar/io.flutter.plugins.pathprovider/path_provider/1.0-SNAPSHOT/res
【Fat-aar-INFO】Merge resource,Library res:/Users/conghl/flutter/.android/Flutter/build/intermediates/exploded-aar/io.github.ponnamkarthik.toast.fluttertoast/fluttertoast/1.0-SNAPSHOT/res
【Fat-aar-INFO】Merge resource,Library res:/Users/conghl/flutter/.android/Flutter/build/intermediates/exploded-aar/io.flutter.plugins.urllauncher/url_launcher/1.0-SNAPSHOT/res
【Fat-aar-INFO】Merge resource,Library res:/Users/conghl/flutter/.android/Flutter/build/intermediates/exploded-aar/io.flutter.plugins.connectivity/connectivity/1.0-SNAPSHOT/res
【Fat-aar-INFO】Merge resource,Library res:/Users/conghl/flutter/.android/Flutter/build/intermediates/exploded-aar/io.flutter.plugins.sharedpreferences/shared_preferences/1.0-SNAPSHOT/res
【Fat-aar-INFO】Merge classes
【Fat-aar-INFO】[androidLibrary]flutter_statusbar
【Fat-aar-INFO】[androidLibrary]path_provider
【Fat-aar-INFO】[androidLibrary]fluttertoast
【Fat-aar-INFO】[androidLibrary]url_launcher
【Fat-aar-INFO】[androidLibrary]connectivity
【Fat-aar-INFO】[androidLibrary]shared_preferences
【Fat-aar-INFO】Merge jars
【Fat-aar-INFO】Not found jar file, Library:flutter_statusbar
【Fat-aar-INFO】Not found jar file, Library:path_provider
【Fat-aar-INFO】Not found jar file, Library:fluttertoast
【Fat-aar-INFO】Not found jar file, Library:url_launcher
【Fat-aar-INFO】Not found jar file, Library:connectivity
【Fat-aar-INFO】Not found jar file, Library:shared_preferences
【Fat-aar-INFO】Generate R File, Library:flutter_statusbar
【Fat-aar-INFO】Generate R File, Library:path_provider
【Fat-aar-INFO】Generate R File, Library:fluttertoast
【Fat-aar-INFO】Generate R File, Library:url_launcher
【Fat-aar-INFO】Generate R File, Library:connectivity
【Fat-aar-INFO】Generate R File, Library:shared_preferences
【Fat-aar-INFO】Compile R.class, Dir:/Users/conghl/flutter/.android/Flutter/build/intermediates/exploded-aar/r
【Fat-aar-INFO】Generate R.jar, Dir:/Users/conghl/flutter/.android/Flutter/build/intermediates/exploded-aar/r-class
【Fat-aar-INFO】reBundle final aar, from:/Users/conghl/flutter/.android/Flutter/build/outputs/aar-R/release
【Fat-aar-INFO】reBundle final aar, target:/Users/conghl/flutter/.android/Flutter/build/outputs/aar/flutter-release.aar
4,最后一行内的文件即为android中间件文件,拷贝到native项目libs文件内。
D8: Program type already present: ******
出现这个错误将.android/Flutter/build 文件删除重新编译即可
native项目修改
1,将aar文件拷贝到libs文件内
2,app/build.gradle
dependencies {
...
api(name: 'flutter-release', ext: 'aar')
...
...
}
3,project/build.gradle
allprojects {
repositories {
......
flatDir {
dirs 'libs' // aar目录
}
......
}
}
多渠道aar: flutter build apk --flavor XXX