使用fat-aar(com.kezong.fat-aar) 配合flutter package項(xiàng)目生成nativie項(xiàng)目中間件aar
1锉桑,.android項(xiàng)目內(nèi)跟目錄的build.gradle 添加如下:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// classpath "com.mobbeel.plugin:fat-aar:2.0.3"http://這個使用出現(xiàn)bug
classpath 'com.kezong:fat-aar:1.1.7'//fat arr打包arr中間件
}
2,.android項(xiàng)目內(nèi)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,執(zhí)行命令 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辙售,最后一行內(nèi)的文件即為android中間件文件轻抱,拷貝到native項(xiàng)目libs文件內(nèi)。
D8: Program type already present: ******
出現(xiàn)這個錯誤將.android/Flutter/build 文件刪除重新編譯即可
native項(xiàng)目修改
1旦部,將aar文件拷貝到libs文件內(nèi)
2祈搜,app/build.gradle
dependencies {
...
api(name: 'flutter-release', ext: 'aar')
...
...
}
3,project/build.gradle
allprojects {
repositories {
......
flatDir {
dirs 'libs' // aar目錄
}
......
}
}
使用另一個aar(fataar-gradle-plugin)問題,編譯重視失敗最后嘗試也沒成功士八,浪費(fèi)很長時間 放棄了容燕。
https://github.com/flutter/flutter/issues/18025
https://github.com/flutter/flutter/issues/23944
多渠道aar: flutter build apk --flavor XXX