一段時間沒玩Flutter,今天打開一個項目編譯了一下,忽然發現不能編譯了,出現android
Launching lib\main.dart on Nokia X6 in debug mode... FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:preDebugBuild'. > Android dependency 'androidx.appcompat:appcompat' has different version for the compile (1.0.0-beta01) and runtime (1.1.0-alpha02) classpath. You should manually set the same version via DependencyResolution * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 15s ******************************************************************************************* The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app. See https://goo.gl/CP92wY for more information on the problem and how to fix it. ******************************************************************************************* Gradle task assembleDebug failed with exit code 1 Exited (sigterm)
大概意思是說,安卓依賴在編譯時和運行時出現了不一樣的版本,由於有了AndroidX的出現。app
可能在你使用的依賴package的時候,你會注意到他們的更新日誌,其中會有Migrate to AndroidX。gradle
緣由:ui
因爲以前的Android.support包管理過於混亂,因此Google推出了AndroidX。若是各位開發者有時間的話,仍是要儘可能升級一下項目到AndroidX,畢竟這個是將來,谷歌的新標準。this
怎麼升級,錯誤信息已經給出了提示,進入 https://goo.gl/CP92wY spa
①使用Android Studio自動升級debug
確保Android Studio版本是最新版,或者至少3.2以上。日誌
打開你的項目,選中android文件夾,右鍵選擇,Flutter,Open Android Module in Android Studio。code
這個時候會打開一個新窗口,等它分析完成以後,選擇Refactor——Migrate to AndroidX。orm
檢測完成後,下方出現提示,提示須要升級的地方,確認後點擊「Do Refector」
升級完成後,關閉窗口便可。
這個時候你再編譯Flutter,就沒問題啦~~~~~~~~~~~~
②手動升級到AndroidX(不推薦)
谷歌提示不推薦這個方法,麻煩,並且搞很差容易出錯。
不過若是你沒有安裝Android Studio,你得采用這個手動升級的辦法。
a)打開android/gradle/wrapper/gradle-wrapper.properties,修改distributionUrl的值,
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
b)打開android/build.gradle,修改com.android.tools.build:gradle 到3.3.0
dependencies { classpath 'com.android.tools.build:gradle:3.3.0' }
c)打開android/gradle.properties,添加兩行
android.enableJetifier=true android.useAndroidX=true
d)打開android/app/build.gradle,在android{裏面,確保compileSdkVersion
和 targetSdkVersion
值爲28。
替換全部過期的依賴庫android.support到androidx。
例如替換,須要一一查找。
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
爲新的
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
在dependencies{裏面,替換
androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
爲新的
androidTestImplementation 'androidx.test.runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'