溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Android studio2.3.3升級到3.1.2坑有哪些

發(fā)布時間:2021-09-10 13:54:21 來源:億速云 閱讀:164 作者:小新 欄目:移動開發(fā)

這篇文章主要介紹Android studio2.3.3升級到3.1.2坑有哪些,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

1.grade配置Error: Could not find com.android.tools.build:gradle:2.2.1.

解決方法與Maven倉庫有點像:進入

D:\software\android\android-studio-ide-145.3276617-windows\android-studio\gradle\m2repository\com\android\tools\build\gradle

將項目中的build.gradle文件中

dependencies { classpath 'com.android.tools.build:gradle:2.2.1'}

改為

dependencies { classpath 'com.android.tools.build:gradle:3.1.2'}

2.All flavors must now belong to a named flavor dimension.

在module下的build.gradle中添加一行代碼即可解決:

android{ ... flavorDimensions "versionCode" ...}

3.升級到Android Studio 3.1,重新構(gòu)建項目時報錯,主要錯誤為:

The SourceSet 'instrumentTest' is not recognized by the Android Gradle Plugin. Perhaps you misspelled something?
instrumentTest已被廢棄,新的Gradle插件已經(jīng)不支持。instrumentTest需要修改為androidTest。

修改后,sourceSets相關(guān)內(nèi)容類似:

android { buildToolsVersion "27.0.3" compileSdkVersion 24 sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] aidl.srcDirs = ['src'] renderscript.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] jniLibs.srcDirs = ['libs'] } androidTest.setRoot('tests') }}

4. AAPT2 編譯報錯 AAPT2 error

報錯

Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
解決:在gradle.properties中關(guān)閉APPT2 編譯

android.enableAapt2=false

注:如果是eclipse轉(zhuǎn)到as上的項目,可能沒有g(shù)radle.properties文件,請在項目根目錄中手動創(chuàng)建

5.升級完Android Stadio 3.1以后

將所有的compile變?yōu)閕mplementation 后,clean和rebuild都沒有發(fā)現(xiàn)錯誤,唯獨在run的時候出現(xiàn)了以下錯誤:

原因及解決辦法

原因:按照android stadio 3.1的要求,需要把gradle版本升級為 4.4及以上,但是gradle 4.4及以上要求將依賴api的compile換成implementation。而implementation聲明的依賴沒辦法傳遞到module以外,即該module 以外module沒辦法引用到implementation聲明的api。

即:module A implementation libA,而 moduleB implementation module A,那么module B 引導(dǎo) libA 中的api,不然在build的時候會報org.gradle.api.internal.tasks.compile.CompilationFailedException。
解決辦法:將compile 替換為 api即可,也就是如果有外部引用,則換成:api,剩下的換成:implementation。

示例:

dependencies { api fileTree(dir: 'libs', include: ['*.jar']) testImplementation 'junit:junit:4.12' api 'com.android.support:support-v4:26.1.0' api 'com.android.support:appcompat-v7:26.1.0' api 'com.google.code.gson:gson:2.8.2' api 'com.j256.ormlite:ormlite-core:4.48' api 'com.j256.ormlite:ormlite-android:4.48'

ps:解決辦法:

Android 6.0(api 23)已經(jīng)不支持HttpClient了,在build.gradle中 加入 useLibrary 'org.apache.http.legacy'就可以了,如圖:

Error:(633, 16) 錯誤: 找不到符號 符號: 方法 sqrt(float) 位置: 類 FloatMath

解決方案

原因是Android6.0不支持FloatMath.sin()了,主要有兩個方法可以解決。

方法一:

用23一下的SDK版本進行編譯。將gradle.build文件里(包括project的gradle.build和module的gradle.build)的compileSdkVersion設(shè)為23以下。

方法二:

將上面報錯的地方,即 用Math類替換FloatMath類,Math.sin();

方法三 :

(float)Math.sqrt 替換 FloatMath.sqrt

以上是“Android studio2.3.3升級到3.1.2坑有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI