[Android開發] Android Studio問題以及解決記錄
http://blog.csdn.net/niubitianping/article/details/51400721
1、真機運行報錯Multi dex requires Build Tools 21.0.0 / Current: 19.1
解決:
在項目 build.gradle 裏面把classpath ‘com.android.tools.build:gradle:1.5.0’ 改為1.5.0 或者1.3.0
2、導入第三方包運行報錯:前言不允許有內容
解決
一般是包的位置錯誤,請放到main目錄下的libs 文件夾裏面,再右鍵 add as library
3、運行錯誤: finished with non-zero exit valule 2
1. 包沖突
例如可能你v7支持包,v4支持包都有這個類,一編譯就沖突了,或者你complie了包,然後又手動add as library了,或者重復add了,等等。 (反正我出現這個問題幾乎都是包沖突)
2. 其他錯誤
這個一般會有錯誤提示,在編譯的日誌上面,例如圖片不正確,看看是不是重新添加了圖片,然後在Android studio 裏面雙擊打開這個圖片看看 是否能正常打開,打不開就重新保存一下格式(這個情況一般是出現在自己一個搞項目時候亂搞圖片會出現的問題)
4、編譯錯誤 Gradle DSL method not found: ‘apt()’
解決
1、在項目的gradle的dependencies裏面添加
classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.8‘
- 1
2、在你這個module的gradle裏面的頭部添加
apply plugin: ‘android-apt‘
- 1
重新編譯解決
5、Failed to resolve: org.hamcrest:hamcrest-core:1.3
解決:
打開as 的Setting,gradle路徑下的offline work 勾選,路徑改為gradle解壓之後的文件夾,gradle可以自己上網下載http://services.gradle.org/distributions
6、打包時候報錯 Error: Expected resource of type styleable [ResourceType]
一般位於這裏:
TypedArray ta = mContext.obtainStyledAttributes(attrs);
boolean hasBottomLine = ta.getBoolean(0, false);
boolean hasTopLine = ta.getBoolean(1, false);
- 1
- 2
- 3
解決:
在報錯的這行代碼的 方法體上面加@SuppressWarnings(“ResourceType”)
@SuppressWarnings("ResourceType")
public SystemBarTintManager(Activity activity) {
Window win = activity.getWindow();
ViewGroup decorViewGroup = (ViewGroup) win.getDecorView();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// check theme attrs
int[] attrs = {android.R.attr.windowTranslucentStatus,
android.R.attr.windowTranslucentNavigation};
TypedArray a = activity.obtainStyledAttributes(attrs);
try {
mStatusBarAvailable = a.getBoolean(0, false);
mNavBarAvailable = a.getBoolean(1, false);
} finally {
a.recycle();
}
。。。。。。
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
即可解決
7、混淆後打包報錯: java.io.IOException: The same input jar [D:\Users\workspace_studio\Test5\app\libs\xxxxxxx.jar] is specified twice
原因:
build.gradle文件配置了
dependencies { compile fileTree(include: ‘*.jar’, dir: ‘libs’)}
裏面已經添加過jar包,混淆文件proguard-rules.pro裏面又加了句-libraryjars libs/.jar,將-libraryjars libs/.jar
解決:
proguard-rules.pro中的 -libraryjars libs/*.jar ,前面用#號註釋或者直接刪掉即可。
8、打包時候報錯Suspicious method call; should probably call “layout” rather than”onLayout”:
Suspicious method call; should probably call "layout
" rather than"onLayout"
- 1
- 2
解決:
在調用onLayout的方法 上加
@SuppressLint("WrongCall")
- 1
9、編譯的時候報錯:Error running app:Instant Run requires ‘Tools|Android|Enable ADB integration’ to be enabled
解決:
開啟adb, 菜單Tools—-Android——Enable ADB Integration
10、R 文件報錯,無法取消引用int
原因:
自動導入了其他的R文件包,例如百度地圖的R文件包
解決:
把其他R文件的包刪掉,添加自己的包名的R文件。
11、Gradle sync failed: Unable to load class ‘org.gradle.internal.logging.LoggingManagerInternal’
gradle版本和android-maven-gradle-plugin 版本不協調
解決:
如果你的gradle用的是2.1.2 ,你要把android-maven-gradle-plugin改為1.3
11、導入ADT項目報錯There are unrecoverable errors which must be corrected first
看android Studio的信息,說appcompat_v7_12 could not found,所以就是這個問題了。
把eclipse的project根目錄project.properties裏面的android.library.reference.1=../appcompat_v7刪掉,再重新導入AndroidStudio就行了
12、打印的Log顯示不全
log輸出進行了字符的限制為4000個,解決方法是寫一個類采用分段的方法輸出log
public static void printAll(String str){
if (str.length() > 4000) {
Log.v(TAG, "sb.length = " + str.length());
int chunkCount = str.length() / 4000; // integer division
for (int i = 0; i <= chunkCount; i++) {
int max = 4000 * (i + 1);
if (max >= str.length()) {
Log.v(TAG, "chunk " + i + " of " + chunkCount + ":" + str.substring(4000 * i));
} else {
Log.v(TAG, "chunk " + i + " of " + chunkCount + ":" + str.substring(4000 * i, max));
}
}
} else {
Log.v(TAG, str);
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
13、導入微信demo錯誤:Error:java.lang.RuntimeException:Some file crunching failed,see logs for details
在build.gradle的andoid裏面添加
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
- 1
- 2
14、斷開手機連接,遠程主機強迫關閉了一個現有的連接
1. miui系統關閉usb安裝管理,運行安裝未知來源。
2. 重寫拔插手機
3. 電腦換個插口
4. 換根數據線
15、Failed to open zip file.
Gradle’s dependency cache may be corrupt(this sometimes ocurs after a network connection timeout.)
我是搞了svn才出現的問題。
解決方法:
設置gradle
1. 設置本地gradle
把gradle壓縮包解壓出來,放隨便一個盤,在as裏面設置
2. 搭建本地的gradle服務器。
Windows安裝iis,然後把gradle的壓縮包放iis目錄裏面,然後在 項目根目錄\gradle\wrapper\gradle-wrapper.properties,修改最後的為distributionUrl=http://localhost/xxxxx.zip ,重新構建就o了
例如我的就是
distributionUrl=http://localhost/gradle-2.14.1-all.zip
16、No cached version of com.android.tools.build:gradle:2.2.3 available for offl
更新了AS之後出現的問題,更新AS,對應的gradle也得更新了,但是如果你使用的是之前的離線的GRadle就會出現這樣的問題了。
解決方法
File – Setting – Gradle – 取消勾選Offine work,選擇回默認的gradle wrapper
17、Error converting bytecode to dex:Cause:com.android.dex.DexEcception:Multiple dex files define….
原因1: 重復導包
原因2: buildToolsVersion和compileSdkVersion的版本不對
解決: 對應上面的原因修改即可,本人的原因是因為第二個。
18、Error:org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection cannot be cast to org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection Possible causes for this unexpected error include:Gradle’s dependency…
原因: gradle的版本不對。
解決: 把project的build.gralde的版本改為你的AndroidStudio的版本號,例如我是2.3.0版本的,就得把gradle版本改為2.3.0,然後重新sync即可。看圖
然後重新構建,出現下面的問題,就點第一個update即可。
19、Error while Installing APK,安裝app失敗,遠程主機強迫關閉了一個現有的鏈接
解決: 打開任務管理器,把adb進程給關掉就行了
[Android開發] Android Studio問題以及解決記錄