flutter aar 上传 Maven
通过脚本支持了 Jenkins 上自动打包 Flutter,上传 Maven,修改版本号,一键自动化打包。
上传 Maven
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
   | diff --git a/packages/flutter_tools/gradle/aar_init_script.gradle b/packages/flutter_tools/gradle/aar_init_script.gradle index cc2bbe6f98..242ac61fb0 100644 --- a/packages/flutter_tools/gradle/aar_init_script.gradle +++ b/packages/flutter_tools/gradle/aar_init_script.gradle @@ -37,7 +37,10 @@ void configureProject(Project project, String outputDir) {      project.uploadArchives {          repositories {              mavenDeployer { -                repository(url: "file://${outputDir}/outputs/repo") +                 +                repository(url: "http://10.2.0.210:8081/repository/maven-releases/") { +                    authentication(userName: "a", password: "b") +                }              }          }      }
 
  | 
 
https://stackoverflow.com/questions/62284466/how-to-build-and-maven-publish-a-flutter-aar
自定义环境修改源码
要不然编译不过Flutter 238行
1 2 3 4 5 6 7 8 9 10 11 12 13 14
   | project. android. buildTypes {
  profile { initWith debug if (it.hasProperty ("matchingFallbacks")) { matchingFallbacks \= \["debug", "release"\] } } envTest { initWith debug } pre { initWith debug }
 
  | 
 
jinkens上传脚本
在根 build. gradle
1 2 3
   | apply from: 'buildscript/update_module_properties.gradle'      buildscript {}
 
  | 
 
update_module_properties. gradle
获取 jinken 构建号当做 Flutter 版本号,然后 build aar,上面的 aar_init_script 会上传到 Maven,Flutter 上传完后 cd 到项目的目录下,修改对应的依赖的 Flutter 版本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
   | task update_module_version {     doLast {         println '执行  update_module_version task'         def BUILD_NUMBER = System.getenv('BUILD_NUMBER')
          def array1 = BUILD_NUMBER.toCharArray()         StringBuilder flutterVersion = new StringBuilder()         for (int i = 0; i < array1.length; i++) {             if (i != array1.length - 1) {                 flutterVersion.append(array1[i].toString() + '.')             } else {                 flutterVersion.append(array1[i])             }         }         println 'flutterVersion :' + flutterVersion.toString()
          exec {             workingDir             commandLine 'sh', '-c', "echo flutter uploading..."             commandLine 'sh', '-c', 'flutter pub get'             commandLine 'sh', '-c', "flutter build aar --build-number ${flutterVersion.toString()}  --no-debug --no-profile"         }
 
 
          def branch = System.getenv('PROPERTIES_BRANCH')
          def moduleName = System.getenv("moduleName")         if (moduleName == null) {             moduleName = System.getenv("JOB_BASE_NAME")         }         def aarVersion = System.getenv("BUILD_VERSION")         if (System.getenv('isUserBuildVersion') == false || System.getenv('isUserBuildVersion') == 'false') {             aarVersion = System.getProperty("buildVersion")         }         def dirpath = rootDir.parentFile.path + '/bookproperties/'         def workingDir = new File(dirpath)         def local_branch = branch         def origin_branch = "origin/" + branch         println "pwd".execute(null, workingDir).text         def command = "git branch"         def proc = command.execute()         proc.waitFor()         if (proc.exitValue() == 0) {             def branches=  proc.in.text             println "当前所在分支:$branches"         }         println "git checkout -b $local_branch $origin_branch".execute(null, workingDir).errorStream.text         println "git checkout  $local_branch ".execute(null, workingDir).errorStream.text         println "git pull".execute(null, workingDir).errorStream.text         println " end pull ----------------"
          def filepath = rootDir.parentFile.path + '/bookproperties/bookproperties/modules.gradle'         def file = new File(filepath)         def text = file.getText()
          int currentmodle = -1
          def originalText = ""         StringBuilder newText = new StringBuilder()         text.eachLine {             if (it.contains('business_configure') || it.contains('business_base_configure') || it.contains('xeslibraries_configure') || it.contains('thirdlibraries_configure')) {                 currentmodle++             }                          if (it.contains('flutteraar')) {                 originalText = it                 String[] splits = it.split(":")                 if (splits.length >= 2) {                     for (final def content in splits) {                         if (content.contains("@")) {                             String[] splits1 = content.split("@")                             splits1[0] = flutterVersion.toString()                             newText.append(splits1[0] + "@")                             newText.append(splits1[1])                         } else {                             newText.append(content + ":")                         }                     }                 }                 println "需要替换的aar的包名为:" + it             }         }         if (text.contains(originalText)) {               text = text.replaceAll(originalText, newText.toString())         }         StringBuffer buffer = new StringBuffer()         buffer.append(text)         println("新的moudles---" + buffer.toString())         file.write(buffer.toString())
          def subVcode = System.getenv('BUILD_TAG')         println "git add . ".execute(null, workingDir).errorStream.text         println "git commit -m 'updateversion--${subVcode}' ".execute(null, workingDir).errorStream.text         println "git push ".execute(null, workingDir).errorStream.text     }
  }
 
  | 
 
原生的依赖
1 2 3 4
   | flutteraar:'com.bundle:flutter_release:3.5@aar', flutterv7:'io.flutter:armeabi_v7a_release:1.0.0-e85ea0e79c6d894c120cda4ee8ee10fe6745e187',   flutterembedding:'io.flutter:flutter_embedding_release:1.0.0-e85ea0e79c6d894c120cda4ee8ee10fe6745e187',   flutterv8:'io.flutter:arm64_v8a_release:1.0.0-e85ea0e79c6d894c120cda4ee8ee10fe6745e187',
 
  | 
 
- flutteraar: 这是 Flutter 的 AAR(Android Archive)库文件,用于在 Android 项目中引入 Flutter 框架。它包含了 Flutter 运行时和相应的依赖项,允许在 Flutter 和 Android 之间进行交互和集成。
 
- flutterv7: 这是 Flutter 的 armeabi-v7a 架构下的发布版本库。Flutter 支持多种 CPU 架构,armeabi-v7a 是面向 ARM 架构的 32 位设备,这个库提供了在 armeabi-v7a 架构设备上运行 Flutter 应用所需的二进制文件。
 
- flutterembedding: 这是 Flutter 的嵌入式库,用于在原生 Android 或 iOS 项目中嵌入 Flutter 模块。它提供了与 Flutter 交互的接口和工具,允许在原生应用程序中使用 Flutter 模块来实现跨平台功能。