從AS2.3升級到3.0後,3.0仍是不穩定,遇到一些bug:
總結帖以下:
android studio3.0 升級後的變化和坑
Android Studio3.0升級gradle遇到的坑java
遇到的新問題:react
Unable to resolve dependency for :app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0.;android
Unable to resolve dependency for :constraint-layout: Could not resolve constraint-layout:1.0.2;app
setting->System setting->android SDK->SDK Tools 最下面關於
constraint-layout的依賴都導入;
ide
implementation 'com.android.support:appcompat-v7:26.1.0'
改成gradle
implementation 'com.android.support:appcompat-v7:26.+' androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.1'
改成ui
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
1.2.3 runner修改this
androidTestImplementation 'com.android.support.test:runner:1.0.1'
改成google
androidTestImplementation 'com.android.support.test:runner:0.4'
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.+' implementation 'com.android.support.constraint:constraint-layout:1.0.2' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:0.4' androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2' }
Error:Jack is required to support java 8 language features. Either enable Jack or remove sourceCompatibility JavaVersion.VERSION_1_8
須要在spa
defaultConfig { applicationId "com.xxx" minSdkVersion 19 targetSdkVersion 24 versionCode 1 versionName "1.0" jackOptions { enabled true } }
須要添加
jackOptions {enabled true}
之前若是遇超過方法數超過65535的解決辦法通常是defaultConfig 中添加
multiDexEnabled true dependencies { compile 'com.android.support:multidex:1.0.0' }
Application 類重寫方法:
@Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); }
如今AS3.0好像沒有這個限制
com.android.support:multidex:1.0.0這個包也沒法依賴,
把依賴包、multiDexEnabled true、application中的東西所有刪除就能夠正常運行;
Android Studio 3.0 最近升級爲 3.0.1
新建項目報錯問題,google已經修復。按照系統默認的dependencies徹底能夠gradle,項目不會報錯。
不過gradle的version須要按照系統提示升級爲4.1;
classpath 升級爲'com.android.tools.build:gradle:3.0.1'
使用Rxjava依賴以下:
implementation('com.squareup.retrofit2:adapter-rxjava:2.1.0') { exclude group: 'io.reactivex' } implementation 'io.reactivex:rxandroid:1.2.1' implementation 'io.reactivex:rxjava:1.1.6'
並添加:packagingOptions { exclude 'META-INF/rxjava.properties'}解決OS衝突:
android { compileSdkVersion 26 defaultConfig { applicationId "com.xxx.xxxxx.xxxxx" minSdkVersion 18 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" packagingOptions { exclude 'META-INF/rxjava.properties' } }
這樣作再安裝apk的時候會報錯以下:
java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
只能手動在libs文件夾中添加:rxandroid的jar包,buildPath。最後的依賴以下:
implementation('com.squareup.retrofit2:adapter-rxjava:2.1.0') { exclude group: 'io.reactivex' } implementation 'io.reactivex:rxjava:1.1.6' implementation files('libs/rxandroid-0.24.0.jar')
才解決衝突正常使用rxjava/RxAndroid;但願Google能解決這個衝突;