<address id="r9vd9"><address id="r9vd9"><listing id="r9vd9"></listing></address></address>

      歡迎您光臨深圳塔燈網絡科技有限公司!
      電話圖標 余先生:13699882642

      網站百科

      為您解碼網站建設的點點滴滴

      flutter 結構改動

      發表日期:2018-12 文章編輯:小燈 瀏覽次數:2403

      為什么要改結構?

      比如我寫了一個阿里支付的 plugin ,其默認結構應該是這樣的

      xxxLib --android //android 的代碼 --ios //ios 的代碼,這個里面我沒有實現 --lib //flutter 的代碼 

      flutter 的工程想使用當然沒問題,

      那要是android 工程想引用呢?僅當做android 工程的一個lib?

      因為這個lib 依賴 flutter.jar 所以要加入,要不然無法單獨編譯

      apply plugin: 'com.android.library' def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } def flutterRoot = localProperties.getProperty('flutter.sdk') if(flutterRoot!=null) { project.dependencies { if (project.getConfigurations().findByName("compileOnly")) { compileOnly project.files("$flutterRoot/bin/cache/artifacts/engine/android-arm/flutter.jar") } else { compile project.files("$flutterRoot/bin/cache/artifacts/engine/android-arm/flutter.jar") } } } 

      并且要在 local.properties 加入

      flutter.sdk=/Users/mac/Library/flutter flutter.versionName= xxx flutter.versionCode= xxx flutter.buildMode=debug 

      那么要傳到遠程倉庫上怎么辦呢?遠程倉庫沒flutter 環境怎么編譯出產物

      1.把jar包放進去
      2.把flutter的相關代碼去了

      于是成了下面這樣

      if (rootProject.getExtensions().findByName(getName())==null){ ext.set("moduleType",Type.isModule.name()) }else{ ext.set("moduleType",rootProject.getExtensions().getByName(getName())) } enum Type{ isAPP, //app運行 isModule, //android lib 庫 isFlutterPlugin; //flutterplugins } if (moduleType == Type.isAPP.name()){ apply plugin: 'com.android.application' }else { apply plugin: 'com.android.library' if (moduleType == Type.isFlutterPlugin.name()) { def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } def flutterRoot = localProperties.getProperty('flutter.sdk') if(flutterRoot!=null) { project.dependencies { if (project.getConfigurations().findByName("compileOnly")) { compileOnly project.files("$flutterRoot/bin/cache/artifacts/engine/android-arm/flutter.jar") } else { compile project.files("$flutterRoot/bin/cache/artifacts/engine/android-arm/flutter.jar") } } } } }sourceSets { main { if(moduleType == Type.isAPP.name()){ manifest.srcFile 'src/module/AndroidManifest.xml' //特別注意這里manifest 的大小寫 不是 Manifest java.srcDirs = [ 'src/main/java', 'src/module/java' ] res.srcDirs = [ 'src/main/res', 'src/module/res' ] }else if(moduleType == Type.isFlutterPlugin.name()){ java.srcDirs = [ 'src/main/java', 'src/flutter/java' ] } } } 

      然后在 工程下的build.gradle中可以用不同的方式

      //這里可以改為不同的編譯方式 rootProject.extensions.add("ali_pay",Type.isFlutterPlugin.name())enum Type{ isAPP, //app運行 isModule, //android lib 庫 isFlutterPlugin; //flutterplugins } 

      目錄結構如下


      QQ20181201-124355@2x.png

      flutter 工程引用要做些什么改動?

      0.pubspec.yaml 里加 plugins 照舊 比如

      ali_pay: path: ../../github/ali_pay/ali_pay/src/flutter 

      1.flutter 工程里的android里的 build.gradle 加入

       //這里可以改為不同的編譯方式 rootProject.extensions.add("ali_pay",Type.isFlutterPlugin.name()) enum Type{ isAPP, //app運行 isModule, //android lib 庫 isFlutterPlugin; //flutterplugins } 

      2.flutter 工程里的android里的 settings.gradle 改為

      def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()def plugins = new Properties() def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') if (pluginsFile.exists()) { pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } }plugins.each { name, path -> def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() if(!pluginDirectory.exists()){ pluginDirectory = flutterProjectRoot.resolve(path).getParent().getParent().toFile() } if(pluginDirectory.exists()){ include ":$name" project(":$name").projectDir = pluginDirectory } } 

      這樣結構就被改動了,如果要用ios 的話不要這么改

      ali_pay 的鏈接


      本頁內容由塔燈網絡科技有限公司通過網絡收集編輯所得,所有資料僅供用戶學習參考,本站不擁有所有權,如您認為本網頁中由涉嫌抄襲的內容,請及時與我們聯系,并提供相關證據,工作人員會在5工作日內聯系您,一經查實,本站立刻刪除侵權內容。本文鏈接:http://www.webpost.com.cn/17662.html
      相關APP開發
        SQL執行錯誤,請檢查国产成人精品综合在线观看