从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能解决这个冲突;