前言
- 開發(fā)過程中,Android Studio 難免會(huì)出現(xiàn)各種各樣的問題缀蹄,影響了開發(fā)進(jìn)度
- 這篇文章記錄了使用 Android Studio 時(shí)容易遇到的一些問題,希望能幫上忙
1、Cannot resolve symbol ’R'
- 表現(xiàn):R 標(biāo)紅碌燕,提示
Cannot resolve symbol 'R'
,但是程序可以正常運(yùn)行 - 原因:Intellij IDEA 對(duì)單個(gè)文件大小默認(rèn)限制為2500 kb(Android Studio基于Intellij IDEA)
- 修復(fù):進(jìn)入 Android Studio 的安裝目錄\bin瓣蛀,找到
idea.properties
文件陆蟆,查找idea.max.intellisense.filesize=2500
,將2500
修改為5000
惋增,重啟 Android Studio
#---------------------------------------------------------------------
# Maximum file size (kilobytes) IDE should provide code assistance for.
# The larger file is the slower its editor works and higher overall system memory requirements are
# if code assistance is enabled. Remove this property or set to very large number if you need
# code assistance for any files available regardless their size.
#---------------------------------------------------------------------
idea.max.intellisense.filesize=5000
2叠殷、Failed to resolve:[aar 文件名]
- 表現(xiàn):
Gradle Sync
失敗 - 原因:被依賴的 Module 中依賴了 aar 文件,例如:Module A依賴了一個(gè)Module B诈皿,而 Module B 中依賴了aar文件
- 修復(fù):在 Module A 的
build.gradle
文件中添加以下配置林束,指出 aar 文件位置:
...
android{
...
}
dependencies{
...
}
repositories {
flatDir {
dirs project(':[Module B名]').file('[依賴的aar文件名]')
}
}
- 規(guī)避:
3像棘、permission denied: ./gradlew
- 表現(xiàn):執(zhí)行
./gradlew clean
等 task 失敗 - 原因:當(dāng)前用戶沒有
gradlew
腳本的執(zhí)行權(quán)限 - 修復(fù):執(zhí)行
chmod +x ./gradlew
授予執(zhí)行權(quán)限
4、No IDEA annotations attached to the JDK 1.8, some issues will not be found
- 表現(xiàn):很多Android或Java源碼提示
Cannot find declaration to goto
- 解決辦法:
- 1壶冒、進(jìn)入
C:\Users\UserName\.android
缕题,刪除文件夾build-cache
提示
C:\Users\UserName\.android
是默認(rèn)的Android Sdk Home目錄,除非你使用ANDROID_SDK_HOME
環(huán)境變量配置了新的目錄- 2胖腾、進(jìn)入
C:\Users\UserName\.AndroidStudio3.2\system
- 1壶冒、進(jìn)入
5烟零、Gradle sync failed: Read timed out
Consult IDE log for more details (Help | Show Log) (1m 32s 930ms)
Execution failed for task ':[Module名]:transformClassesWithDexFor[Build Type名]'
Error:Execution failed for task ':[Module名]:transformClassesWithDexForNormal[Build Type名]'.
> com.android.build.api.transform.TransformException:
com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException:
java.lang.RuntimeException: Translation has been interrupted
- 表現(xiàn):
Make Project
或者Run
失敗 - 原因:
- 修復(fù):
editing
推薦閱讀
- Android | 代碼壓縮、優(yōu)化與混淆 — ProGuard與R8
- Android | 自定義屬性
- Android | 再按一次返回鍵退出
- Android | InputManagerService 與輸入事件采集
- 工具集 | Android Studio — 使用 Live Template 輸入模板代碼
- 工具集 | Android Studio — 使用 WI-FI 進(jìn)行 ADB 調(diào)試
- 工具集 | 使用 Keytool 管理密鑰和證書
- 自媒體 | 使用LaTeX編寫數(shù)學(xué)公式