Android Studio從2升級到3 程式碼遷移需要的操作
特麼的執行著 然後發現死丟丟跑不起來了,是建立helloworld都出錯的那種,果斷換成新版本來弄一下。程式碼import是一片紅,哈哈
module目錄下的build.gradle
1.刪除buildToolsVersion。Android Studio3.0之後不需要再指定buildToolsVersion,每個版本的Android Gradle外掛都有預設版本的構建工具,不刪除只會報警告,但是這句指定構建版本的語句會被忽略
2.dependencies中 compile 替換為 implementation ,testCompile 替換為 testImplementation ,androidTestCompile 替換為 androidTestImplementation專案根目錄下的build.gradle
1.buildscript和allprojects的repositories中新增google()
2.dependencies中的classpath中將gradle版本修改為對應版本專案根目錄下的gradle/wrapper資料夾下的gradle-wrapper.properties檔案
修改 distributionUrl 的地址
總算感覺好了,發現還是報錯,因為使用了ButterKnife 8.8.1
Error:Unable to find method 'com.android.build.gradle .api.BaseVariant.getOutputs()Ljava/util/List;'.
本來是這樣的使用:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
}
}
and then apply it in your module:
apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'
改成8.4.0就不會報錯了:
classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.8’
apply plugin: ‘android-apt’
compile ‘com.jakewharton:butterknife:8.4.0’
apt ‘com.jakewharton:butterknife-compiler:8.4.0’
特麼新問題又來了
Error:Could not get unknown property ‘apkVariantData’ for object of type com.android.build.gradle.in
感覺像是gradle 版本影響了,然後我把build:gradle:3.1.1 改成2.3.2報錯了,很生氣啊,直接把AndResGuard 遮蔽看看,出現如下錯誤:
Error:android-apt plugin is incompatible with the Android Gradle plugin. Please use ‘annotationProcessor’ configuration instead
這個 我看懂了,就是把apt 用 annotationProcessor 替換,感覺還是Butterknife 的鍋,最後乾脆改回8.8.1,發現也是可以的,把AndResGuard改成最新版本發現也是適配了android studio 3.0 的
Android 8.0踩坑記錄——Only fullscreen opaque activities can request orientation
解決辦法:
1.找到你設定透明的Activity,然後在他的theme中將android:windowIsTranslucent改為false
false
2.再加入true
3.去掉activity中的orientation屬性