Eclipse遷移Android Studio遇到的問題
1:Error:Execution failed for task ':app:transformNative_libsWithStripDebugSymbolForDebug'.
> Java.lang.NullPointerException (no error message:
編譯可以通過抄瓦,但是一運行就報這個錯,是一個NDK版本的問題 Android Studio2.2的一個bug
解決方法:
進 local.properties 中把 ndk.dir 直接刪除禁用,然后clean–rebuild 就可以了
就是禁用ndk進 local.properties 中把 ndk.dir 直接刪除禁用陶冷,然后clean–rebuild 就可以了
就是禁用ndk
2:Error:Execution failed for task ':XXXX:processDebugManifest'.
> Manifest merger failed with multiple errors, see logs
原因之一:一個工程里面有多個項目钙姊,其中一個主項目需要依賴其中的一個modle,而這個modle本身也含有Manifest文件埂伦。
Android Studio的gradle插件默認(rèn)會啟用Mainfest Merger Tool,如果你需要依賴的那個modle或者library項目
的Manifest文件中也包含與主項目相同的屬性煞额,例如icon、theme等等沾谜,就會出現(xiàn)清單文件合并失敗的錯誤膊毁,編譯不通過。
解決方法:
在Manifest.xml的根標(biāo)簽上加入xmlns:tools="http://schemas.Android.com/tools"基跑,
然后在application標(biāo)簽下添加tools:replace="icon,label,theme"婚温,多個屬性用逗號隔開。
原因之二:多個Moudle的build.gradle中的編譯版本不同所致
Moudle中的編譯版本應(yīng)不低于主程序的編譯版本
compileSdkVersion 20
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 11
targetSdkVersion 20
}
原因之三:清單文件報錯 在Eclipse中清單文件有些錯誤是檢測不出來的 比如多個友盟注冊? Service未指定優(yōu)先級
這些錯誤在Androiud Studio中都會導(dǎo)致這個錯誤 在Message中點擊方形的第二排第四個按鈕可以看到詳細(xì)的報錯信息
3:android studio 非法字符: \65279 Error:(1, 10) 錯誤: 需要class, interface或enum
這個錯誤是文件BOM導(dǎo)致的
只要將文件編碼方式改掉就行涩僻,不要使用UTF-8 WITH BOM(UTF-8包含簽名)
使用UTF-8無Bom格式
4:Expected resource of type styleable[ResourceType]
在使用TypedArray獲取數(shù)據(jù)屬性值的時候,編譯時出現(xiàn)錯誤,但是能正常調(diào)試,但是使用gradle打包apk的時候,會被檢查出來,導(dǎo)致打包失敗
這是英文錯誤信息
This inspection looks at Android API calls that have been annotated with various support annotations (such as RequiresPermission or UiThread)
and flags any calls that are not using the API correctly as specified by the annotations.
Examples of errors flagged by this inspection:
Passing the wrong type of resource integer (such as R.string) to an API that expects a different type (such as R.dimen).
Forgetting to invoke the overridden method (via super) in methods that require it
Calling a method that requires a permission without having declared that permission in the manifest
Passing a resource color reference to a method which expects an RGB integer value.
翻譯過來是這樣的缭召;
API中有很多種注解,這些注解在一定程度上規(guī)定了某些方法使用,例如要求聲明某個權(quán)限或者必須是UI主線程中調(diào)用等,如果沒有正確按照API的方法上的注解規(guī)定使用,就是出現(xiàn)這個錯誤的提示信息
例如:
api要求使用R.dimen,你卻使用了R.string;
重寫了父類的方法,但是沒有加override/supper關(guān)鍵詞
使用了要求有某種權(quán)限的方法,但是這個權(quán)限在配置文件manifest中沒有聲明
要求使用RGB顏色值作參數(shù)的方法你使用了資源顏色
這個方法的提示信息是Expected resource of type styleable [ResourceType]
也就是說我們是因為違反了[ResourceType]這個規(guī)定,因為getDimension(int,int)想要的參數(shù)是資源類型,就是R.XX.XX的這種,但是我們這里直接傳遞的是int類型,雖然都是int類型的,
但是不是他想要的,就報錯了,這里實驗一下,當(dāng)我們傳遞一個int類型的R.styleable.XX,這個提示信息就消失了,
異常解決:
在使用TypedArray的語句,方法上或者類上加上注解@SuppressWarnings("ResourceType")
關(guān)于解決方法:
SuppressWarning("XXX")
方法的作用是告訴編譯器,一個讓類型的警告不再顯示.參數(shù)"XXX",就是指定某種類型的警告.
就像我們的使用SuppressWarning("ResourceType"),就是說不要再報關(guān)于ResourceType類型的警告錯誤了.
5:打包的時候遇到此錯誤
Error:A problem was found with the configuration of task ':eglobal:packageRelease'.
> File 'D:\StudioWorkspace\eglobal\eglobal\build\intermediates\res\resources-release-stripped.ap_' specified for property 'resourceFile' does not exist.
原因:build.gradle中加了 shrinkResources true 打包的時候會刪除一些不必要的文件結(jié)果就打包失敗了
6:在工程的gradle中設(shè)置
可以支持超過65k的方法數(shù)
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
}
7:com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: ch/boye/httpclientandroidlib/ConnectionClosedException.class
解決方法:
重復(fù)包,把對應(yīng)重復(fù)的刪除即可一般為v4沖突
8:
android {
lintOptions{
//checkReleaseBuilds就是在打包Release版本的時候進行檢測逆日,這里就直接關(guān)掉了,
//也可以打開萄凤,這樣報錯還會顯示出來温治。關(guān)鍵的就是abortOnError一定要設(shè)為false纫谅,這樣即使有報錯也不會停止打包了。
checkReleaseBuilds false
abortOnError false//執(zhí)行l(wèi)int檢查笛粘,有任何的錯誤或者警告提示,都會終止構(gòu)建钻弄,我們可以將其關(guān)掉。
ignoreWarnings true//如果為true,則只報告錯誤
}
}
9:
FATAL EXCEPTION: main
Process: com.wanda.property_client, PID: 11910
java.lang.NoClassDefFoundError: org.apache.cordova.PluginEntry
導(dǎo)致4.4系統(tǒng)安裝程序直接崩掉
解決:
在application中加入:
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
10:
Android Studio導(dǎo)入github一個項目library
出現(xiàn)了Error:No such property: GROUP for class: org.gradle.api.publication.maven.internal.ant.DefaultGroovyMavenDeployer
解決方式:
在Android Studio里漓概,左上角將項目的顯示方式改為project,然后找到導(dǎo)入的庫的文件夾病梢,點開胃珍,打開其build.gradle文件
然后你注釋掉最后一行代碼(與maven有關(guān)的,比如://apply from: './gradle-mvn-push.gradle')蜓陌,重新build一下就OK了
11:android studio升級2.0后啟動APP會出現(xiàn)白屏
谷歌在AS2.0里加入了快速啟動功能觅彰,就是不需要重新安裝apk就可以顯示改變的代碼效果。
一個治標(biāo)的方法是你可以點擊這個按鈕重啟app钮热,一般重啟一次到兩次就可以進入界面了填抬,
還有一個治本的辦法就是吧Instance run這個功能取消,
方式:進入設(shè)置Build,Exception,Deployment--->Instant Run 將所有的鉤鉤取消掉
12:在studio的布局頁面無法實現(xiàn)預(yù)覽 是主題的問題
Missing styles. Is the correct theme chosen for this layout?
Use the Theme combo box above the layout to choose a different layout, or fix the theme style references.
Failed to find style 'textViewStyle' in current theme
解決方法如下:
layout預(yù)覽界面(Graphic Layout),右上角有個Theme的選擇項隧期,默認(rèn)為notitle飒责,
根據(jù)喜好隨意設(shè)定值,我們這里設(shè)定為android以前默認(rèn)的Theme.black.
13:
XML中出現(xiàn)錯誤:
In Gradle projects, always use http://schemas.Android.com/apk/res-auto for custom attributes
http://schemas.android.com/apk/res/com.xxx.xxx
根據(jù)提示信息修改為:http://schemas.android.com/apk/res-auto